From 5fe858d771d286204d2ed911533869223ea20d2c Mon Sep 17 00:00:00 2001 From: Cyandev Date: Sun, 10 Mar 2024 13:14:31 +0800 Subject: Add scrollbar for mark list --- src/interactive/widgets/mark.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index a774c73..d50bd0e 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -17,7 +17,10 @@ use tui::{ layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, text::{Line, Span, Text}, - widgets::{Block, Borders, Paragraph, Widget}, + widgets::{ + Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, + Widget, + }, }; use tui_react::{ draw_text_nowrap_fn, @@ -411,12 +414,33 @@ impl MarkPane { inner_area }; + let line_count = marked.len(); let props = ListProps { block: None, entry_in_view, }; self.list.render(props, entries, list_area, buf); + let scrollbar = Scrollbar::default() + .orientation(ScrollbarOrientation::VerticalRight) + .begin_symbol(None) + .end_symbol(None); + let mut scrollbar_state = + ScrollbarState::new(line_count).position(selected.unwrap_or(self.list.offset)); + + scrollbar.render( + { + let mut scrollbar_area = list_area; + // The list has no blocks, so we need to increase + // the render area for scrollbar to make sure it + // will be drawn on the border. + scrollbar_area.width += 1; + scrollbar_area + }, + buf, + &mut scrollbar_state, + ); + if has_focus { let help_text = " . = o|.. = u ── ⇊ = Ctrl+d|↓ = j|⇈ = Ctrl+u|↑ = k "; let help_text_block_width = block_width(help_text); -- cgit v1.2.3