From a10089e3f62bde7fe7442ae857405ccee07d7b54 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 23:17:43 +0100 Subject: [PATCH 1/2] WIP: Dialogs: a floating dialog's body stays inside the window when it grows (photocraft#16326) Co-Authored-By: Claude Opus 5.5 From 06238616d482b566aa1956303d36fa9a8b7fe3ff Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 23:44:58 +0100 Subject: [PATCH 2/2] Dialogs: a layer's body leaves its footer room when it fills (photocraft#16326) A layer's measuring run lays its body out before the footer runs, so a body that fills the layer's room (a scrolling list, About's Contributors grab bag) took the footer's height too. The layer came out taller than its room by the footer, with empty space under the buttons, and in a small window it ran past the window's bottom edge. When what a layer with a footer took is taller than its room, the run is now taken back and the body laid out again beside the footer that run measured, as a capped inline body already is. Co-Authored-By: Claude Opus 5.5 --- crates/ui-contract/src/contract/body/hooks.rs | 21 +++++++++++ .../ui-panels/tests/it/body/footer_reserve.rs | 29 ++++++++++++++- .../tests/it/form_dialogs/about.rs | 36 +++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index bf9e23c47..61385d00c 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -329,6 +329,7 @@ impl ShapeHooks for BodyHooks<'_> { // is laid out as given the room, at the footer and header this run measured, so the children that fill share // it; its record of the content height lets later runs of the pass and kept transcripts lay it out the same. None if self.capped(&self.props, at.env, at.at) => self.measure_capped(comp, at, cx, plan), + None if self.footed_layer() => self.measure_footed_layer(comp, at, cx, plan), None => self.measure_run(comp, at, cx, plan.key, None), }; self.measured_took(took, pad, vertical) @@ -1924,6 +1925,26 @@ impl BodyHooks<'_> { } } + /// Whether the container is a layer with a footer: its body is laid out before the footer runs, so a body that + /// fills the layer's room takes the footer's height too, unless the run knows the footer from an earlier one. + fn footed_layer(&self) -> bool { + overlay_of(&self.props).is_some() && self.props.footer.is_some() && self.room.y.is_finite() + } + + /// The measuring run of a layer with a footer (photocraft#16326): while what the regions took fits the room it + /// stands; taller (a body that fills, such as a scrolling list, took the room the footer needs), the run is taken + /// back and the body is laid out again beside the footer this run measured, so the layer keeps to its room with + /// the footer as its last row. + fn measure_footed_layer(&mut self, comp: &mut C, at: &Measuring<'_, '_>, cx: &mut Cx<'_, C>, plan: MeasurePlan) -> Vec2 { + let fits = self.room.y + plan.tolerance; + let (took, kept) = crate::contract::draft(&plan.ctx, || self.measure_run(comp, at, cx, plan.key.clone(), None), |took| took.y <= fits); + if kept { + return took; + } + self.measured_footer = self.footer_size.unwrap_or(Vec2::ZERO); + self.measure_run(comp, at, cx, plan.key, None) + } + /// The extent a measuring run reports from what its regions `took`. fn measured_took(&mut self, took: Vec2, pad: Vec2, vertical: bool) -> Vec2 { // A layer hung from an opener or a rect is at least as wide as its overlay asks for, in the measuring run too, diff --git a/crates/ui-panels/tests/it/body/footer_reserve.rs b/crates/ui-panels/tests/it/body/footer_reserve.rs index 66006f283..88816c9a9 100644 --- a/crates/ui-panels/tests/it/body/footer_reserve.rs +++ b/crates/ui-panels/tests/it/body/footer_reserve.rs @@ -2,8 +2,10 @@ use craft_behavior::{DisplayOrder, ItemSource}; use craft_ui::contract::{Bind, ShowCollection as _, ShowContainer as _}; +use craft_ui::contract::{Scroll, Show as _}; use craft_ui::dialog::Dialog; -use craft_ui::layout_components::Row; +use craft_ui::display::Text; +use craft_ui::layout_components::{Row, Stack}; use craft_ui::list::{List, ListRow}; use craft_ui::sections::{DialogRole, FooterButton}; use craft_ui::testing::{Fixture, trial}; @@ -53,3 +55,28 @@ fn a_dialog_with_a_filling_body_keeps_its_footer_below_the_body_and_inside_the_s assert!(craft_ui::testing::relations::above(body, button.rect), "{label} is below the body: {:?} under {body:?}", button.rect); } } + +/// photocraft#16326: a dialog whose body holds a scrolling stack that fills, under a line of other content, keeps to +/// its share of the screen with the footer as its last row: the body leaves the footer its height instead of taking +/// the whole room and pushing the footer past it. +#[trial] +fn a_dialog_with_a_filling_scroll_body_keeps_to_its_room_with_the_footer_last() { + let mut fixture = Fixture::new(move |ui| { + let mut open = true; + Dialog::new("Pick").opened(Bind::bound(&mut open)).buttons([FooterButton::new("OK", DialogRole::Accept)]).show(ui, |ui, _| { + Text::new("Pick a row").show(ui); + Stack::new().scroll(Scroll::vertical()).fill().show(ui, |ui, _| { + for at in 0..ROWS { + Text::new(format!("Row {at}")).show(ui); + } + }); + }); + }); + fixture.room(egui::Vec2::new(1200.0, 700.0)).settle(); + let screen = fixture.ctx().content_rect(); + let dialog = fixture.by_role(craft_ui::contract::Role::DIALOG).first().expect("the dialog shows").rect; + let ok = fixture.by_label("OK").expect("the footer's OK").rect; + assert!(screen.contains_rect(dialog), "the dialog is inside the screen: {dialog:?} in {screen:?}"); + assert!(dialog.height() <= 0.9 * screen.height() + 1.0, "the dialog keeps to its share of the screen: {dialog:?} in {screen:?}"); + assert!(dialog.bottom() - ok.bottom() < 20.0, "OK is the dialog's last row: {ok:?} in {dialog:?}"); +} diff --git a/crates/ui-patterns/tests/it/form_dialogs/about.rs b/crates/ui-patterns/tests/it/form_dialogs/about.rs index 18a8d3928..464999d56 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/about.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/about.rs @@ -255,3 +255,39 @@ fn names_sort_without_at_and_case_and_undated_contributors_sort_last_both_ways() sort_by(&mut fixture, "Name"); assert_eq!(rows(&fixture, &["@zed", "Ann", "@alice", "@carol"]), ["@alice", "Ann", "@carol", "@zed"], "a display name sorts among the usernames"); } + +/// A crowd of contributors whose grab bag is taller than a small window. +static CROWD: LazyLock = LazyLock::new(|| { + let people: Vec = (0..400).map(|at| Contributor::new(format!("contributor-number-{at}")).counts(1, 1)).collect(); + Credits::new(people, Vec::new(), 400) +}); + +/// photocraft#16326: in a small window the Contributors tab, whose grab bag fills the room it is offered, keeps the +/// About dialog inside the window, and back on About the dialog stands centred again, as it opened. +#[trial] +fn about_stays_inside_a_small_window_on_contributors_and_comes_back_to_the_middle() { + let host = Rc::new(RefCell::new(DialogHost::new())); + let shown = Rc::clone(&host); + let mut fixture = Fixture::new(move |ui| shown.borrow_mut().run(ui)); + fixture.room(Vec2::new(1200.0, 700.0)); + let id = host.borrow_mut().open(HostedAbout::new(AboutInfo::new("PhotoCraft", "An image editor.", "1.0"), CROWD.clone())); + fixture.settle(); + let screen = fixture.ctx().content_rect(); + let dialog = |fixture: &Fixture| fixture.by_role(Role::DIALOG).first().expect("the dialog shows").rect; + let opened = dialog(&fixture); + assert!((opened.center().y - screen.center().y).abs() < 1.0, "About opens centred: {opened:?} in {screen:?}"); + + let ctx = fixture.ctx().clone(); + host.borrow_mut().set_json_field(&ctx, id, "tab", json!("contributors")).expect("`tab` takes Contributors"); + fixture.settle(); + let tall = dialog(&fixture); + assert!(screen.contains_rect(tall), "Contributors keeps the dialog inside the window: {tall:?} in {screen:?}"); + let ok = fixture.by_label("OK").expect("the footer's OK").rect; + assert!(tall.bottom() - ok.bottom() < 20.0, "OK is the dialog's last row: {ok:?} in {tall:?}"); + assert!(tall.height() <= 0.9 * screen.height() + 1.0, "the dialog keeps to its share of the window: {tall:?} in {screen:?}"); + + host.borrow_mut().set_json_field(&ctx, id, "tab", json!("about")).expect("`tab` takes About"); + fixture.settle(); + let back = dialog(&fixture); + assert!((back.center().y - screen.center().y).abs() < 1.0, "back on About the dialog is centred again: {back:?} in {screen:?}"); +}