tui_scrollview/
lib.rs

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