From 83dd95b87f65daa59cc1bc18cb3f172ac8cfa542 Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Sat, 24 Feb 2024 18:38:52 +0100 Subject: [PATCH] fix(scrollbar): calculate area margin from inside and outside of border areas --- examples/example.rs | 1 - src/lib.rs | 21 ++++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/examples/example.rs b/examples/example.rs index 7ea23bd..cf11366 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -119,7 +119,6 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> std::io::Res .title("Tree Widget") .title_bottom(format!("{:?}", app.state)), ) - .experimental_scrollbar_margin(1, 1) .experimental_scrollbar(Some( Scrollbar::new(ScrollbarOrientation::VerticalRight) .begin_symbol(None) diff --git a/src/lib.rs b/src/lib.rs index f593ce0..c33dd9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,7 +61,6 @@ pub struct Tree<'a, Identifier> { block: Option>, scrollbar: Option>, - scrollbar_margin: (u16, u16), /// Style used as a base style for the widget style: Style, @@ -103,7 +102,6 @@ where items, block: None, scrollbar: None, - scrollbar_margin: (0, 0), style: Style::new(), highlight_style: Style::new(), highlight_symbol: "", @@ -131,13 +129,6 @@ where self } - /// See [`experimental_scrollbar`](Self::experimental_scrollbar) - #[must_use] - pub const fn experimental_scrollbar_margin(mut self, begin: u16, end: u16) -> Self { - self.scrollbar_margin = (begin, end); - self - } - #[must_use] pub const fn style(mut self, style: Style) -> Self { self.style = style; @@ -257,12 +248,12 @@ where .position(start) .viewport_content_length(height); let scrollbar_area = Rect { - y: full_area.y.saturating_add(self.scrollbar_margin.0), - height: full_area - .height - .saturating_sub(self.scrollbar_margin.0) - .saturating_sub(self.scrollbar_margin.1), - ..full_area + // Inner height to be exactly as the content + y: area.y, + height: area.height, + // Outer width to stay on the right border + x: full_area.x, + width: full_area.width, }; scrollbar.render(scrollbar_area, buf, &mut scrollbar_state); }