From 2d8b8429548e3f4b05acbee0f9ed1882762ce7f9 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 21 Nov 2026 19:48:46 +0000 Subject: [PATCH 1/4] A content-sized shell slot runs its content in the room it can grow into A SlotSize::Content slot ran its content in the rect it was laid out at, the extent its content took in the last pass. A child that fills its height there is capped at that room, so content of fill-height containers (the ribbon's groups) could never grow the slot past its first height, and their controls ran past their containers' feet. The slot's pane is now as large as its content from its outer edge (ShellPane::at_content_extent, which covers bottom and side panes as well as the top), in the room from that edge to the far edge of what the slots before it leave. The window is still laid out at the kept extent, and remeasure lays it out again when the pane's extent differs. --- crates/ui-contract/src/contract/body/hooks.rs | 4 +- crates/ui-contract/src/contract/body/size.rs | 9 +- crates/ui-contract/src/contract/container.rs | 19 ++-- crates/ui-contract/src/contract/mount.rs | 15 ++- crates/ui-shell/src/shell/app_shell.rs | 46 ++++----- crates/ui-shell/src/shell/regions.rs | 11 ++- crates/ui-shell/tests/it/shell/app_shell.rs | 98 ++++++++++++++++++- 7 files changed, 158 insertions(+), 44 deletions(-) diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index bf9e23c47..2ff1164aa 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -1787,10 +1787,10 @@ impl BodyHooks<'_> { fn measure_room(&mut self, comp: &mut C, at: &Measuring<'_, '_>, cx: &mut Cx<'_, C>) -> Result { let props = &self.props; // A mount outside the flow takes no room in a parent's sizing pass, so its regions run only when it is - // measured itself. A pane as tall as its content takes its height in the flow. + // measured itself. A pane as large as its content takes its extent in the flow. let flows = match &props.mount { Mount::Inline => true, - Mount::Pane(pane) => pane.content_height, + Mount::Pane(pane) => pane.content_extent, _ => false, }; if !flows && at.ui.is_sizing_pass() { diff --git a/crates/ui-contract/src/contract/body/size.rs b/crates/ui-contract/src/contract/body/size.rs index 1cb5f02c7..6111db511 100644 --- a/crates/ui-contract/src/contract/body/size.rs +++ b/crates/ui-contract/src/contract/body/size.rs @@ -5,7 +5,7 @@ use super::placement::overlay_of; use super::regions::{RegionSizes, end_full_height, footer_in_body, footer_in_end}; use super::scroll::scroll_of; use crate::contract::run::ShowAt; -use crate::contract::{ContainerProps, Mount, PadEdges, ShellPane, Sizing}; +use crate::contract::{ContainerProps, Mount, PadEdges, PaneEdge, ShellPane, Sizing}; use crate::runtime::egui::areas; use crate::runtime::env::Env; use crate::runtime::layout_memory; @@ -103,7 +103,8 @@ impl<'b> BodyHooks<'b> { /// from its content until the user sizes it; an inline container follows its props. pub(super) fn sizing(&self, props: &ContainerProps) -> Sizing { match &props.mount { - Mount::Pane(pane) if pane.content_height => Sizing::FillWidth, + Mount::Pane(pane) if pane.content_extent && matches!(pane.edge, PaneEdge::Start | PaneEdge::End) => Sizing::FillHeight, + Mount::Pane(pane) if pane.content_extent => Sizing::FillWidth, Mount::Pane(_) | Mount::Window { .. } => Sizing::Fill, Mount::Layer(_) | Mount::Viewport { .. } | Mount::FullWindow if self.fixed => Sizing::Fill, Mount::Layer(_) | Mount::Viewport { .. } => Sizing::Content, @@ -327,9 +328,9 @@ impl<'b> BodyHooks<'b> { None => room, } } - // A pane as tall as its content runs in the rect its caller laid out. + // A pane as large as its content runs in the rect its caller laid out. _ => match (&props.mount, at) { - (Mount::Pane(ShellPane { at: Some(rect), content_height: true, .. }), _) => rect.size(), + (Mount::Pane(ShellPane { at: Some(rect), content_extent: true, .. }), _) => rect.size(), (_, ShowAt::Rect(rect)) => rect.size(), (_, ShowAt::Flow) => { let room = crate::layout::flow_room(ui); diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 13a48e3c9..327398781 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -72,8 +72,10 @@ impl Mount { /// its siblings (so a pane can overlay another) and ignores the extent. Otherwise an edge pane takes /// [`extent`](Self::extent) along its edge from the room left, or, without an extent, the size it first took, which it /// keeps in pane memory until the user resizes it. The central pane fills what the edge panes leave. A pane at a rect -/// that is as tall as its content (a content-sized embedded shell's body) takes the rect's width, its content's height -/// from the rect's top, and that room in the flow of its parent. +/// that is as large as its content along its edge (a content-sized embedded shell's body, a slot sized by its content) +/// takes the rect's cross extent, its content's extent from the rect's outer edge, and that room in the flow of its +/// parent: a top or central pane its height from the rect's top, a bottom pane its height from the rect's bottom, a +/// start or end pane its width from that side. #[derive(Clone, Copy, Debug, PartialEq)] #[non_exhaustive] pub struct ShellPane { @@ -85,14 +87,14 @@ pub struct ShellPane { pub extent: Option, /// The rect the caller laid the pane out in. pub at: Option, - /// The pane at `at` is as tall as its content. - pub(crate) content_height: bool, + /// The pane at `at` is as large as its content along its edge. + pub(crate) content_extent: bool, } impl ShellPane { /// The central pane named `name`. pub const fn new(name: &'static str) -> Self { - ShellPane { name, edge: PaneEdge::Center, extent: None, at: None, content_height: false } + ShellPane { name, edge: PaneEdge::Center, extent: None, at: None, content_extent: false } } /// The pane at `edge`. @@ -113,11 +115,12 @@ impl ShellPane { self } - /// The pane at `rect`, as tall as its content from the rect's top, taking that room in its parent's flow. + /// The pane in `rect`, as large as its content along its edge from the rect's outer edge, taking that room in its + /// parent's flow. `rect` is the room the content may take. #[doc(hidden)] - pub const fn at_content_height(mut self, rect: Rect) -> Self { + pub const fn at_content_extent(mut self, rect: Rect) -> Self { self.at = Some(rect); - self.content_height = true; + self.content_extent = true; self } } diff --git a/crates/ui-contract/src/contract/mount.rs b/crates/ui-contract/src/contract/mount.rs index 34137bf9a..fc2e44b89 100644 --- a/crates/ui-contract/src/contract/mount.rs +++ b/crates/ui-contract/src/contract/mount.rs @@ -143,11 +143,20 @@ pub(super) fn pane_grip_id(id: Id) -> Id { impl Host for PaneHost { fn run(&mut self, id: Id, parent: &mut Ui, env: &Env, pass: &mut HostPass<'_>) { - // A pane the caller laid out shows in its rect and leaves the room of its siblings alone; one as tall as its - // content flows from the rect's top and takes its height in the parent's flow. + // A pane the caller laid out shows in its rect and leaves the room of its siblings alone; one as large as its + // content flows from the rect's outer edge and takes its extent in the parent's flow. if let Some(rect) = self.0.at { - if self.0.content_height { + if self.0.content_extent { + let rtl = env.direction.is_rtl(); let builder = egui::UiBuilder::new().max_rect(rect); + let builder = match self.0.edge { + PaneEdge::Bottom => builder.layout(egui::Layout::bottom_up(egui::Align::Min)), + PaneEdge::Start | PaneEdge::End if (self.0.edge == PaneEdge::Start) == rtl => { + builder.layout(egui::Layout::right_to_left(egui::Align::Min)) + } + PaneEdge::Start | PaneEdge::End => builder.layout(egui::Layout::left_to_right(egui::Align::Min)), + _ => builder, + }; let mut ui = crate::runtime::egui::alloc::child(parent, builder); pass(&mut ui, Some(ShowAt::Flow), None); crate::runtime::egui::alloc::advance_past(parent, ui.min_rect()); diff --git a/crates/ui-shell/src/shell/app_shell.rs b/crates/ui-shell/src/shell/app_shell.rs index 12105351e..3265508d7 100644 --- a/crates/ui-shell/src/shell/app_shell.rs +++ b/crates/ui-shell/src/shell/app_shell.rs @@ -653,6 +653,15 @@ impl<'a, S> AppShell<'a, S> { let panels_hidden = kept.reveal.panels_hidden(); let rect_of = |key| regions.slots.iter().find(|(shown, _)| *shown == key).map_or(Rect::ZERO, |(_, rect)| *rect); + // The room a content slot can grow into: from its outer edge to the far edge of what the slots before it + // leave. Its content runs there, so it measures at its own extent, never at the extent it was laid out at. + let window_rect = cx.rect; + let grow_room = |key: SlotKey| { + let Some(at) = claims.iter().position(|claim| claim.key == key) else { return Rect::ZERO }; + let mut claimed = claims[..=at].to_vec(); + claimed[at].extent = f32::INFINITY; + layout(window_rect, &claimed, rtl).slots.get(at).map_or(Rect::ZERO, |(_, rect)| *rect) + }; // The extents the content slots were laid out at, and what their content took in this pass. let measured_before = kept.measured.clone(); let mut measured_now: Vec<(SlotKey, f32)> = Vec::new(); @@ -667,7 +676,7 @@ impl<'a, S> AppShell<'a, S> { } if let Some((scope, SlotBody(page))) = page.as_mut() { let pane = ShellPane::new("page"); - let pane = if content_room.is_some() { pane.at_content_height(regions.body) } else { pane.at(regions.body) }; + let pane = if content_room.is_some() { pane.at_content_extent(regions.body) } else { pane.at(regions.body) }; let mut region = ShellRegion::pane(pane).label(body_label.clone()); region.props = region.props.command_scope(*scope); let shown = region.show(ui, |ui, bcx| page(ui, bcx, app)); @@ -690,8 +699,10 @@ impl<'a, S> AppShell<'a, S> { let by_content = placed.sized_by_content(); let along_x = placed.along_x(); let Placed { slot, edge, named, add, .. } = placed; - let at = rect_of(slot.key()); - let pane = ShellPane::new(slot.key()).edge(*edge).extent(extent).at(at); + // A slot sized by its content is as large as its content from its outer edge, in the room it + // can grow into; any other slot fills its rect. + let pane = ShellPane::new(slot.key()).edge(*edge).extent(extent); + let pane = if by_content { pane.at_content_extent(grow_room(slot.key())) } else { pane.at(rect_of(slot.key())) }; // Every slot is a chrome pane: it paints the surface under its bar or rail and the rule toward // the body. let mut region = ShellRegion::chrome(pane).id_salt(("slot", slot.key())); @@ -709,28 +720,19 @@ impl<'a, S> AppShell<'a, S> { region.show(ui, |ui, bcx| add(ui, bcx, app)); continue; } - // The slot's extent along its edge: what its content allocated, plus what the pane keeps + // The slot's extent along its edge is the pane's: its content's, with what the pane keeps // around its body (its rule). A top or bottom slot's content fills its width and is as tall - // as it is; a rail's is as wide as it is. The content is read from the `Ui` it allocated in, - // never from the stack's response: a response rect is clipped to the pane (`sense_root`), so - // it can never report more than the extent the slot was laid out at. - let took = region + // as it is; a rail's is as wide as it is. + let pane = region .show(ui, |ui, bcx| { - let room = ui.max_rect(); - let inset = (if along_x { at.width() - room.width() } else { at.height() - room.height() }).max(0.0); let stack = if along_x { Stack::new() } else { Stack::new().fill_width() }; - stack - .show(ui, |ui, _| { - add(ui, bcx, app); - let content = ui.min_rect(); - if along_x { content.width() } else { content.height() } - }) - .inner - .map(|content| content + if inset.is_finite() { inset } else { 0.0 }) + stack.show(ui, |ui, _| add(ui, bcx, app)); }) - .inner - .flatten(); - if let Some(took) = took.filter(|took| took.is_finite() && *took > 0.0) { + .output + .response + .rect; + let took = if along_x { pane.width() } else { pane.height() }; + if took.is_finite() && took > 0.0 { measured_now.push((key, took)); } } @@ -740,7 +742,7 @@ impl<'a, S> AppShell<'a, S> { // mode's surround (Focus's black). Otherwise the body paints what it shows, and the gaps between its parts // (the dock's gutters) show the window's background; Immersive's body fills the room with its own canvas. let pane = ShellPane::new("body"); - let pane = if content_room.is_some() { pane.at_content_height(regions.body) } else { pane.at(regions.body) }; + let pane = if content_room.is_some() { pane.at_content_extent(regions.body) } else { pane.at(regions.body) }; let mut center = ShellRegion::pane(pane).label(body_label.clone()); let surround = if only && !host_only { Some(SurfaceKind::Scrim) } else { mode.surround() }; if let Some(surface) = surround { diff --git a/crates/ui-shell/src/shell/regions.rs b/crates/ui-shell/src/shell/regions.rs index 332644a37..ade420978 100644 --- a/crates/ui-shell/src/shell/regions.rs +++ b/crates/ui-shell/src/shell/regions.rs @@ -22,10 +22,13 @@ pub enum SlotSize { OptionsBarNarrow, /// `size.rail.width`: the default extent of a start or end slot. RailWidth, - /// As tall (a top or bottom slot) or as wide (a start or end slot) as its content: the extent the content took the - /// last time the slot showed, and the edge's default until it first shows. The slot stacks its content from its - /// outer edge instead of centring one line in it, so content of more than one line (a ribbon: a tab strip over a - /// group row) gets its own height and the slot's full width. Outside a shell it resolves to `size.bar.options`. + /// As tall (a top or bottom slot) or as wide (a start or end slot) as its content. The window is laid out at the + /// extent the content took the last time the slot showed (the edge's default until it first shows), while the + /// content runs in the room the slot can grow into, from its outer edge to the far edge of what the slots before it + /// leave: it measures at its own extent, and when that differs the shell lays the window out again in the same + /// frame. The slot stacks its content from its outer edge instead of centring one line in it, so content of more + /// than one line (a ribbon: a tab strip over a group row) gets its own height and the slot's full width. Outside a + /// shell it resolves to `size.bar.options`. Content, } diff --git a/crates/ui-shell/tests/it/shell/app_shell.rs b/crates/ui-shell/tests/it/shell/app_shell.rs index 0ae4eb778..5dd6ab672 100644 --- a/crates/ui-shell/tests/it/shell/app_shell.rs +++ b/crates/ui-shell/tests/it/shell/app_shell.rs @@ -3,10 +3,11 @@ //! body, and its band keeps the window's ends and moves the window. use craft_host::target::ShellInfo; +use craft_theme::Size; use craft_ui::bars::{Bar, BarKind}; use craft_ui::buttons::Button; use craft_ui::choice::Checkbox; -use craft_ui::contract::{Bind, CommandSet, MemoProps, MemoView, Props as _, Scroll, Show as _, ShowContainer as _}; +use craft_ui::contract::{Bind, CommandSet, MemoProps, MemoView, Props as _, Scroll, Show as _, ShowContainer as _, Sizing}; use craft_ui::dialog::Dialog; use craft_ui::display::Text; use craft_ui::layout_components::{Row, Stack}; @@ -138,6 +139,101 @@ fn a_top_slot_sized_by_its_content_stacks_it_and_takes_its_height() { assert!(body.min.y >= row.max.y - SLACK, "the body {body:?} starts under the row {row:?}"); } +/// The labels of a column of buttons taller than a slot's default extent. +const TALL: [&str; 6] = ["Paste", "Cut", "Copy", "Format Painter", "Clipboard", "Styles"]; + +/// The rect of the fill-height column a content slot holds and of each of its buttons, from the last run. +type Column = Rc)>>; + +fn column() -> Column { + Rc::new(RefCell::new((Rect::NOTHING, Vec::new()))) +} + +/// A column of `labels` that fills its height, as a ribbon group does, recording its rects in `seen`. +fn fill_column(ui: &mut Ui, labels: &[&'static str], seen: &Column) { + let mut buttons = Vec::new(); + let column = Stack::new() + .sizing(Sizing::FillHeight) + .show(ui, |ui, _| { + for label in labels { + buttons.push(Button::new(*label).show(ui).rect); + } + }) + .output + .rect; + *seen.borrow_mut() = (column, buttons); +} + +/// A content slot whose content fills its height grows to that content, at the top and at the bottom edge: its +/// content runs in the room the slot can grow into, not in the extent it was first laid out at, so the column takes +/// its buttons' height and the slot takes the column's. +#[trial] +fn a_slot_sized_by_its_content_grows_to_a_child_that_fills_its_height() { + let (top, bottom) = (column(), column()); + let regions = Rc::new(RefCell::new(None)); + let (top_seen, bottom_seen, out) = (Rc::clone(&top), Rc::clone(&bottom), Rc::clone(®ions)); + let mut fixture = Fixture::new(move |ui| { + let shown = AppShell::new(WindowKey::main()) + .top(Slot::new("ribbon").size(SlotSize::Content), |ui, _, _: &mut ()| fill_column(ui, &TALL, &top_seen)) + .bottom(Slot::new("findBar").size(SlotSize::Content), |ui, _, _: &mut ()| fill_column(ui, &TALL, &bottom_seen)) + .body(|_, _, _| {}) + .show(ui, &mut ()); + *out.borrow_mut() = Some(shown.regions); + }); + fixture.room(Vec2::new(600.0, 700.0)).settle(); + let regions = regions.borrow().clone().expect("the shell shows"); + const SLACK: f32 = 1.0; + for (key, seen) in [("ribbon", &top), ("findBar", &bottom)] { + let slot = regions.slots.iter().find(|(shown, _)| *shown == key).map(|(_, rect)| *rect).expect("the slot shows"); + let (column, buttons) = seen.borrow().clone(); + assert_eq!(buttons.len(), TALL.len(), "{key}: every button shows"); + for button in &buttons { + assert!(column.expand(SLACK).contains_rect(*button), "{key}: the button {button:?} lies in its column {column:?}"); + } + assert!(slot.expand(SLACK).contains_rect(column), "{key}: the slot {slot:?} holds its column {column:?}"); + } + let (top_slot, bottom_slot) = (regions.slots[0].1, regions.slots[1].1); + assert!( + regions.body.min.y >= top_slot.max.y - SLACK && regions.body.max.y <= bottom_slot.min.y + SLACK, + "the body {:?} lies between the slots", + regions.body + ); + assert!((bottom_slot.max.y - 700.0).abs() <= SLACK, "the bottom slot {bottom_slot:?} stands on the window's bottom edge"); +} + +/// A settled frame runs a content slot's content once, in one pass: its measure is reused while its inputs are +/// unchanged. A frame where the content grows (a denser theme makes every button taller) lays the window out again at +/// most once and shows the new extent in that frame. +#[trial] +fn a_content_slot_runs_its_content_once_per_settled_frame_and_grows_in_one_frame() { + let runs = Rc::new(Cell::new(0_u32)); + let seen = column(); + let regions = Rc::new(RefCell::new(None)); + let (count, column, out) = (Rc::clone(&runs), Rc::clone(&seen), Rc::clone(®ions)); + let mut fixture = Fixture::new(move |ui| { + let shown = AppShell::new(WindowKey::main()) + .top(Slot::new("ribbon").size(SlotSize::Content), |ui, _, _: &mut ()| { + count.set(count.get() + 1); + fill_column(ui, &TALL, &column); + }) + .body(|_, _, _| {}) + .show(ui, &mut ()); + *out.borrow_mut() = Some(shown.regions); + }); + fixture.room(Vec2::new(600.0, 700.0)).density(Size::Compact).settle(); + let before = seen.borrow().0; + runs.set(0); + fixture.frame(Vec::new()); + assert_eq!(fixture.passes(), 1, "a settled frame runs one pass"); + assert_eq!(runs.get(), 1, "a settled frame runs the slot's content once"); + fixture.density(Size::Comfortable).frame(Vec::new()); + assert!(fixture.passes() <= 2, "the frame the content grows in lays the window out again at most once: {} passes", fixture.passes()); + let slot = regions.borrow().as_ref().and_then(|regions| regions.slots.first().map(|(_, rect)| *rect)).expect("the slot shows"); + let grown = seen.borrow().0; + assert!(grown.height() > before.height() + 1.0, "the denser theme makes the column taller: {before:?} to {grown:?}"); + assert!(slot.expand(1.0).contains_rect(grown), "in the frame it grows in, the slot {slot:?} holds the grown column {grown:?}"); +} + /// A check box with its label after it sits on the options slot's middle, as a button beside it does: the slot is /// shorter than the bar asks for, and the bar centres its members in it. #[trial] From 5366157e63ea58feb3f2d093acdd7022426ed4d9 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 21 Nov 2026 20:37:02 +0000 Subject: [PATCH 2/4] A content slot records its extent only from its own real run The shell recorded a content slot's extent from any run of its content, including the scope's measuring run, which alone runs for an embedded shell out of sight. The slot's own body now says whether it ran for real, and only that run records. A content slot's pane no longer carries an extent: a pane at a rect ignores it. The out-of-sight trial also holds a content slot, which does not run. --- crates/ui-shell/src/shell/app_shell.rs | 33 +++++++++++--------- crates/ui-shell/tests/it/dialog/contained.rs | 15 +++++++-- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/crates/ui-shell/src/shell/app_shell.rs b/crates/ui-shell/src/shell/app_shell.rs index 3265508d7..4b93f560d 100644 --- a/crates/ui-shell/src/shell/app_shell.rs +++ b/crates/ui-shell/src/shell/app_shell.rs @@ -695,14 +695,17 @@ impl<'a, S> AppShell<'a, S> { if !*shown || covers(&placed.slot, only) != covering { continue; } - let extent = placed.extent(&tokens, &measured_before); let by_content = placed.sized_by_content(); let along_x = placed.along_x(); - let Placed { slot, edge, named, add, .. } = placed; // A slot sized by its content is as large as its content from its outer edge, in the room it - // can grow into; any other slot fills its rect. - let pane = ShellPane::new(slot.key()).edge(*edge).extent(extent); - let pane = if by_content { pane.at_content_extent(grow_room(slot.key())) } else { pane.at(rect_of(slot.key())) }; + // can grow into; any other slot takes its extent and fills its rect. + let pane = ShellPane::new(placed.slot.key()).edge(placed.edge); + let pane = if by_content { + pane.at_content_extent(grow_room(placed.slot.key())) + } else { + pane.extent(placed.extent(&tokens, &measured_before)).at(rect_of(placed.slot.key())) + }; + let Placed { slot, named, add, .. } = placed; // Every slot is a chrome pane: it paints the surface under its bar or rail and the rule toward // the body. let mut region = ShellRegion::chrome(pane).id_salt(("slot", slot.key())); @@ -722,17 +725,17 @@ impl<'a, S> AppShell<'a, S> { } // The slot's extent along its edge is the pane's: its content's, with what the pane keeps // around its body (its rule). A top or bottom slot's content fills its width and is as tall - // as it is; a rail's is as wide as it is. - let pane = region - .show(ui, |ui, bcx| { - let stack = if along_x { Stack::new() } else { Stack::new().fill_width() }; - stack.show(ui, |ui, _| add(ui, bcx, app)); - }) - .output - .response - .rect; + // as it is; a rail's is as wide as it is. Only the slot's own real run records it: a run in a + // sizing pass (the scope's measuring run, which alone runs for a shell out of sight) is not + // what shows. + let shown = region.show(ui, |ui, bcx| { + let stack = if along_x { Stack::new() } else { Stack::new().fill_width() }; + stack.show(ui, |ui, _| add(ui, bcx, app)); + !ui.is_sizing_pass() + }); + let pane = shown.output.response.rect; let took = if along_x { pane.width() } else { pane.height() }; - if took.is_finite() && took > 0.0 { + if shown.inner == Some(true) && took.is_finite() && took > 0.0 { measured_now.push((key, took)); } } diff --git a/crates/ui-shell/tests/it/dialog/contained.rs b/crates/ui-shell/tests/it/dialog/contained.rs index e049c8daa..70a82595e 100644 --- a/crates/ui-shell/tests/it/dialog/contained.rs +++ b/crates/ui-shell/tests/it/dialog/contained.rs @@ -6,7 +6,7 @@ use craft_ui::dialog::Dialog; use craft_ui::layout_components::Stack; use craft_ui::runtime::env::WindowKey; use craft_ui::sections::{DialogRole, FooterButton}; -use craft_ui::shell::AppShell; +use craft_ui::shell::{AppShell, Slot, SlotSize}; use craft_ui::testing::contract::clicked; use craft_ui::testing::{Fixture, trial}; use egui::{Rect, Ui}; @@ -87,16 +87,24 @@ fn a_dialog_in_an_embedded_region_is_placed_in_it_and_blocks_only_it() { } /// An embedded shell scrolled out of sight with its dialog open shows nothing and does not fail: its region has no -/// room, so neither its body nor its dialog runs in that pass. +/// room, so neither its body, its dialog nor a slot sized by its content runs in that pass. #[trial] fn an_embedded_shell_out_of_sight_shows_nothing() { - let mut fixture = Fixture::new(|ui| { + let real = Rc::new(Cell::new(0_u32)); + let count = Rc::clone(&real); + let mut fixture = Fixture::new(move |ui| { Stack::new().fill().scroll(Scroll::vertical()).show(ui, |ui, _| { let _ = Button::new("Top").show(ui); let view = ui.clip_rect(); let below = Rect::from_min_size(egui::pos2(view.min.x, view.max.y + view.height()), egui::vec2(view.width(), view.height())); let mut open = true; AppShell::embedded(WindowKey::new("out-of-sight")) + .top(Slot::new("ribbon").size(SlotSize::Content), |ui, _, _: &mut ()| { + if !ui.is_sizing_pass() { + count.set(count.get() + 1); + } + let _ = Button::new("Slot").show(ui); + }) .body(|ui, _, _| { let _ = Button::new("Hidden").show(ui); Dialog::new("Out of sight").opened(Bind::bound(&mut open)).show(ui, |_, _| {}); @@ -108,4 +116,5 @@ fn an_embedded_shell_out_of_sight_shows_nothing() { assert!(fixture.by_label("Top").is_some(), "the visible part is shown"); assert!(fixture.by_role(Role::DIALOG).is_empty(), "the dialog of a shell out of sight is not shown"); assert!(fixture.by_label("Hidden").is_none(), "the body of a shell out of sight does not run"); + assert!(fixture.by_label("Slot").is_none() && real.get() == 0, "the content slot of a shell out of sight does not run"); } From 0aa781ecf0e979163fa847f8e65d8fb5fd884cc4 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 21 Nov 2026 20:37:02 +0000 Subject: [PATCH 3/4] Trials for content rails, scrolling lists and the settled frame after a grow Content start and end rails sit at their sides in left-to-right and right-to-left windows, hold their content and settle in one pass with each rail's content run once. A content slot holding a vertically scrolling list, content-sized or filling its height, is as tall as the list's rows and the body keeps the rest of the window. The count trial's grow half also checks that the next frame is settled. SlotSize::Content documents that the slot never takes more than the room the window leaves it, and that raw egui content allocates its own extent along the slot's edge. --- crates/ui-shell/src/shell/regions.rs | 8 +- crates/ui-shell/tests/it/shell/app_shell.rs | 102 +++++++++++++++++++- 2 files changed, 105 insertions(+), 5 deletions(-) diff --git a/crates/ui-shell/src/shell/regions.rs b/crates/ui-shell/src/shell/regions.rs index ade420978..150a55d64 100644 --- a/crates/ui-shell/src/shell/regions.rs +++ b/crates/ui-shell/src/shell/regions.rs @@ -27,8 +27,12 @@ pub enum SlotSize { /// content runs in the room the slot can grow into, from its outer edge to the far edge of what the slots before it /// leave: it measures at its own extent, and when that differs the shell lays the window out again in the same /// frame. The slot stacks its content from its outer edge instead of centring one line in it, so content of more - /// than one line (a ribbon: a tab strip over a group row) gets its own height and the slot's full width. Outside a - /// shell it resolves to `size.bar.options`. + /// than one line (a ribbon: a tab strip over a group row) gets its own height and the slot's full width. + /// + /// The slot never takes more than the room the window leaves it: content larger than that, unless it scrolls, + /// is cut at the window's edge. Raw egui content allocates its own extent along the slot's edge; content that takes whatever room it is + /// offered (`ui.available_size()`) takes the whole room the slot can grow into. Outside a shell it resolves to + /// `size.bar.options`. Content, } diff --git a/crates/ui-shell/tests/it/shell/app_shell.rs b/crates/ui-shell/tests/it/shell/app_shell.rs index 5dd6ab672..fa4eda93d 100644 --- a/crates/ui-shell/tests/it/shell/app_shell.rs +++ b/crates/ui-shell/tests/it/shell/app_shell.rs @@ -202,8 +202,8 @@ fn a_slot_sized_by_its_content_grows_to_a_child_that_fills_its_height() { } /// A settled frame runs a content slot's content once, in one pass: its measure is reused while its inputs are -/// unchanged. A frame where the content grows (a denser theme makes every button taller) lays the window out again at -/// most once and shows the new extent in that frame. +/// unchanged. A frame where the content grows (a roomier density makes every button taller) lays the window out again +/// at most once, shows the new extent in that frame and leaves the next frame settled. #[trial] fn a_content_slot_runs_its_content_once_per_settled_frame_and_grows_in_one_frame() { let runs = Rc::new(Cell::new(0_u32)); @@ -230,8 +230,104 @@ fn a_content_slot_runs_its_content_once_per_settled_frame_and_grows_in_one_frame assert!(fixture.passes() <= 2, "the frame the content grows in lays the window out again at most once: {} passes", fixture.passes()); let slot = regions.borrow().as_ref().and_then(|regions| regions.slots.first().map(|(_, rect)| *rect)).expect("the slot shows"); let grown = seen.borrow().0; - assert!(grown.height() > before.height() + 1.0, "the denser theme makes the column taller: {before:?} to {grown:?}"); + assert!(grown.height() > before.height() + 1.0, "the roomier density makes the column taller: {before:?} to {grown:?}"); assert!(slot.expand(1.0).contains_rect(grown), "in the frame it grows in, the slot {slot:?} holds the grown column {grown:?}"); + runs.set(0); + fixture.frame(Vec::new()); + assert_eq!(fixture.passes(), 1, "the frame after the grow is settled: one pass"); + assert_eq!(runs.get(), 1, "the frame after the grow runs the slot's content once"); +} + +/// Content rails sit at their own sides in either reading direction, each as wide as the column it holds, and a +/// settled frame runs one pass with each rail's content once: the start rail at the reading start, the end rail at the +/// reading end, the body between them. +#[trial] +fn content_rails_sit_at_their_sides_and_settle_in_one_pass() { + const RAIL: [&str; 3] = ["Move", "Brush", "Eraser"]; + for rtl in [false, true] { + let direction = if rtl { craft_i18n::Direction::Rtl } else { craft_i18n::Direction::Ltr }; + let (start, end) = (column(), column()); + let (start_runs, end_runs) = (Rc::new(Cell::new(0_u32)), Rc::new(Cell::new(0_u32))); + let regions = Rc::new(RefCell::new(None)); + let (start_seen, end_seen, start_count, end_count, out) = + (Rc::clone(&start), Rc::clone(&end), Rc::clone(&start_runs), Rc::clone(&end_runs), Rc::clone(®ions)); + let mut fixture = Fixture::new(move |ui| { + let shown = AppShell::new(WindowKey::main()) + .start(Slot::new("tools").size(SlotSize::Content), |ui, _, _: &mut ()| { + start_count.set(start_count.get() + 1); + fill_column(ui, &RAIL, &start_seen); + }) + .end(Slot::new("inspector").size(SlotSize::Content), |ui, _, _: &mut ()| { + end_count.set(end_count.get() + 1); + fill_column(ui, &RAIL, &end_seen); + }) + .body(|_, _, _| {}) + .show(ui, &mut ()); + *out.borrow_mut() = Some(shown.regions); + }); + fixture.direction(direction).room(Vec2::new(600.0, 400.0)).settle(); + let regions = regions.borrow().clone().expect("the shell shows"); + const SLACK: f32 = 1.0; + let rect_of = |key| regions.slots.iter().find(|(shown, _)| *shown == key).map(|(_, rect)| *rect).expect("the rail shows"); + let (start_rail, end_rail) = (rect_of("tools"), rect_of("inspector")); + for (key, rail, seen) in [("tools", start_rail, &start), ("inspector", end_rail, &end)] { + let (column, buttons) = seen.borrow().clone(); + assert_eq!(buttons.len(), RAIL.len(), "RTL {rtl}, {key}: every button shows"); + for button in &buttons { + assert!(column.expand(SLACK).contains_rect(*button), "RTL {rtl}, {key}: the button {button:?} lies in its column {column:?}"); + } + assert!(rail.expand(SLACK).contains_rect(column), "RTL {rtl}, {key}: the rail {rail:?} holds its column {column:?}"); + } + let body = regions.body; + let (left, right) = if rtl { (end_rail, start_rail) } else { (start_rail, end_rail) }; + assert!(left.max.x <= body.min.x + SLACK, "RTL {rtl}: the rail {left:?} lies left of the body {body:?}"); + assert!(right.min.x >= body.max.x - SLACK, "RTL {rtl}: the rail {right:?} lies right of the body {body:?}"); + (start_runs.set(0), end_runs.set(0)); + fixture.frame(Vec::new()); + assert_eq!(fixture.passes(), 1, "RTL {rtl}: a settled frame runs one pass"); + assert_eq!((start_runs.get(), end_runs.get()), (1, 1), "RTL {rtl}: a settled frame runs each rail's content once"); + } +} + +/// A content slot holding a list that scrolls along its height is as tall as the list's rows, whether the list sizes +/// from its content or fills its height: the slot offers its content no bound along its edge, so the list shows all +/// of its rows instead of taking the window's height, and the body keeps the rest of the window. +#[trial] +fn a_content_slot_holding_a_scrolling_list_takes_the_list_height() { + for sizing in [Sizing::Content, Sizing::FillHeight, Sizing::Fill] { + let rows = Rc::new(RefCell::new(Vec::new())); + let regions = Rc::new(RefCell::new(None)); + let (seen, out) = (Rc::clone(&rows), Rc::clone(®ions)); + let mut fixture = Fixture::new(move |ui| { + let shown = AppShell::new(WindowKey::main()) + .top(Slot::new("findBar").size(SlotSize::Content), |ui, _, _: &mut ()| { + let mut buttons = Vec::new(); + Stack::new().sizing(sizing).scroll(Scroll::vertical()).show(ui, |ui, _| { + for label in ["First", "Second", "Third"] { + buttons.push(Button::new(label).show(ui).rect); + } + }); + *seen.borrow_mut() = buttons; + }) + .body(|_, _, _| {}) + .show(ui, &mut ()); + *out.borrow_mut() = Some(shown.regions); + }); + fixture.room(Vec2::new(600.0, 700.0)).settle(); + let regions = regions.borrow().clone().expect("the shell shows"); + let slot = regions.slots.iter().find(|(key, _)| *key == "findBar").map(|(_, rect)| *rect).expect("the slot shows"); + let rows = rows.borrow().iter().fold(Rect::NOTHING, |all, row| all.union(*row)); + const SLACK: f32 = 1.0; + // The rule toward the body, the stack's padding and rounding. + const AROUND: f32 = 24.0; + assert!(slot.expand(SLACK).contains_rect(rows), "{sizing:?}: the slot {slot:?} holds the list's rows {rows:?}"); + assert!(slot.height() <= rows.height() + AROUND, "{sizing:?}: the slot {slot:?} is as tall as the list's rows {rows:?}, not the window"); + let body = regions.body; + assert!( + body.min.y >= slot.max.y - SLACK && (body.max.y - 700.0).abs() <= SLACK, + "{sizing:?}: the body {body:?} keeps the window under the slot {slot:?}" + ); + } } /// A check box with its label after it sits on the options slot's middle, as a button beside it does: the slot is From f36b91287220d5783fb23c445c2b03fb226b6c29 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 21 Nov 2026 20:59:54 +0000 Subject: [PATCH 4/4] Shell trial: reset the rail run counters as two statements --- crates/ui-shell/tests/it/shell/app_shell.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-shell/tests/it/shell/app_shell.rs b/crates/ui-shell/tests/it/shell/app_shell.rs index fa4eda93d..cd4bc8a6e 100644 --- a/crates/ui-shell/tests/it/shell/app_shell.rs +++ b/crates/ui-shell/tests/it/shell/app_shell.rs @@ -282,7 +282,8 @@ fn content_rails_sit_at_their_sides_and_settle_in_one_pass() { let (left, right) = if rtl { (end_rail, start_rail) } else { (start_rail, end_rail) }; assert!(left.max.x <= body.min.x + SLACK, "RTL {rtl}: the rail {left:?} lies left of the body {body:?}"); assert!(right.min.x >= body.max.x - SLACK, "RTL {rtl}: the rail {right:?} lies right of the body {body:?}"); - (start_runs.set(0), end_runs.set(0)); + start_runs.set(0); + end_runs.set(0); fixture.frame(Vec::new()); assert_eq!(fixture.passes(), 1, "RTL {rtl}: a settled frame runs one pass"); assert_eq!((start_runs.get(), end_runs.get()), (1, 1), "RTL {rtl}: a settled frame runs each rail's content once");