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 [examples] directory.
53//! [scrollview.rs](https://github.com/joshka/tui-widgets/tree/main/tui-scrollview/examples/scrollview.rs)
54//!
55//! This example shows a scrollable view with two paragraphs of text, one for the line numbers and
56//! one for the text. On top of this a Gauge widget is rendered to show that this can be used in
57//! combination with any other widget.
58//!
59//! 
60//!
61//! (Note: a github bug stops the example gif above being displayed, but you can view it at:
62//! <https://vhs.charm.sh/vhs-6PuT3pdwSTp4aTvKrCBx9F.gif>)
63//!
64//! [Crates.io Badge]: https://img.shields.io/crates/v/tui-scrollview?logo=rust&style=for-the-badge
65//! [License Badge]: https://img.shields.io/crates/l/tui-scrollview?style=for-the-badge
66//! [Docs.rs Badge]: https://img.shields.io/docsrs/tui-scrollview?logo=rust&style=for-the-badge
67//! [Deps.rs Badge]:
68//! https://deps.rs/repo/github/joshka/tui-scrollview/status.svg?style=for-the-badge
69//! [Codecov.io Badge]:
70//! https://img.shields.io/codecov/c/github/joshka/tui-scrollview?logo=codecov&style=for-the-badge&token=BAQ8SOKEST
71//! [Discord Badge]:
72//! https://img.shields.io/discord/1070692720437383208?label=ratatui+discord&logo=discord&style=for-the-badge
73//!
74//! [Crate]: https://crates.io/crates/tui-scrollview
75//! [API Docs]: https://docs.rs/crate/tui-scrollview/
76//! [Dependencies]: https://deps.rs/repo/github/joshka/tui-scrollview
77//! [Coverage]: https://app.codecov.io/gh/joshka/tui-scrollview
78//! [Ratatui Discord]: https://discord.gg/pMCEU9hNEj
79//!
80//! [Ratatui]: https://crates.io/crates/ratatui
81
82mod scroll_view;
83mod state;
84
85pub use scroll_view::{ScrollView, ScrollbarVisibility};
86pub use state::ScrollViewState;