Levitate cursor in scrollable

Fixes #3074
This commit is contained in:
Héctor Ramón Jiménez 2025-10-11 07:57:37 +02:00
parent 62795909d8
commit 01429d72cd
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 36 additions and 37 deletions

View file

@ -762,7 +762,7 @@ where
),
)
}
_ => mouse::Cursor::Unavailable,
_ => cursor.levitate(),
};
let had_input_method = shell.input_method().is_enabled();
@ -1178,35 +1178,33 @@ where
let (mouse_over_y_scrollbar, mouse_over_x_scrollbar) =
scrollbars.is_mouse_over(cursor);
if (mouse_over_x_scrollbar || mouse_over_y_scrollbar)
|| state.scrollers_grabbed()
{
mouse::Interaction::None
} else {
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 + translation)
}
_ => mouse::Cursor::Unavailable,
};
self.content.as_widget().mouse_interaction(
&tree.children[0],
content_layout,
cursor,
&Rectangle {
y: bounds.y + translation.y,
x: bounds.x + translation.x,
..bounds
},
renderer,
)
if state.scrollers_grabbed() {
return mouse::Interaction::None;
}
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 + translation)
}
_ => cursor.levitate(),
};
self.content.as_widget().mouse_interaction(
&tree.children[0],
content_layout,
cursor,
&Rectangle {
y: bounds.y + translation.y,
x: bounds.x + translation.x,
..bounds
},
renderer,
)
}
fn overlay<'b>(

View file

@ -363,7 +363,11 @@ where
Event::Mouse(mouse::Event::CursorMoved { .. })
| Event::Touch(touch::Event::FingerMoved { .. }) => {
if state.is_dragging {
let _ = cursor.position().and_then(locate).map(change);
let _ = cursor
.land()
.position()
.and_then(locate)
.map(change);
shell.capture_event();
}
@ -527,12 +531,10 @@ where
_renderer: &Renderer,
) -> mouse::Interaction {
let state = tree.state.downcast_ref::<State>();
let bounds = layout.bounds();
let is_mouse_over = cursor.is_over(bounds);
if state.is_dragging {
mouse::Interaction::Grabbing
} else if is_mouse_over {
} else if cursor.is_over(layout.bounds()) {
mouse::Interaction::Grab
} else {
mouse::Interaction::default()

View file

@ -365,7 +365,8 @@ where
Event::Mouse(mouse::Event::CursorMoved { .. })
| Event::Touch(touch::Event::FingerMoved { .. }) => {
if is_dragging {
let _ = cursor.position().and_then(locate).map(change);
let _ =
cursor.land().position().and_then(locate).map(change);
shell.capture_event();
}
@ -522,12 +523,10 @@ where
_renderer: &Renderer,
) -> mouse::Interaction {
let state = tree.state.downcast_ref::<State>();
let bounds = layout.bounds();
let is_mouse_over = cursor.is_over(bounds);
if state.is_dragging {
mouse::Interaction::Grabbing
} else if is_mouse_over {
} else if cursor.is_over(layout.bounds()) {
mouse::Interaction::Grab
} else {
mouse::Interaction::default()