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.
This commit is contained in:
aiongg
2026-11-12 14:32:51 +00:00
parent 0c064ca7d3
commit f5110ecdb5
7 changed files with 93 additions and 22 deletions
+2 -2
View File
@@ -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 {
@@ -989,10 +989,14 @@ impl<C: Container> ShapeHooks<C> 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<C: Container> ShapeHooks<C> 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);
}
+11 -2
View File
@@ -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<Gap>,
/// 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.
+19 -8
View File
@@ -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)]
+6 -6
View File
@@ -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<Label>) -> Self {
let overlay = Overlay::dialog().resizable(false);
Dialog::on(title, overlay, HeaderRegion::new().band(DragBand::Move).rule(true))
Dialog::on(title, overlay, HEADER.band(DragBand::Move))
}
/// A prompt titled `title`: a dialog on the modal preset, centred with its content capped, fixed in place and
/// not remembered.
pub fn prompt(title: impl Into<Label>) -> Self {
Dialog::on(title, Overlay::modal(), HeaderRegion::new().rule(true))
Dialog::on(title, Overlay::modal(), HEADER)
}
fn on(title: impl Into<Label>, overlay: Overlay, header: HeaderRegion) -> Self {
@@ -261,7 +261,7 @@ impl<'a> Dialog<'a> {
#[must_use]
pub fn side_buttons(mut self, on: bool) -> Self {
self.side = on;
self.props.end = on.then(EndRegion::new);
self.props.end = on.then_some(SIDE_BUTTONS);
if self.props.footer.is_some() {
let region = self.footer_region();
self.props = self.props.footer(region);
+30
View File
@@ -100,6 +100,36 @@ fn a_dialog_widens_for_a_footer_wider_than_its_body() {
assert_eq!(short, long, "a short body does not squeeze the buttons");
}
/// The dialog chrome every dialog shares: the body starts apart from the title row's rule and ends apart from the
/// footer, and the buttons stay inside the dialog, off its foot.
#[trial]
fn a_dialogs_body_stands_apart_from_its_header_and_its_footer() {
let mut frames = Frames::new();
let mut ui = |ui: &mut Ui| {
let (mut open, mut snap) = (true, false);
Dialog::new("Options")
.opened(Bind::bound(&mut open))
.buttons([FooterButton::new("Cancel", DialogRole::Cancel), FooterButton::new("OK", DialogRole::Accept)])
.show(ui, |ui, _| {
Checkbox::new(Bind::bound(&mut snap)).label("Snap to the grid").show(ui);
});
};
frames.idle(30, &mut ui);
let tree = frames.tree();
let rect = |role: Role, name: &str| {
let key = tree.keys().into_iter().find(|key| tree.role_of(*key) == Some(role) && tree.name_of(*key) == Some(name));
key.and_then(|key| tree.bounds_of(key))
};
let [Some(dialog), Some(title), Some(body), Some(ok)] =
[rect(Role::DIALOG, "Options"), rect(Role::HEADING, "Options"), rect(Role::CHECK_BOX, "Snap to the grid"), rect(Role::BUTTON, "OK")]
else {
panic!("every part is shown");
};
assert!(body.min.y > title.max.y + 1.0, "a space separates the body from the title row's rule: {title:?} {body:?}");
assert!(ok.min.y > body.max.y + 1.0, "a space separates the body from the footer: {body:?} {ok:?}");
assert!(ok.max.y < dialog.max.y - 1.0, "the buttons stay off the dialog's foot: {ok:?} {dialog:?}");
}
#[trial]
fn side_buttons_stand_in_one_column_beside_the_body() {
let mut frames = Frames::new();
+17
View File
@@ -112,6 +112,23 @@ fn a_filling_body_lies_between_its_header_and_its_footer_in_the_first_pass() {
assert!(footer.max.y <= AREA.max.y + EDGE_SLACK, "the footer lies inside the container, at its foot: {footer:?}");
}
/// A footer inset keeps the footer's content off the sides and the foot of a container without padding (a
/// full-window dialog's buttons), under the body.
#[trial]
fn a_footer_inset_keeps_the_footer_off_the_sides_and_the_foot() {
use craft_ui::contract::Pad;
let footer_of = |footer: FooterRegion| {
let took = first_pass(ContainerProps::new().sizing(Sizing::Fill).footer(footer), None);
(took.body.unwrap(), took.footer.unwrap())
};
let (_, flush) = footer_of(FooterRegion::new());
let (body, inset) = footer_of(FooterRegion::new().inset(Pad::Regular));
assert!(inset.min.x > flush.min.x + EDGE_SLACK, "the inset moves the footer off the start side: {flush:?} {inset:?}");
assert!(inset.max.y < flush.max.y - EDGE_SLACK, "the inset lifts the footer off the foot: {flush:?} {inset:?}");
assert!(inset.max.y <= AREA.max.y + EDGE_SLACK, "the inset footer stays inside the container: {inset:?}");
assert!(body.max.y <= inset.min.y + EDGE_SLACK, "the body ends above the inset footer: {body:?} {inset:?}");
}
/// A row body beside an inline header and before an end region is measured in the line they leave, as it is shown:
/// a wrapping text there shows on one line while the line has room for it, between the header and the end region.
#[trial]