From f5110ecdb56eeaa9f8ebe457f12cad91c3ddff82 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 11:49:27 +0000 Subject: [PATCH] Dialog chrome: a section gap under the header rule, above the footer and beside a button column; no footer rule; full-window header and footer inset The dialog shells take their regions from frame.rs (HEADER, FOOTER, SIDE_BUTTONS), spaced by one gap. FooterRegion gains an inset tier, the counterpart of HeaderRegion::inset, so a full-window dialog keeps its title and buttons off the window edges while its canvas and side columns reach them. --- crates/ui-canvas/src/canvas/full_window.rs | 4 +-- crates/ui-contract/src/contract/body/hooks.rs | 12 +++++--- crates/ui-contract/src/contract/container.rs | 13 ++++++-- crates/ui-panels/src/dialog/frame.rs | 27 ++++++++++++----- crates/ui-panels/src/dialog/modal.rs | 12 ++++---- crates/ui-panels/src/dialog/trials.rs | 30 +++++++++++++++++++ crates/ui-shell/tests/it/body/regions.rs | 17 +++++++++++ 7 files changed, 93 insertions(+), 22 deletions(-) diff --git a/crates/ui-canvas/src/canvas/full_window.rs b/crates/ui-canvas/src/canvas/full_window.rs index 53abeb6d1..f9448af2d 100644 --- a/crates/ui-canvas/src/canvas/full_window.rs +++ b/crates/ui-canvas/src/canvas/full_window.rs @@ -93,7 +93,7 @@ impl<'a> FullWindowDialog<'a> { .mount(Mount::FullWindow) .surface(SurfaceKind::Panel) .pad(Pad::None) - .header(HeaderRegion::new().rule(true)) + .header(HeaderRegion::new().rule(true).inset(Pad::Regular)) .focus(FocusPolicy::DIALOG.initial(Initial::Keep)) .command_scope(ViewCommands::SCOPE); FullWindowDialog { @@ -195,7 +195,7 @@ impl<'a> FullWindowDialog<'a> { /// The footer region: among the side columns when there are any, else across the dialog's foot. fn footer_region(&self) -> FooterRegion { - FOOTER.place(if self.sides.is_some() { self.side_footer.place() } else { FooterPlace::Across }) + FOOTER.inset(Pad::Regular).place(if self.sides.is_some() { self.side_footer.place() } else { FooterPlace::Across }) } fn place_footer(mut self) -> Self { diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index c1162dbdf..bfafea332 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -989,10 +989,14 @@ impl ShapeHooks for BodyHooks<'_> { // the control. if props.footer.is_some() { let (mut footer_rect, offset) = self.place_footer(&props, &mut regions, inner, body_rect, rtl); - // The region's height counts the gap (it is part of what the footer took), so the content starts below it. + // The region's size counts the gap and the inset (they are part of what the footer took), so the content + // starts below the gap and stays the inset away from the sides and the foot. let lead = props.footer.and_then(|footer| footer.gap).map_or(0.0, |gap| gap_of(&env.tokens, gap)); + let inset = props.footer.map_or(0.0, |footer| pad_of(&env.tokens, footer.inset)); footer_rect.min.y += lead; - footer_rect.max.y = footer_rect.max.y.max(footer_rect.min.y); + footer_rect.max.y = (footer_rect.max.y - inset).max(footer_rect.min.y); + footer_rect.min.x += inset; + footer_rect.max.x = (footer_rect.max.x - inset).max(footer_rect.min.x); let mut bcx = BodyCx::new(body_id, env_view, resolved, footer_rect, &mut *cx.core.memory, &mut open, gate.as_mut()) .with_field_message(field_message) .with_owner(owner); @@ -1004,10 +1008,10 @@ impl ShapeHooks for BodyHooks<'_> { let mut took = self.region_size(&footer_ui); // The footer's width counts from the container's edge, past the column it starts after. if took.x > 0.0 { - took.x += offset; + took.x += offset + 2.0 * inset; } if took.y > 0.0 { - took.y += lead; + took.y += lead + inset; } self.footer_size = Some(took); } diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index c4deda19b..17187a36b 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -320,15 +320,24 @@ pub struct FooterRegion { pub place: FooterPlace, /// The space above the footer's content, inside the region; none by default. pub gap: Option, + /// The padding between the container's edges and the footer's content, at its two sides and under it: the + /// footer's own tier, for a container whose body has no padding. + pub inset: Pad, /// The footer shows the validity message of the control the container labels as its status line /// (`BodyCx::field_message`); a control under a container without one shows its message itself. pub status: bool, } impl FooterRegion { - /// A footer across the container under the line, with no rule. + /// A footer across the container under the line, with no rule and no inset. pub const fn new() -> Self { - FooterRegion { rule: false, place: FooterPlace::Across, gap: None, status: false } + FooterRegion { rule: false, place: FooterPlace::Across, gap: None, inset: Pad::None, status: false } + } + + /// The padding tier between the container's edges and the footer's content, at its sides and under it. + pub const fn inset(mut self, pad: Pad) -> Self { + self.inset = pad; + self } /// Whether a rule separates the footer from the content beside it. diff --git a/crates/ui-panels/src/dialog/frame.rs b/crates/ui-panels/src/dialog/frame.rs index 6b5199782..6a652cb49 100644 --- a/crates/ui-panels/src/dialog/frame.rs +++ b/crates/ui-panels/src/dialog/frame.rs @@ -3,7 +3,7 @@ use super::host::DialogResult; use crate::contract::{ - BodyCx, Common, Component, Container, ContainerProps, Cx, FooterRegion, HeaderRegion, Pad, Props as _, Role, Scroll, Show as _, + BodyCx, Common, Component, Container, ContainerProps, Cx, EndRegion, FooterRegion, Gap, HeaderRegion, Pad, Props as _, Role, Scroll, Show as _, ShowContainer as _, WordSetCx as _, }; use crate::contract::{NoValue, Outcome}; @@ -212,15 +212,26 @@ pub fn close_action(closable: bool) -> &'static [HeaderAction] { if closable { &[HeaderAction::Close] } else { &[] } } -/// The props every dialog shell starts from: the dialog surface and a header with a rule under it. A layer scrolls its -/// body vertically unless the body is a collection; a frame in a parent's flow asks for the scroll itself. -pub(crate) fn chrome_props() -> ContainerProps { - ContainerProps::new().surface(SurfaceKind::Dialog).pad(Pad::Regular).header(HeaderRegion::new().rule(true)) -} +/// The space between a dialog's regions: under the header's rule, above the footer and beside a column of buttons. +const REGION_GAP: Gap = Gap::Section; -/// The footer region of a shell that has footer content. +/// The header region of a dialog shell: the title row, a rule under it and the region gap before the body. #[doc(hidden)] -pub const FOOTER: FooterRegion = FooterRegion::new().rule(true); +pub const HEADER: HeaderRegion = HeaderRegion::new().rule(true).gap(REGION_GAP); + +/// The footer region of a shell that has footer content: the region gap above it, and no rule. +#[doc(hidden)] +pub const FOOTER: FooterRegion = FooterRegion::new().gap(REGION_GAP); + +/// The end region of a dialog whose buttons stand in a column beside the body, the region gap away from it. +#[doc(hidden)] +pub const SIDE_BUTTONS: EndRegion = EndRegion::new().gap(REGION_GAP); + +/// The props every dialog shell starts from: the dialog surface and the dialog header. A layer scrolls its body +/// vertically unless the body is a collection; a frame in a parent's flow asks for the scroll itself. +pub(crate) fn chrome_props() -> ContainerProps { + ContainerProps::new().surface(SurfaceKind::Dialog).pad(Pad::Regular).header(HEADER) +} /// The style of a dialog frame: the surface and padding come from the container. #[derive(Clone, Debug, Default, PartialEq, ComponentStyle)] diff --git a/crates/ui-panels/src/dialog/modal.rs b/crates/ui-panels/src/dialog/modal.rs index 7620530f3..1c96e263a 100644 --- a/crates/ui-panels/src/dialog/modal.rs +++ b/crates/ui-panels/src/dialog/modal.rs @@ -1,11 +1,11 @@ //! `Dialog` (16.5): `DialogFrame`'s chrome on an egui layer: modal or modeless, movable by its header, with a //! focus trap, placement and size remembered under a `SaveKey`. -use super::frame::{self, DialogOutput, FOOTER, FooterCx, FooterFn, FooterHooks}; +use super::frame::{self, DialogOutput, FOOTER, FooterCx, FooterFn, FooterHooks, HEADER, SIDE_BUTTONS}; use crate::contract::overlay::{FloatPlace, OverlayFit, Place}; use crate::contract::{ - Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, DragBand, EndRegion, FooterPlace, FooterRegion, HeaderRegion, Mount, - Overlay, Pad, Props as _, Role, SaveKey, ShowContainer as _, + Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, DragBand, FooterPlace, FooterRegion, HeaderRegion, Mount, Overlay, Pad, + Props as _, Role, SaveKey, ShowContainer as _, }; use crate::edit::outer::{self, OuterEnd}; use crate::runtime::access::Access; @@ -89,13 +89,13 @@ impl<'a> Dialog<'a> { /// `resizable` says so. pub fn new(title: impl Into