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.
This commit is contained in:
Emil Ernerfeldt 2021-10-26 20:40:17 +02:00
parent 41f77ba7d7
commit bbe0f6089c
2 changed files with 6 additions and 1 deletions

View file

@ -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 {

View file

@ -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