ratatui_toolkit/widgets/markdown_widget/extensions/scrollbar/constructors/new.rs
1//! Constructor methods for CustomScrollbar.
2
3use crate::widgets::markdown_widget::extensions::scrollbar::{CustomScrollbar, ScrollbarConfig};
4use crate::widgets::markdown_widget::state::scroll_state::ScrollState;
5
6impl<'a> CustomScrollbar<'a> {
7 /// Create a new CustomScrollbar with the given scroll state.
8 ///
9 /// # Arguments
10 ///
11 /// * `scroll_state` - Reference to the scroll state to track.
12 ///
13 /// # Example
14 ///
15 /// ```rust,ignore
16 /// let scrollbar = CustomScrollbar::new(&scroll_state);
17 /// ```
18 pub fn new(scroll_state: &'a ScrollState) -> Self {
19 Self {
20 scroll_state,
21 config: ScrollbarConfig::default(),
22 show_percentage: false,
23 }
24 }
25
26 /// Set the scrollbar configuration.
27 ///
28 /// # Arguments
29 ///
30 /// * `config` - The configuration to use.
31 ///
32 /// # Returns
33 ///
34 /// Self for method chaining.
35 pub fn config(mut self, config: ScrollbarConfig) -> Self {
36 self.config = config;
37 self
38 }
39
40 /// Enable or disable the percentage indicator.
41 ///
42 /// # Arguments
43 ///
44 /// * `show` - Whether to show the percentage.
45 ///
46 /// # Returns
47 ///
48 /// Self for method chaining.
49 pub fn show_percentage(mut self, show: bool) -> Self {
50 self.show_percentage = show;
51 self
52 }
53}