Skip to main content

tui_scrollview/
lib.rs

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