Skip to content

Commit

Permalink
Fix areas having special click handling code
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Nov 28, 2024
1 parent 69125e5 commit 238b499
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
10 changes: 0 additions & 10 deletions crates/egui/src/containers/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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<Rect> = ctx.memory(|mem| {
mem.areas()
Expand Down
29 changes: 29 additions & 0 deletions crates/egui_demo_lib/src/demo/modals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 238b499

Please sign in to comment.