From 238b49976e36a5cbae5eab8e9fb6ec408fec1fc2 Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Thu, 28 Nov 2024 15:34:26 +0100 Subject: [PATCH] Fix areas having special click handling code --- crates/egui/src/containers/area.rs | 10 --------- crates/egui_demo_lib/src/demo/modals.rs | 29 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/crates/egui/src/containers/area.rs b/crates/egui/src/containers/area.rs index ab9a0b88d09e..3626c7565982 100644 --- a/crates/egui/src/containers/area.rs +++ b/crates/egui/src/containers/area.rs @@ -481,7 +481,6 @@ impl Area { } if (move_response.dragged() || move_response.clicked()) - || pointer_pressed_on_area(ctx, layer_id) || !ctx.memory(|m| m.areas().visible_last_frame(&layer_id)) { ctx.memory_mut(|m| m.areas_mut().move_to_top(layer_id)); @@ -607,15 +606,6 @@ impl Prepared { } } -fn pointer_pressed_on_area(ctx: &Context, layer_id: LayerId) -> bool { - if let Some(pointer_pos) = ctx.pointer_interact_pos() { - let any_pressed = ctx.input(|i| i.pointer.any_pressed()); - any_pressed && ctx.layer_id_at(pointer_pos) == Some(layer_id) - } else { - false - } -} - fn automatic_area_position(ctx: &Context, layer_id: LayerId) -> Pos2 { let mut existing: Vec = ctx.memory(|mem| { mem.areas() diff --git a/crates/egui_demo_lib/src/demo/modals.rs b/crates/egui_demo_lib/src/demo/modals.rs index c3b2dcdb8d69..49d6a727b802 100644 --- a/crates/egui_demo_lib/src/demo/modals.rs +++ b/crates/egui_demo_lib/src/demo/modals.rs @@ -255,4 +255,33 @@ mod tests { result.unwrap(); } } + + // This tests whether the backdrop actually prevents interaction with lower layers. + #[test] + fn backdrop_should_prevent_focusing_lower_area() { + let initial_state = Modals { + save_modal_open: true, + save_progress: Some(0.0), + ..Modals::default() + }; + + let mut harness = Harness::new_state( + |ctx, modals| { + modals.show(ctx, &mut true); + }, + initial_state, + ); + + // TODO(lucasmerlin): Remove these extra runs once run checks for repaint requests + harness.run(); + harness.run(); + harness.run(); + + harness.get_by_label("Yes Please").simulate_click(); + + harness.run(); + + // This snapshots should show the progress bar modal on top of the save modal. + harness.wgpu_snapshot("modals_backdrop_should_prevent_focusing_lower_area"); + } }