From 62cb3207e8920eca83e1828b3f0549442469d10f Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 29 Nov 2026 17:26:29 +0100 Subject: [PATCH 1/5] ui-contract: a dialog in its own window moves by its title row where the platform answers the hit test (photocraft#17952) Another component's widget over a drag band covers it only where that component's parts take a press: a dialog's title row covers its band with its close button, not with its whole row. Co-Authored-By: Claude Opus 5.5 --- .../ui-contract/src/runtime/egui/widgets.rs | 13 +++--- crates/ui-contract/src/runtime/pointer.rs | 25 +++++++++++ crates/ui-contract/src/runtime/windows/hit.rs | 8 +++- .../ui-shell/tests/it/contract/os_window.rs | 43 +++++++++++++++++++ 4 files changed, 83 insertions(+), 6 deletions(-) diff --git a/crates/ui-contract/src/runtime/egui/widgets.rs b/crates/ui-contract/src/runtime/egui/widgets.rs index b4f84f054f..950054ab3d 100644 --- a/crates/ui-contract/src/runtime/egui/widgets.rs +++ b/crates/ui-contract/src/runtime/egui/widgets.rs @@ -4,19 +4,22 @@ use egui::{AreaState, Context, Id, Order, Rect}; -/// The interact rects, in screen space, of the interactive egui widgets of the running pass that egui's hit test +/// The ids and interact rects, in screen space, of the interactive egui widgets of the running pass that egui's hit test /// puts above the widget `below`: those on a layer higher in its order, or later on `below`'s layer. A layer that is /// not interactable is click-through and holds none. Widgets in `skip` are left out. Empty when `below` is not shown /// in the pass. -pub(crate) fn above(ctx: &Context, below: Id, skip: &[Id]) -> Vec { +pub(crate) fn above(ctx: &Context, below: Id, skip: &[Id]) -> Vec<(Id, Rect)> { let (base, layers) = ctx.viewport(|viewport| { let widgets = &viewport.this_pass.widgets; let Some(base) = widgets.get(below).map(|rect| rect.layer_id) else { return (None, Vec::new()) }; let mut layers = Vec::new(); for (layer, rects) in widgets.layers().filter(|(layer, _)| layer.order.allow_interaction()) { let after = if *layer == base { rects.iter().position(|rect| rect.id == below).map_or(rects.len(), |at| at + 1) } else { 0 }; - let hits: Vec = - rects[after..].iter().filter(|rect| rect.sense.interactive() && !skip.contains(&rect.id)).map(|rect| rect.interact_rect).collect(); + let hits: Vec<(Id, Rect)> = rects[after..] + .iter() + .filter(|rect| rect.sense.interactive() && !skip.contains(&rect.id)) + .map(|rect| (rect.id, rect.interact_rect)) + .collect(); if !hits.is_empty() { layers.push((*layer, hits)); } @@ -36,7 +39,7 @@ pub(crate) fn above(ctx: &Context, below: Id, skip: &[Id]) -> Vec { continue; } let to_screen = ctx.layer_transform_to_global(layer).unwrap_or(egui::emath::TSTransform::IDENTITY); - found.extend(hits.into_iter().map(|rect| to_screen * rect)); + found.extend(hits.into_iter().map(|(id, rect)| (id, to_screen * rect))); } found } diff --git a/crates/ui-contract/src/runtime/pointer.rs b/crates/ui-contract/src/runtime/pointer.rs index cf416d1c37..0370a6c4c0 100644 --- a/crates/ui-contract/src/runtime/pointer.rs +++ b/crates/ui-contract/src/runtime/pointer.rs @@ -918,6 +918,31 @@ pub(crate) fn over_part(ctx: &Context, viewport: ViewportId, root: Id, part: Par OverPart { widgets, above } } +/// The bounds, in screen points, of the press-taking shapes of the root whose egui widgets include `widget` in the +/// running pass: where a press over that widget goes to the root's parts (8.3). `None` when no root recorded it, so it +/// is a plain egui widget that takes a press anywhere in its rect. +pub(crate) fn press_shapes_of_widget(ctx: &Context, viewport: ViewportId, widget: Id) -> Option> { + let layers: Vec<(Layer, Vec)> = PerViewport::::with(ctx, viewport, |record| { + let mut found = None::)>>; + for (layer, roots) in &record.this { + for entry in roots.values().filter(|entry| entry.widgets.contains(&widget)) { + let bounds = entry.shapes.iter().filter(|shape| shape.sense.takes_press()).map(|shape| shape.shape.bounds()).collect(); + found.get_or_insert_with(Vec::new).push((*layer, bounds)); + } + } + found + })?; + Some( + layers + .into_iter() + .flat_map(|(layer, bounds)| { + let to_screen = areas::layer_to_screen(ctx, layer); + bounds.into_iter().map(move |rect| to_screen * rect) + }) + .collect(), + ) +} + /// The hit areas the running pass has registered so far for the components `of` takes, in screen points: each shape's /// bounds grown to its least size across, with the component and part it belongs to. pub(crate) fn hit_areas(ctx: &Context, of: impl Fn(Id) -> bool) -> Vec<(Id, Option, egui::Rect)> { diff --git a/crates/ui-contract/src/runtime/windows/hit.rs b/crates/ui-contract/src/runtime/windows/hit.rs index 5a5ba18a21..de8938eca8 100644 --- a/crates/ui-contract/src/runtime/windows/hit.rs +++ b/crates/ui-contract/src/runtime/windows/hit.rs @@ -248,11 +248,17 @@ fn regions_of(ctx: &Context, viewport: ViewportId, parts: &[ExclusivePart]) -> O /// clipped to the band: each interactive egui widget of the running pass that egui's hit test puts above the /// component's widgets, and each of the component's own shapes that a press there goes to instead of the band (a /// member over it, a higher part). The component's widgets resolve as the component (8.3), so they are not hits -/// over the band themselves. +/// over the band themselves. Another component's widget resolves the same way: only its parts that take a press +/// cover the band, so a dialog's title row covers it with its close button and not with its whole row, whose title +/// leaves the press to the band (photocraft: Preferences in its own window did not move by its title row). fn covers_of(ctx: &Context, viewport: ViewportId, owner: Id, part: PartRef, band: Rect) -> Vec { let over = pointer::over_part(ctx, viewport, owner, part); widgets::above(ctx, owner, &over.widgets) .into_iter() + .flat_map(|(widget, rect)| match pointer::press_shapes_of_widget(ctx, viewport, widget) { + Some(shapes) => shapes.into_iter().map(|shape| shape.intersect(rect)).collect(), + None => vec![rect], + }) .chain(over.above) .map(|cover| cover.intersect(band)) .filter(|cover| cover.is_positive()) diff --git a/crates/ui-shell/tests/it/contract/os_window.rs b/crates/ui-shell/tests/it/contract/os_window.rs index 9870eda6cf..ba429c2f30 100644 --- a/crates/ui-shell/tests/it/contract/os_window.rs +++ b/crates/ui-shell/tests/it/contract/os_window.rs @@ -62,3 +62,46 @@ fn a_modals_strip_stands_for_the_hit_sink() { } assert!(sent.iter().all(|(_, command)| *command != ViewportCommand::StartDrag), "the platform moves the window, not the app: {sent:?}"); } + +/// photocraft: Edit › Preferences, a dialog in an OS window of its own in a window the app frames, did not move by its +/// title row: on Windows the platform answers the hit test there (a sink installed), and the sink had no drag area for +/// the title row, so a press on it was a plain click. +#[trial] +fn a_dialog_in_its_own_window_moves_it_by_its_title_row() { + let shell = ShellInfo::default(); + let shell = shell.clone().caps(shell.caps.union(Caps::OS_RESIZES_UNDECORATED)); + let layout = craft_window::Layout { left: vec![], right: vec![Caption::Minimize, Caption::Maximize, Caption::Close] }; + let frame = Frame::Integrated(Captions { family: CaptionFamily::Windows, layout }); + let desktop = Desktop { kind: DesktopKind::Other, ssd: None, gtk_theme: None, icon_theme: None }; + let windows = Windows::with(InstallSpec::new(shell, Arc::new(NoWindows)).frame(Decision { frame, overridden: None, desktop })); + let rect = Rect::from_min_size(Pos2::new(100.0, 100.0), vec2(640.0, 480.0)); + windows.child_info(egui::ViewportInfo { inner_rect: Some(rect), outer_rect: Some(rect), native_pixels_per_point: Some(1.0), ..Default::default() }); + let title = Cell::new(Rect::NOTHING); + let frame = |events: Vec| { + windows.frame(vec![], events, |ui| { + let mut open = true; + let shown = Dialog::new("Preferences") + .resizable(true) + .opened(Bind::bound(&mut open)) + .buttons([FooterButton::new("OK", DialogRole::Accept), FooterButton::new("Cancel", DialogRole::Cancel)]) + .viewport() + .show(ui, |ui, _| { + Block::new(Vec2::new(300.0, 200.0)).show(ui); + }); + let rect = shown.output.response.rect; + title.set(Rect::from_min_size(rect.min, vec2(rect.width(), 40.0))); + }) + }; + let child = frame(vec![]).builders.iter().map(|(id, _)| *id).find(|id| *id != ViewportId::ROOT).expect("the dialog opened a window"); + let host = WindowHost::of(&windows.ctx); + let _sink = host.install_hit_sink(child); + for _ in 0..4 { + frame(vec![]); + } + let regions = host.caption_regions(child).expect("the dialog's window registered its parts"); + let on_title = Pos2::new(title.get().center().x + 60.0, title.get().top() + 16.0); + assert_eq!(regions.hit(on_title), Some(WindowHit::Move), "the title row is a drag area for the sink at {on_title:?}: {regions:?}"); + // The close action at the row's end keeps its press: the platform does not move the window from it. + let on_close = Pos2::new(title.get().right() - 20.0, title.get().top() + 16.0); + assert_eq!(regions.hit(on_close), None, "the close action is no drag area at {on_close:?}: {regions:?}"); +} From c13f5fcdc6d4ba231370a1561c13a121584e4c9b Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 29 Nov 2026 17:26:30 +0100 Subject: [PATCH 2/5] ui-panels: alerts and prompts move by their title row (photocraft#17952) Co-Authored-By: Claude Opus 5.5 --- crates/ui-panels/src/dialog/modal.rs | 6 +++--- crates/ui-panels/tests/it/dialogs.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/ui-panels/src/dialog/modal.rs b/crates/ui-panels/src/dialog/modal.rs index ea7478ef8b..ce55823c26 100644 --- a/crates/ui-panels/src/dialog/modal.rs +++ b/crates/ui-panels/src/dialog/modal.rs @@ -133,10 +133,10 @@ impl<'a> Dialog<'a> { Dialog::on(title, overlay, HEADER.band(DragBand::Move)) } - /// A prompt titled `title`: a dialog centred with its content capped, fixed in place and - /// not remembered. + /// A prompt titled `title`: a dialog centred with its content capped and not remembered. It moves by its title band, + /// as every dialog does, so it can be moved off what the user needs to see while answering it. pub fn prompt(title: impl Into