tui-scrollview 0.1.3

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

See scrollview.rs

Run this with

cargo run --example scrollview

TODO

  • Clamp scroll state to buffer area
  • Add scrollbar
  • Add example
  • Conditionally show scrollbar
  • Add demo GIF
  • Fix scrollbar size (Ratatui bug?)
  • Change offset to use Position once Ratatui PR #790 is released (this will be breaking change for the ScrollViewState)

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.