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
+6 -15
View File
@@ -61,7 +61,6 @@ pub struct Tree<'a, Identifier> {
block: Option<Block<'a>>,
scrollbar: Option<Scrollbar<'a>>,
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);
}