summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2023-09-14 23:13:14 +0200
committerLibravatar GitHub <noreply@github.com>2023-09-14 23:13:14 +0200
commit4613eb26cba3ded83f25ebdefd01c983c79a9d59 (patch)
tree968a55dc12d9b4115f936d0d29f724f142980340
parent9245423c5d82f88c99adecaaf5dd2ac3559a05a8 (diff)
parented11b04f6054809ea55ec9b3f0bd221ac2caf9ca (diff)
downloadiced-4613eb26cba3ded83f25ebdefd01c983c79a9d59.tar.gz
iced-4613eb26cba3ded83f25ebdefd01c983c79a9d59.tar.bz2
iced-4613eb26cba3ded83f25ebdefd01c983c79a9d59.zip
Merge pull request #2084 from iced-rs/fix/horizontal-scrollbar-width
Fix width of horizontal scrollbar in `Scrollable`
-rw-r--r--examples/scrollable/src/main.rs4
-rw-r--r--widget/src/scrollable.rs20
2 files changed, 12 insertions, 12 deletions
diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs
index 8c08d993..21e69284 100644
--- a/examples/scrollable/src/main.rs
+++ b/examples/scrollable/src/main.rs
@@ -389,12 +389,12 @@ impl scrollable::StyleSheet for ScrollbarCustomStyle {
background: style
.active(&theme::Scrollable::default())
.background,
- border_radius: 0.0.into(),
+ border_radius: 2.0.into(),
border_width: 0.0,
border_color: Default::default(),
scroller: Scroller {
color: Color::from_rgb8(250, 85, 134),
- border_radius: 0.0.into(),
+ border_radius: 2.0.into(),
border_width: 0.0,
border_color: Default::default(),
},
diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs
index def28821..f92e6223 100644
--- a/widget/src/scrollable.rs
+++ b/widget/src/scrollable.rs
@@ -1364,15 +1364,15 @@ impl Scrollbars {
let ratio = bounds.height / content_bounds.height;
// min height for easier grabbing with super tall content
- let scroller_height = (bounds.height * ratio).max(2.0);
- let scroller_offset = translation.y * ratio;
+ let scroller_height = (scrollbar_bounds.height * ratio).max(2.0);
+ let scroller_offset =
+ translation.y * ratio * scrollbar_bounds.height / bounds.height;
let scroller_bounds = Rectangle {
x: bounds.x + bounds.width
- total_scrollbar_width / 2.0
- scroller_width / 2.0,
- y: (scrollbar_bounds.y + scroller_offset - x_scrollbar_height)
- .max(0.0),
+ y: (scrollbar_bounds.y + scroller_offset).max(0.0),
width: scroller_width,
height: scroller_height,
};
@@ -1399,8 +1399,8 @@ impl Scrollbars {
// Need to adjust the width of the horizontal scrollbar if the vertical scrollbar
// is present
- let scrollbar_y_width = show_scrollbar_y
- .map_or(0.0, |v| v.width.max(v.scroller_width) + v.margin);
+ let scrollbar_y_width = y_scrollbar
+ .map_or(0.0, |scrollbar| scrollbar.total_bounds.width);
let total_scrollbar_height =
width.max(scroller_width) + 2.0 * margin;
@@ -1425,12 +1425,12 @@ impl Scrollbars {
let ratio = bounds.width / content_bounds.width;
// min width for easier grabbing with extra wide content
- let scroller_length = (bounds.width * ratio).max(2.0);
- let scroller_offset = translation.x * ratio;
+ let scroller_length = (scrollbar_bounds.width * ratio).max(2.0);
+ let scroller_offset =
+ translation.x * ratio * scrollbar_bounds.width / bounds.width;
let scroller_bounds = Rectangle {
- x: (scrollbar_bounds.x + scroller_offset - scrollbar_y_width)
- .max(0.0),
+ x: (scrollbar_bounds.x + scroller_offset).max(0.0),
y: bounds.y + bounds.height
- total_scrollbar_height / 2.0
- scroller_width / 2.0,