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..39cd318103 100644 --- a/crates/ui-contract/src/runtime/pointer.rs +++ b/crates/ui-contract/src/runtime/pointer.rs @@ -918,6 +918,44 @@ pub(crate) fn over_part(ctx: &Context, viewport: ViewportId, root: Id, part: Par OverPart { widgets, above } } +/// The hit areas, in screen points and clipped to where each shows, 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)) { + // A press reaches a shape across its hit area, grown to its least size across (`Shape::hits`), and only + // where it shows through its clip (`find_under`). + let bounds = entry + .shapes + .iter() + .zip(&entry.placed) + .filter(|(shape, _)| shape.sense.takes_press()) + .map(|(shape, placed)| { + let bounds = shape.shape.bounds(); + let grow = (egui::Vec2::splat(shape.min_across) - bounds.size()).max(egui::Vec2::ZERO) / 2.0; + bounds.expand2(grow).intersect(placed.clip) + }) + .filter(|rect| rect.is_positive()) + .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-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