ratatui_toolkit/widgets/markdown_widget/extensions/scrollbar/
mod.rs

1//! Custom scrollbar widget for markdown document navigation.
2//!
3//! Provides a visual scrollbar that accurately tracks scroll position using block characters.
4//! Supports click-to-scroll and drag interactions, with optional percentage indicator.
5//!
6//! # Features
7//!
8//! - Block character rendering (█ for thumb, ░ for track)
9//! - Accurate scroll position tracking via ScrollState
10//! - Click on track to jump to position
11//! - Drag thumb to scroll
12//! - Optional percentage indicator
13//!
14//! # Architecture
15//!
16//! The CustomScrollbar extension is a UI widget only - it receives `&ScrollState` as a parameter
17//! and ONLY handles rendering. State mutations happen through ScrollState methods or via
18//! the click_to_offset helper for interaction.
19
20pub mod constructors;
21pub mod enums;
22mod methods;
23mod traits;
24
25pub use constructors::*;
26pub use enums::*;
27pub use methods::{click_to_offset, is_in_scrollbar_area};
28
29use crate::widgets::markdown_widget::state::scroll_state::ScrollState;
30
31/// Custom scrollbar widget for markdown navigation.
32///
33/// Shows scroll position using block characters with accurate tracking.
34/// Supports click-to-scroll and drag interactions.
35///
36/// This is a UI-only widget that receives `&ScrollState` for state access.
37/// State mutations happen through `ScrollState` methods, not here.
38///
39/// # Example
40///
41/// ```rust,ignore
42/// use ratatui_toolkit::markdown_widget::extensions::scrollbar::{CustomScrollbar, ScrollbarConfig};
43/// use ratatui_toolkit::markdown_widget::state::scroll_state::ScrollState;
44///
45/// let scroll_state = ScrollState::default();
46/// let scrollbar = CustomScrollbar::new(&scroll_state)
47///     .config(ScrollbarConfig::default())
48///     .show_percentage(true);
49/// ```
50#[derive(Debug)]
51pub struct CustomScrollbar<'a> {
52    /// Reference to the scroll state.
53    pub(crate) scroll_state: &'a ScrollState,
54    /// Configuration for appearance.
55    pub(crate) config: ScrollbarConfig,
56    /// Whether to show percentage indicator.
57    pub(crate) show_percentage: bool,
58}