tui_scrollview/
lib.rs

1//! A [Ratatui] widget to build smooth scrollable views. Part of the [tui-widgets] suite by [Joshka].
2//!
3//! ![Demo](https://vhs.charm.sh/vhs-6PuT3pdwSTp4aTvKrCBx9F.gif)
4//!
5//! (Note: a github bug stops the example gif above being displayed, but you can view it at:
6//! <https://vhs.charm.sh/vhs-6PuT3pdwSTp4aTvKrCBx9F.gif>)
7//!
8//! [![Crate badge]][Crate]
9//! [![Docs Badge]][Docs]
10//! [![Deps Badge]][Dependency Status]
11//! [![License Badge]][License]
12//! [![Coverage Badge]][Coverage]
13//! [![Discord Badge]][Ratatui Discord]
14//!
15//! [GitHub Repository] · [API Docs] · [Examples] · [Changelog] · [Contributing]
16//!
17//! # Installation
18//!
19//! ```shell
20//! cargo add tui-scrollview
21//! ```
22//!
23//! # Usage
24//!
25//! ```rust
26//! use std::iter;
27//!
28//! use ratatui::layout::Size;
29//! use ratatui::prelude::*;
30//! use ratatui::widgets::*;
31//! use tui_scrollview::{ScrollView, ScrollViewState};
32//!
33//! struct MyScrollableWidget;
34//!
35//! impl StatefulWidget for MyScrollableWidget {
36//!     type State = ScrollViewState;
37//!
38//!     fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
39//!         // 100 lines of text
40//!         let line_numbers = (1..=100).map(|i| format!("{:>3} ", i)).collect::<String>();
41//!         let content =
42//!             iter::repeat("Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n")
43//!                 .take(100)
44//!                 .collect::<String>();
45//!
46//!         let content_size = Size::new(100, 30);
47//!         let mut scroll_view = ScrollView::new(content_size);
48//!
49//!         // the layout doesn't have to be hardcoded like this, this is just an example
50//!         scroll_view.render_widget(Paragraph::new(line_numbers), Rect::new(0, 0, 5, 100));
51//!         scroll_view.render_widget(Paragraph::new(content), Rect::new(5, 0, 95, 100));
52//!
53//!         scroll_view.render(buf.area, buf, state);
54//!     }
55//! }
56//! ```
57//!
58//! # Full Example
59//!
60//! A full example can be found in the [examples directory].
61//! [scrollview.rs]
62//!
63//! This example shows a scrollable view with two paragraphs of text, one for the line numbers and
64//! one for the text. On top of this a Gauge widget is rendered to show that this can be used in
65//! combination with any other widget.
66//!
67//! # More widgets
68//!
69//! For the full suite of widgets, see [tui-widgets].
70//!
71//! [Crate]: https://crates.io/crates/tui-scrollview
72//! [Docs]: https://docs.rs/tui-scrollview/
73//! [Dependency Status]: https://deps.rs/repo/github/joshka/tui-widgets
74//! [Coverage]: https://app.codecov.io/gh/joshka/tui-widgets
75//! [Ratatui Discord]: https://discord.gg/pMCEU9hNEj
76//! [Crate badge]: https://img.shields.io/crates/v/tui-scrollview?logo=rust&style=flat
77//! [Docs Badge]: https://img.shields.io/docsrs/tui-scrollview?logo=rust&style=flat
78//! [Deps Badge]: https://deps.rs/repo/github/joshka/tui-widgets/status.svg?style=flat
79//! [License Badge]: https://img.shields.io/crates/l/tui-scrollview?style=flat
80//! [License]: https://github.com/joshka/tui-widgets/blob/main/LICENSE-MIT
81//! [Coverage Badge]:
82//!     https://img.shields.io/codecov/c/github/joshka/tui-widgets?logo=codecov&style=flat
83//! [Discord Badge]: https://img.shields.io/discord/1070692720437383208?logo=discord&style=flat
84//!
85//! [GitHub Repository]: https://github.com/joshka/tui-widgets
86//! [API Docs]: https://docs.rs/tui-scrollview/
87//! [Examples]: https://github.com/joshka/tui-widgets/tree/main/tui-scrollview/examples
88//! [examples directory]: https://github.com/joshka/tui-widgets/tree/main/tui-scrollview/examples
89//! [scrollview.rs]:
90//!     https://github.com/joshka/tui-widgets/tree/main/tui-scrollview/examples/scrollview.rs
91//! [Changelog]: https://github.com/joshka/tui-widgets/blob/main/tui-scrollview/CHANGELOG.md
92//! [Contributing]: https://github.com/joshka/tui-widgets/blob/main/CONTRIBUTING.md
93//!
94//! [Ratatui]: https://crates.io/crates/ratatui
95//!
96//! [Joshka]: https://github.com/joshka
97//! [tui-widgets]: https://crates.io/crates/tui-widgets
98
99mod scroll_view;
100mod state;
101
102pub use scroll_view::{ScrollView, ScrollbarVisibility};
103pub use state::ScrollViewState;