From 99c2bdf38b40aa0e5e4632134b3fdfe13c530342 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Thu, 19 Nov 2026 19:54:29 +0000 Subject: [PATCH] look-7a: Pad::Page, a full-window page's margin (two and a half roomy pads, 40 pt compact), as WordCraft's File pages stand off the window; trial and the Stack story's pad choice --- .../ui-contract/src/contract/body/regions.rs | 1 + crates/ui-contract/src/contract/container.rs | 3 +++ .../src/layout_components/stories.rs | 2 +- .../tests/it/layout/stack_widths.rs | 23 ++++++++++++++++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/crates/ui-contract/src/contract/body/regions.rs b/crates/ui-contract/src/contract/body/regions.rs index db356df4f..c6062fe46 100644 --- a/crates/ui-contract/src/contract/body/regions.rs +++ b/crates/ui-contract/src/contract/body/regions.rs @@ -45,6 +45,7 @@ pub fn pad_of(tokens: &UiTokens, pad: Pad) -> f32 { Pad::Control => pads.control, Pad::Regular => pads.regular, Pad::Roomy => pads.roomy, + Pad::Page => pads.roomy * 2.5, _ => 0.0, } } diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 984a806e8..8c0e13bc5 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -135,6 +135,9 @@ pub enum Pad { Regular, /// `space.pad.roomy`. Roomy, + /// A full-window page's margin around its content: two and a half roomy pads (40 pt in the compact set), as a + /// File page's body stands off the window and its side menu. + Page, } /// The edges a container's padding tier applies to. diff --git a/crates/ui-widgets/src/layout_components/stories.rs b/crates/ui-widgets/src/layout_components/stories.rs index 90be48559..47c3f13b1 100644 --- a/crates/ui-widgets/src/layout_components/stories.rs +++ b/crates/ui-widgets/src/layout_components/stories.rs @@ -11,7 +11,7 @@ use egui::Ui; /// The gap and padding tier the Row and Stack stories edit. fn spacing(data: &mut StoryData, gap: Gap, gaps: &'static [(&'static str, Gap)]) -> (Gap, Pad) { let gap = *data.choice("gap", gap, gaps); - let pad = *data.choice("pad", Pad::Regular, &[("None", Pad::None), ("Control", Pad::Control), ("Regular", Pad::Regular), ("Roomy", Pad::Roomy)]); + let pad = *data.choice("pad", Pad::Regular, &[("None", Pad::None), ("Control", Pad::Control), ("Regular", Pad::Regular), ("Roomy", Pad::Roomy), ("Page", Pad::Page)]); (gap, pad) } diff --git a/crates/ui-widgets/tests/it/layout/stack_widths.rs b/crates/ui-widgets/tests/it/layout/stack_widths.rs index 5efdd9c7f..8baec2920 100644 --- a/crates/ui-widgets/tests/it/layout/stack_widths.rs +++ b/crates/ui-widgets/tests/it/layout/stack_widths.rs @@ -4,7 +4,7 @@ //! row there too. use craft_ui::buttons::Button; -use craft_ui::contract::{Gap, LeastWidth, Props as _, Scroll, Show as _, ShowContainer as _, Sizing, WrapWidth}; +use craft_ui::contract::{Gap, LeastWidth, Pad, Props as _, Scroll, Show as _, ShowContainer as _, Sizing, WrapWidth}; use craft_ui::display::Text; use craft_ui::layout_components::{Row, Stack}; use craft_ui::testing::{Fixture, trial}; @@ -85,6 +85,27 @@ fn a_side_menu_in_a_row_keeps_its_least_width() { assert!(menu.height() > 800.0, "the menu is as tall as the row: {menu:?}"); } +/// A page's padding stands its content off the edges by two and a half roomy pads: a File page's margin. +#[trial] +fn a_pages_padding_is_two_and_a_half_roomy_pads() { + let inset = |pad: Pad| { + let seen = Rc::new(Cell::new(Vec2::ZERO)); + let out = Rc::clone(&seen); + let mut fixture = Fixture::new(move |ui| { + let child = Cell::new(Rect::NOTHING); + let shown = Stack::new().pad(pad).show(ui, |ui, _| child.set(Button::new("Home").show(ui).rect)); + if !ui.is_sizing_pass() { + out.set(child.get().min - shown.output.rect.min); + } + }); + fixture.room(Vec2::new(800.0, 600.0)).settle(); + seen.get() + }; + let (roomy, page) = (inset(Pad::Roomy), inset(Pad::Page)); + assert!(roomy.x > 0.0, "a roomy stack pads its content: {roomy:?}"); + assert!((page.x - roomy.x * 2.5).abs() < 0.6 && (page.y - roomy.y * 2.5).abs() < 0.6, "a page pads 2.5 roomy pads: {page:?} for {roomy:?}"); +} + #[trial] fn a_stacks_wrap_width_breaks_a_long_paragraph_at_the_column() { let (plain, one_line) = shown(Stack::new, true);