[go: up one dir, main page]

tui-scrollview 0.3.2

A simple scrollable view for Ratatui
Documentation

Tui-scrollview

Crates.io Badge License Badge Docs.rs Badge Deps.rs Badge Codecov.io Badge Discord Badge

tui-scrollview is a library for creating scrollable views in Ratatui.

Installation

cargo add tui-scrollview

Usage

use std::iter;
use tui_scrollview::{ScrollView, ScrollViewState};
use ratatui::{layout::Size, prelude::*, widgets::*};

fn render(frame: &mut Frame) {
    let size = Size::new(10, 100);
    let mut scroll_view = ScrollView::new(size);
    let some_long_string =
        iter::repeat("Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n")
           .take(100)
           .collect::<String>();
    let area = Rect::new(0, 0, 10, 100);
    scroll_view.render_widget(Paragraph::new(some_long_string), area);
    let mut state = ScrollViewState::default();
    frame.render_stateful_widget(scroll_view, area, &mut state);
}

Example

This example shows a scrollable view with two paragraphs of text, one for the line numbers and one for the text. On top of this a Gauge widget is rendered to show that this can be used in combination with any other widget.

Demo

scrollview.rs

TODO

  • Conditionally show scrollbar
  • Implement horizontal scrolling and bar

License

Copyright (c) 2024 Josh McKinney

This project is licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

See CONTRIBUTING.md.