From a0cfd52d1b9de87a73ef13b0883e9ae5d385bc2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 15 Oct 2025 22:17:39 +0200 Subject: [PATCH] Apply `translation` to levitated `Cursor` in `scrollable` --- core/src/mouse/cursor.rs | 14 ++++++++++++++ widget/src/scrollable.rs | 19 ++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/core/src/mouse/cursor.rs b/core/src/mouse/cursor.rs index 9388a578..7acf6c7d 100644 --- a/core/src/mouse/cursor.rs +++ b/core/src/mouse/cursor.rs @@ -75,6 +75,20 @@ impl Cursor { } } +impl std::ops::Add for Cursor { + type Output = Self; + + fn add(self, translation: Vector) -> Self::Output { + match self { + Cursor::Available(point) => Cursor::Available(point + translation), + Cursor::Levitating(point) => { + Cursor::Levitating(point + translation) + } + Cursor::Unavailable => Cursor::Unavailable, + } + } +} + impl std::ops::Mul for Cursor { type Output = Self; diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 8c146543..420ae88e 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -748,28 +748,21 @@ where Event::Mouse(mouse::Event::WheelScrolled { .. }) ) { + let translation = + state.translation(self.direction, bounds, content_bounds); + let cursor = match cursor_over_scrollable { Some(cursor_position) if !(mouse_over_x_scrollbar || mouse_over_y_scrollbar) => { - mouse::Cursor::Available( - cursor_position - + state.translation( - self.direction, - bounds, - content_bounds, - ), - ) + mouse::Cursor::Available(cursor_position + translation) } - _ => cursor.levitate(), + _ => cursor.levitate() + translation, }; let had_input_method = shell.input_method().is_enabled(); - let translation = - state.translation(self.direction, bounds, content_bounds); - self.content.as_widget_mut().update( &mut tree.children[0], event, @@ -1191,7 +1184,7 @@ where { mouse::Cursor::Available(cursor_position + translation) } - _ => cursor.levitate(), + _ => cursor.levitate() + translation, }; self.content.as_widget().mouse_interaction(