Skip to content

Commit

Permalink
Open ContextMenu on pointer button press, not click
Browse files Browse the repository at this point in the history
clicks only occur on button release, button press feels more responsive
  • Loading branch information
mankinskin committed Jul 25, 2021
1 parent cbfc743 commit ea3e39a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions egui/src/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl ContextMenuSystem {
fn sense_click(&mut self, response: &Response) -> MenuResponse {
let response = response.interact(Sense::click());
let pointer = &response.ctx.input().pointer;
if pointer.any_click() {
if pointer.any_pressed() {
if let Some(pos) = pointer.interact_pos() {
let mut destroy = false;
let mut in_old_menu = false;
Expand All @@ -26,9 +26,10 @@ impl ContextMenuSystem {
destroy = context_menu.ui_id == response.id;
}
if !in_old_menu {
if response.secondary_clicked() {
let in_target = response.rect.contains(pos);
if in_target && pointer.secondary_down() {
return MenuResponse::Create(pos);
} else if response.clicked() || destroy {
} else if (in_target && pointer.primary_down()) || destroy {
return MenuResponse::Close;
}
}
Expand Down

0 comments on commit ea3e39a

Please sign in to comment.