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