From 0c0651de5b1722194d48c19cd645e747fb72ccb6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 3 Feb 2025 05:45:51 +0100 Subject: Introduce `Levitating` variant for `mouse::Cursor` --- widget/src/scrollable.rs | 6 ++++-- widget/src/stack.rs | 21 +++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'widget') diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 312aee29..2dbe0479 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -563,7 +563,8 @@ where Event::Mouse(mouse::Event::CursorMoved { .. }) | Event::Touch(touch::Event::FingerMoved { .. }) => { if let Some(scrollbar) = scrollbars.y { - let Some(cursor_position) = cursor.position() + let Some(cursor_position) = + cursor.land().position() else { return; }; @@ -635,7 +636,8 @@ where match event { Event::Mouse(mouse::Event::CursorMoved { .. }) | Event::Touch(touch::Event::FingerMoved { .. }) => { - let Some(cursor_position) = cursor.position() else { + let Some(cursor_position) = cursor.land().position() + else { return; }; diff --git a/widget/src/stack.rs b/widget/src/stack.rs index 12ed941d..d5cf1ecf 100644 --- a/widget/src/stack.rs +++ b/widget/src/stack.rs @@ -216,15 +216,15 @@ where viewport: &Rectangle, ) { let is_over = cursor.is_over(layout.bounds()); - let is_mouse_movement = - matches!(event, Event::Mouse(mouse::Event::CursorMoved { .. })); + let end = self.children.len() - 1; - for ((child, state), layout) in self + for (i, ((child, state), layout)) in self .children .iter_mut() .rev() .zip(tree.children.iter_mut().rev()) .zip(layout.children().rev()) + .enumerate() { child.as_widget_mut().update( state, @@ -237,22 +237,19 @@ where viewport, ); - if is_over - && !is_mouse_movement - && cursor != mouse::Cursor::Unavailable - { + if shell.is_event_captured() { + return; + } + + if i < end && is_over && !cursor.is_levitating() { let interaction = child.as_widget().mouse_interaction( state, layout, cursor, viewport, renderer, ); if interaction != mouse::Interaction::None { - cursor = mouse::Cursor::Unavailable; + cursor = cursor.levitate(); } } - - if shell.is_event_captured() { - return; - } } } -- cgit