Fix: still track mouse when dragging outside web canvas (#4522)
* Closes https://github.com/emilk/egui/issues/3157 If the mouse leaves the canvas when dragging a slider, the slider will still move. --- To support this, I had to revert https://github.com/emilk/egui/pull/4419 Despite that, I fail to reproduce the two issues it claimed to solve: * https://github.com/emilk/egui/issues/4406 may have been solved in another way by this PR * https://github.com/emilk/egui/issues/4418 I cannot reproduce on Mac. If it is still a problem, I think it should be solved by triggering a `PointerEvent::Released` when focus is lost (i.e. on alt-tab), and not on `PointerGone`
This commit is contained in:
@@ -1875,8 +1875,8 @@ impl Context {
|
||||
drag_started: _,
|
||||
dragged,
|
||||
drag_stopped: _,
|
||||
hovered,
|
||||
contains_pointer,
|
||||
hovered,
|
||||
} = interact_widgets;
|
||||
|
||||
if true {
|
||||
|
||||
@@ -800,10 +800,8 @@ impl PointerState {
|
||||
}
|
||||
Event::PointerGone => {
|
||||
self.latest_pos = None;
|
||||
self.pointer_events.push(PointerEvent::Released {
|
||||
click: None,
|
||||
button: PointerButton::Primary,
|
||||
});
|
||||
// When dragging a slider and the mouse leaves the viewport, we still want the drag to work,
|
||||
// so we don't treat this as a `PointerEvent::Released`.
|
||||
// NOTE: we do NOT clear `self.interact_pos` here. It will be cleared next frame.
|
||||
}
|
||||
Event::MouseMoved(delta) => *self.motion.get_or_insert(Vec2::ZERO) += *delta,
|
||||
|
||||
@@ -283,7 +283,7 @@ pub(crate) fn interact(
|
||||
drag_started,
|
||||
dragged,
|
||||
drag_stopped,
|
||||
hovered,
|
||||
contains_pointer,
|
||||
hovered,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user