From bbe0f6089c83d00ea2906e8c476a6428e189fe9e Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 26 Oct 2021 20:40:17 +0200 Subject: [PATCH] Context-menu: fix right-click edge-case response.hovered() checks a larger rect which includes the item spacing, and it always matches the hover effect. --- egui/src/menu.rs | 2 +- egui/src/response.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/egui/src/menu.rs b/egui/src/menu.rs index 1c6b37bb..ae31ca5f 100644 --- a/egui/src/menu.rs +++ b/egui/src/menu.rs @@ -329,7 +329,7 @@ impl MenuRoot { destroy = root.id == response.id; } if !in_old_menu { - let in_target = response.rect.contains(pos); + let in_target = response.hovered(); if in_target && pointer.secondary_down() { return MenuResponse::Create(pos, id); } else if (in_target && pointer.primary_down()) || destroy { diff --git a/egui/src/response.rs b/egui/src/response.rs index 99720b2a..cfb95069 100644 --- a/egui/src/response.rs +++ b/egui/src/response.rs @@ -176,6 +176,11 @@ impl Response { } /// The pointer is hovering above this widget or the widget was clicked/tapped this frame. + /// + /// Note that this is slightly different from checking `response.rect.contains(pointer_pos)`. + /// For one, the hover rectangle is slightly larger, by half of the current item spacing + /// (to make it easier to click things). But `hovered` also checks that no other area + /// is covering this response rectangle. #[inline(always)] pub fn hovered(&self) -> bool { self.hovered