From 3f75e250765bccac9067fe68d56937ddf6080dd9 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 24 Nov 2026 18:50:22 +0000 Subject: [PATCH] A press on an app's own drag-only egui widget in a container body is no surface press The surface-press rule left a press alone when its click target was a raw egui widget (pointer::foreign_target); a widget that senses only drags (a canvas) is the press's drag target and has no click target, so the container took the press as one on its empty surface. Both targets are checked. --- .../ui-contract/src/contract/body/presses.rs | 2 +- crates/ui-panels/tests/it/dock_group.rs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/ui-contract/src/contract/body/presses.rs b/crates/ui-contract/src/contract/body/presses.rs index 492406636..54e203e75 100644 --- a/crates/ui-contract/src/contract/body/presses.rs +++ b/crates/ui-contract/src/contract/body/presses.rs @@ -95,7 +95,7 @@ impl BodyHooks<'_> { inside(press.origin) && pointer::press_winner(&ctx, press.origin, pass.press_targets).is_none() && !pointer::text_takes_press(&ctx, pass.press_targets) - && !pass.press_targets.click.is_some_and(|widget| pointer::foreign_target(&ctx, widget)) + && ![pass.press_targets.click, pass.press_targets.drag].into_iter().flatten().any(|widget| pointer::foreign_target(&ctx, widget)) }) } else { None diff --git a/crates/ui-panels/tests/it/dock_group.rs b/crates/ui-panels/tests/it/dock_group.rs index 8b0651477..f477586ec 100644 --- a/crates/ui-panels/tests/it/dock_group.rs +++ b/crates/ui-panels/tests/it/dock_group.rs @@ -268,3 +268,28 @@ fn a_click_on_an_app_field_in_the_body_keeps_its_focus() { assert!(group_stop.is_some() && fixture.focused() != Some(field_id), "a press on the empty body focuses the group's panel"); assert_ne!(on_field, group_stop, "the clicks on the field left the group's stop unfocused"); } + +// A press on an app's own egui widget in a group's body that only drags (a canvas) is the widget's, not a press on the +// group's empty body; a press on the body's empty room still is. +#[trial] +fn a_press_on_an_app_drag_widget_in_the_body_is_no_surface_press() { + let surface = Rc::new(Cell::new(false)); + let canvas = Rc::new(Cell::new(None::)); + let (pressed, shown) = (Rc::clone(&surface), Rc::clone(&canvas)); + let panels = vec![PanelTitle::new(PanelKey::new(1), "Navigator")]; + let mut fixture = Fixture::new(move |ui| { + let group = DockGroup::new(1usize, Titles::from_content(panels.clone()), panels[0].key); + let (pressed, shown) = (Rc::clone(&pressed), Rc::clone(&shown)); + group.show_at(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(300.0, 240.0)), move |ui, cx| { + pressed.set(pressed.get() || cx.surface_pressed()); + let (rect, _) = ui.allocate_exact_size(Vec2::new(120.0, 60.0), egui::Sense::drag()); + shown.set(Some(rect)); + }); + }); + fixture.settle(); + let Some(rect) = canvas.get() else { panic!("the body shows the app's canvas") }; + fixture.click_at(rect.center()).settle(); + assert!(!surface.get(), "a press on the drag-only widget is no press on the group's empty body"); + fixture.click_at(Pos2::new(rect.center().x, rect.bottom() + 80.0)).settle(); + assert!(surface.get(), "a press on the empty body is the group's surface press"); +}