fix(dnd_source): rely on current cursor position for hover state
This commit is contained in:
parent
79f8337634
commit
3d2c018cd1
2 changed files with 22 additions and 31 deletions
2
iced
2
iced
|
|
@ -1 +1 @@
|
||||||
Subproject commit 02149769ec61d485ddc0bf4f07e98f0ec700420f
|
Subproject commit ac24bbe80dd16ea586b8a0b5816066e3ba1b48fa
|
||||||
|
|
@ -240,7 +240,7 @@ impl<Message: Clone + 'static, D: iced::clipboard::mime::AsMimeTypes + std::mark
|
||||||
Event::Mouse(mouse_event) => match mouse_event {
|
Event::Mouse(mouse_event) => match mouse_event {
|
||||||
mouse::Event::ButtonPressed(mouse::Button::Left) => {
|
mouse::Event::ButtonPressed(mouse::Button::Left) => {
|
||||||
if let Some(position) = cursor.position() {
|
if let Some(position) = cursor.position() {
|
||||||
if !state.hovered {
|
if !cursor.is_over(layout.bounds()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -256,33 +256,27 @@ impl<Message: Clone + 'static, D: iced::clipboard::mime::AsMimeTypes + std::mark
|
||||||
}
|
}
|
||||||
mouse::Event::CursorMoved { .. } => {
|
mouse::Event::CursorMoved { .. } => {
|
||||||
if let Some(position) = cursor.position() {
|
if let Some(position) = cursor.position() {
|
||||||
if state.hovered {
|
// We ignore motion if we do not possess drag content by now.
|
||||||
// We ignore motion if we do not possess drag content by now.
|
if self.drag_content.is_none() {
|
||||||
if self.drag_content.is_none() {
|
state.left_pressed_position = None;
|
||||||
state.left_pressed_position = None;
|
return;
|
||||||
return;
|
}
|
||||||
|
if let Some(left_pressed_position) = state.left_pressed_position
|
||||||
|
&& position.distance(left_pressed_position) > self.drag_threshold
|
||||||
|
{
|
||||||
|
if let Some(on_start) = self.on_start.as_ref() {
|
||||||
|
shell.publish(on_start.clone());
|
||||||
}
|
}
|
||||||
if let Some(left_pressed_position) = state.left_pressed_position {
|
let offset = Vector::new(
|
||||||
if position.distance(left_pressed_position) > self.drag_threshold {
|
left_pressed_position.x - layout.bounds().x,
|
||||||
if let Some(on_start) = self.on_start.as_ref() {
|
left_pressed_position.y - layout.bounds().y,
|
||||||
shell.publish(on_start.clone())
|
);
|
||||||
}
|
self.start_dnd(clipboard, state.cached_bounds, offset);
|
||||||
let offset = Vector::new(
|
state.is_dragging = true;
|
||||||
left_pressed_position.x - layout.bounds().x,
|
state.left_pressed_position = None;
|
||||||
left_pressed_position.y - layout.bounds().y,
|
}
|
||||||
);
|
if !cursor.is_over(layout.bounds()) {
|
||||||
self.start_dnd(clipboard, state.cached_bounds, offset);
|
return;
|
||||||
state.is_dragging = true;
|
|
||||||
state.left_pressed_position = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !cursor.is_over(layout.bounds()) {
|
|
||||||
state.hovered = false;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if cursor.is_over(layout.bounds()) {
|
|
||||||
state.hovered = true;
|
|
||||||
}
|
}
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
}
|
}
|
||||||
|
|
@ -296,7 +290,6 @@ impl<Message: Clone + 'static, D: iced::clipboard::mime::AsMimeTypes + std::mark
|
||||||
}
|
}
|
||||||
state.is_dragging = false;
|
state.is_dragging = false;
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Dnd(DndEvent::Source(SourceEvent::Finished)) => {
|
Event::Dnd(DndEvent::Source(SourceEvent::Finished)) => {
|
||||||
|
|
@ -306,7 +299,6 @@ impl<Message: Clone + 'static, D: iced::clipboard::mime::AsMimeTypes + std::mark
|
||||||
}
|
}
|
||||||
state.is_dragging = false;
|
state.is_dragging = false;
|
||||||
shell.capture_event();
|
shell.capture_event();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
@ -422,7 +414,6 @@ impl<
|
||||||
/// Local state of the [`MouseListener`].
|
/// Local state of the [`MouseListener`].
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct State {
|
struct State {
|
||||||
hovered: bool,
|
|
||||||
left_pressed_position: Option<Point>,
|
left_pressed_position: Option<Point>,
|
||||||
is_dragging: bool,
|
is_dragging: bool,
|
||||||
cached_bounds: Rectangle,
|
cached_bounds: Rectangle,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue