summaryrefslogtreecommitdiffstats
path: root/widget/src/scrollable.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-06-27 22:41:16 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-06-27 23:04:49 +0200
commit412e15b170a61f7d7369122d7d0b089491e1b0ea (patch)
tree050db8717148377c8e6ccca2e1de12830561c27c /widget/src/scrollable.rs
parent493571695a8853ee91309a92d04b8dbea29bab8d (diff)
downloadiced-412e15b170a61f7d7369122d7d0b089491e1b0ea.tar.gz
iced-412e15b170a61f7d7369122d7d0b089491e1b0ea.tar.bz2
iced-412e15b170a61f7d7369122d7d0b089491e1b0ea.zip
Require a `Direction` when computing `State::offset` in `scrollable`
Diffstat (limited to 'widget/src/scrollable.rs')
-rw-r--r--widget/src/scrollable.rs41
1 files changed, 23 insertions, 18 deletions
diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs
index 82f71dff..5bc6914c 100644
--- a/widget/src/scrollable.rs
+++ b/widget/src/scrollable.rs
@@ -358,10 +358,11 @@ where
let bounds = layout.bounds();
let content_layout = layout.children().next().unwrap();
let content_bounds = content_layout.bounds();
- let offset = tree
- .state
- .downcast_ref::<State>()
- .offset(bounds, content_bounds);
+ let offset = tree.state.downcast_ref::<State>().offset(
+ &self.direction,
+ bounds,
+ content_bounds,
+ );
overlay.translate(Vector::new(-offset.x, -offset.y))
})
@@ -493,7 +494,8 @@ pub fn update<Message>(
if !(mouse_over_x_scrollbar || mouse_over_y_scrollbar) =>
{
mouse::Cursor::Available(
- cursor_position + state.offset(bounds, content_bounds),
+ cursor_position
+ + state.offset(direction, bounds, content_bounds),
)
}
_ => mouse::Cursor::Unavailable,
@@ -564,12 +566,6 @@ pub fn update<Message>(
cursor_position.y - scroll_box_touched_at.y,
);
- let delta = Vector::new(
- delta.x
- * direction.horizontal().map_or(0.0, |_| 1.0),
- delta.y * direction.vertical().map_or(0.0, |_| 1.0),
- );
-
state.scroll(delta, bounds, content_bounds);
state.scroll_area_touched_at = Some(cursor_position);
@@ -775,7 +771,7 @@ pub fn mouse_interaction(
{
mouse::Interaction::Idle
} else {
- let offset = state.offset(bounds, content_bounds);
+ let offset = state.offset(direction, bounds, content_bounds);
let cursor = match cursor_over_scrollable {
Some(cursor_position)
@@ -822,7 +818,7 @@ pub fn draw<Renderer>(
let (mouse_over_y_scrollbar, mouse_over_x_scrollbar) =
scrollbars.is_mouse_over(cursor);
- let offset = state.offset(bounds, content_bounds);
+ let offset = state.offset(direction, bounds, content_bounds);
let cursor = match cursor_over_scrollable {
Some(cursor_position)
@@ -1161,16 +1157,25 @@ impl State {
);
}
- /// Returns the scrolling offset of the [`State`], given the bounds of the
- /// [`Scrollable`] and its contents.
+ /// Returns the scrolling offset of the [`State`], given a [`Direction`],
+ /// the bounds of the [`Scrollable`] and its contents.
pub fn offset(
&self,
+ direction: &Direction,
bounds: Rectangle,
content_bounds: Rectangle,
) -> Vector {
Vector::new(
- self.offset_x.absolute(bounds.width, content_bounds.width),
- self.offset_y.absolute(bounds.height, content_bounds.height),
+ if direction.horizontal().is_some() {
+ self.offset_x.absolute(bounds.width, content_bounds.width)
+ } else {
+ 0.0
+ },
+ if direction.vertical().is_some() {
+ self.offset_y.absolute(bounds.height, content_bounds.height)
+ } else {
+ 0.0
+ },
)
}
@@ -1196,7 +1201,7 @@ impl Scrollbars {
bounds: Rectangle,
content_bounds: Rectangle,
) -> Self {
- let offset = state.offset(bounds, content_bounds);
+ let offset = state.offset(direction, bounds, content_bounds);
let show_scrollbar_x = direction.horizontal().and_then(|h| {
if content_bounds.width > bounds.width {