Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Treat Event::PointerGone as PointerEvent::Released #4419

Merged
merged 18 commits into from
May 11, 2024
2 changes: 1 addition & 1 deletion crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1875,8 +1875,8 @@ impl Context {
drag_started: _,
dragged,
drag_stopped: _,
contains_pointer,
hovered,
contains_pointer,
} = interact_widgets;

if true {
Expand Down
4 changes: 4 additions & 0 deletions crates/egui/src/input_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,10 @@ impl PointerState {
}
Event::PointerGone => {
self.latest_pos = None;
self.pointer_events.push(PointerEvent::Released {
click: None,
button: PointerButton::Primary,
});
// 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,
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub(crate) fn interact(
drag_started,
dragged,
drag_stopped,
contains_pointer,
hovered,
contains_pointer,
}
}
19 changes: 7 additions & 12 deletions crates/egui_demo_lib/src/demo/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,33 +456,28 @@ fn response_summary(response: &egui::Response, show_hovers: bool) -> String {
egui::PointerButton::Extra1,
egui::PointerButton::Extra2,
] {
let button_suffix = if button == egui::PointerButton::Primary {
// Reduce visual clutter in common case:
String::default()
} else {
format!(" by {button:?} button")
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert

let button_suffix = format!(" : {button:?} button");

// These are in inverse logical/chonological order, because we show them in the ui that way:

if response.triple_clicked_by(button) {
writeln!(new_info, "Triple-clicked{button_suffix}").ok();
writeln!(new_info, "Triple_clicked_by{button_suffix}").ok();
}
if response.double_clicked_by(button) {
writeln!(new_info, "Double-clicked{button_suffix}").ok();
writeln!(new_info, "Double_clicked_by{button_suffix}").ok();
}
if response.clicked_by(button) {
writeln!(new_info, "Clicked{button_suffix}").ok();
writeln!(new_info, "Clicked_by{button_suffix}").ok();
}

if response.drag_stopped_by(button) {
writeln!(new_info, "Drag stopped{button_suffix}").ok();
writeln!(new_info, "Drag_stopped_by{button_suffix}").ok();
}
if response.dragged_by(button) {
writeln!(new_info, "Dragged{button_suffix}").ok();
writeln!(new_info, "Dragged_by{button_suffix}").ok();
}
if response.drag_started_by(button) {
writeln!(new_info, "Drag started{button_suffix}").ok();
writeln!(new_info, "Drag_started_by{button_suffix}").ok();
}
}

Expand Down
Loading