fix(scrollbar): calculate area margin from inside and outside of border areas

This commit is contained in:
EdJoPaTo
2024-02-24 18:38:52 +01:00
parent 9a0b26f5c9
commit 83dd95b87f
2 changed files with 6 additions and 16 deletions
-1
View File
@@ -119,7 +119,6 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> std::io::Res
.title("Tree Widget") .title("Tree Widget")
.title_bottom(format!("{:?}", app.state)), .title_bottom(format!("{:?}", app.state)),
) )
.experimental_scrollbar_margin(1, 1)
.experimental_scrollbar(Some( .experimental_scrollbar(Some(
Scrollbar::new(ScrollbarOrientation::VerticalRight) Scrollbar::new(ScrollbarOrientation::VerticalRight)
.begin_symbol(None) .begin_symbol(None)
+6 -15
View File
@@ -61,7 +61,6 @@ pub struct Tree<'a, Identifier> {
block: Option<Block<'a>>, block: Option<Block<'a>>,
scrollbar: Option<Scrollbar<'a>>, scrollbar: Option<Scrollbar<'a>>,
scrollbar_margin: (u16, u16),
/// Style used as a base style for the widget /// Style used as a base style for the widget
style: Style, style: Style,
@@ -103,7 +102,6 @@ where
items, items,
block: None, block: None,
scrollbar: None, scrollbar: None,
scrollbar_margin: (0, 0),
style: Style::new(), style: Style::new(),
highlight_style: Style::new(), highlight_style: Style::new(),
highlight_symbol: "", highlight_symbol: "",
@@ -131,13 +129,6 @@ where
self 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] #[must_use]
pub const fn style(mut self, style: Style) -> Self { pub const fn style(mut self, style: Style) -> Self {
self.style = style; self.style = style;
@@ -257,12 +248,12 @@ where
.position(start) .position(start)
.viewport_content_length(height); .viewport_content_length(height);
let scrollbar_area = Rect { let scrollbar_area = Rect {
y: full_area.y.saturating_add(self.scrollbar_margin.0), // Inner height to be exactly as the content
height: full_area y: area.y,
.height height: area.height,
.saturating_sub(self.scrollbar_margin.0) // Outer width to stay on the right border
.saturating_sub(self.scrollbar_margin.1), x: full_area.x,
..full_area width: full_area.width,
}; };
scrollbar.render(scrollbar_area, buf, &mut scrollbar_state); scrollbar.render(scrollbar_area, buf, &mut scrollbar_state);
} }