summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Clark Moody <clark@clarkmoody.com>2020-10-22 16:05:44 -0500
committerLibravatar Clark Moody <clark@clarkmoody.com>2020-10-22 16:05:44 -0500
commitf05578c8f88b38cb538657e40c2feb725e72c7d8 (patch)
tree8a73a3cf39920bbd5dffaef7efcf609d5efc6fc0 /graphics
parent09e67c5c2701e7eeeb0bdb924966f8442c698b6a (diff)
downloadiced-f05578c8f88b38cb538657e40c2feb725e72c7d8.tar.gz
iced-f05578c8f88b38cb538657e40c2feb725e72c7d8.tar.bz2
iced-f05578c8f88b38cb538657e40c2feb725e72c7d8.zip
Update scrollbar logic and introduce outer_bounds
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/widget/scrollable.rs33
1 files changed, 20 insertions, 13 deletions
diff --git a/graphics/src/widget/scrollable.rs b/graphics/src/widget/scrollable.rs
index 0a3191fa..fed79c18 100644
--- a/graphics/src/widget/scrollable.rs
+++ b/graphics/src/widget/scrollable.rs
@@ -28,29 +28,41 @@ where
offset: u32,
scrollbar_width: u16,
scrollbar_margin: u16,
- _scroller_width: u16,
+ scroller_width: u16,
) -> Option<scrollable::Scrollbar> {
if content_bounds.height > bounds.height {
+ let outer_width =
+ scrollbar_width.max(scroller_width) + 2 * scrollbar_margin;
+
+ let outer_bounds = Rectangle {
+ x: bounds.x + bounds.width - outer_width as f32,
+ y: bounds.y,
+ width: outer_width as f32,
+ height: bounds.height,
+ };
+
let scrollbar_bounds = Rectangle {
x: bounds.x + bounds.width
- - f32::from(scrollbar_width + 2 * scrollbar_margin),
+ - f32::from(outer_width / 2 + scrollbar_width / 2),
y: bounds.y,
- width: f32::from(scrollbar_width + 2 * scrollbar_margin),
+ width: scrollbar_width as f32,
height: bounds.height,
};
let ratio = bounds.height / content_bounds.height;
- let scrollbar_height = bounds.height * ratio;
+ let scroller_height = bounds.height * ratio;
let y_offset = offset as f32 * ratio;
let scroller_bounds = Rectangle {
- x: scrollbar_bounds.x + f32::from(scrollbar_margin),
+ x: bounds.x + bounds.width
+ - f32::from(outer_width / 2 + scroller_width / 2),
y: scrollbar_bounds.y + y_offset,
- width: scrollbar_bounds.width - f32::from(2 * scrollbar_margin),
- height: scrollbar_height,
+ width: scroller_width as f32,
+ height: scroller_height,
};
Some(scrollable::Scrollbar {
+ outer_bounds,
bounds: scrollbar_bounds,
margin: scrollbar_margin,
scroller: scrollable::Scroller {
@@ -110,12 +122,7 @@ where
let scrollbar = if is_scrollbar_visible {
Primitive::Quad {
- bounds: Rectangle {
- x: scrollbar.bounds.x + f32::from(scrollbar.margin),
- width: scrollbar.bounds.width
- - f32::from(2 * scrollbar.margin),
- ..scrollbar.bounds
- },
+ bounds: scrollbar.bounds,
background: style
.background
.unwrap_or(Background::Color(Color::TRANSPARENT)),