mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-24 11:31:28 +01:00
Keep covered context menu openers from receiving clicks
This commit is contained in:
2 files changed
+28
-2
No files matched your search
@@ -76,7 +76,9 @@ impl Opener {
|
||||
let inside = frame
|
||||
.pos
|
||||
.is_some_and(|pos| anchor.rect.contains(areas::layer_map(&anchor.ctx, anchor.layer_id).map_or(pos, |map| map.to_layer(pos))));
|
||||
let by_pointer = inside && frame.release == Some(PointerButton::Secondary);
|
||||
let by_pointer = inside
|
||||
&& frame.release == Some(PointerButton::Secondary)
|
||||
&& frame.pos.is_some_and(|pos| areas::layer_at(&anchor.ctx, pos) == Some(anchor.layer_id));
|
||||
// A root opener opens on the primary press inside it, as a pop-up button does, however long the press is
|
||||
// then held; a `Click` opener's release completes the click that press began.
|
||||
let primary = pressed_on && frame.press.is_some_and(|press| press.button == PointerButton::Primary);
|
||||
@@ -138,7 +140,8 @@ pub(super) fn secondary_release_in(response: &Response) -> bool {
|
||||
pass.frame.as_ref().is_some_and(|frame| {
|
||||
frame.release == Some(PointerButton::Secondary)
|
||||
&& frame.pos.is_some_and(|pos| {
|
||||
response.rect.contains(areas::layer_map(&response.ctx, response.layer_id).map_or(pos, |map| map.to_layer(pos)))
|
||||
areas::layer_at(&response.ctx, pos) == Some(response.layer_id)
|
||||
&& response.rect.contains(areas::layer_map(&response.ctx, response.layer_id).map_or(pos, |map| map.to_layer(pos)))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -64,6 +64,29 @@ fn right_click(fixture: &mut Fixture, at: egui::Pos2) {
|
||||
fixture.settle();
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_context_menu_beneath_a_popover_does_not_open_from_its_click() {
|
||||
let mut fixture = Fixture::new(|ui| {
|
||||
let background = Button::new("Background").show_at(ui, Rect::from_min_max(pos2(0.0, 0.0), pos2(500.0, 500.0)));
|
||||
Menu::context("Background menu", &background).show(ui, |ui, _| {
|
||||
MenuItem::new("Background action").show(ui);
|
||||
});
|
||||
let opener = Button::new("Open popover").show(ui);
|
||||
let mut open = true;
|
||||
Popover::new("Floating", Bind::bound(&mut open)).opened_by(&opener).show(ui, |ui, _| {
|
||||
let target = Button::new("Floating target").show(ui);
|
||||
Menu::context("Floating menu", &target).show(ui, |ui, _| {
|
||||
MenuItem::new("Floating action").show(ui);
|
||||
});
|
||||
});
|
||||
});
|
||||
fixture.settle();
|
||||
let at = fixture.by_label("Floating target").expect("floating target").center();
|
||||
right_click(&mut fixture, at);
|
||||
assert!(fixture.by_label("Floating action").is_some(), "the floating menu opens");
|
||||
assert!(fixture.by_label("Background action").is_none(), "the covered menu stays closed");
|
||||
}
|
||||
|
||||
/// A secondary click on a press menu's button opens its menu, as a primary press does.
|
||||
#[trial]
|
||||
fn a_secondary_click_on_a_press_menu_button_opens_its_menu() {
|
||||
|
||||
Reference in new issue
Block a user