From 6cc5affef5b24abc47d44be3d870283656e19b3c Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Thu, 19 Nov 2026 13:57:48 +0000 Subject: [PATCH] look-rest-2: LeastWidth::WideDialog and Dialog::least_width; the listed About is a wide dialog, as WordCraft's; trial --- crates/ui-contract/src/contract/container.rs | 4 ++++ crates/ui-panels/src/dialog/modal.rs | 8 ++++++++ .../src/patterns/form_dialogs/about.rs | 8 ++++++-- .../ui-patterns/tests/it/form_dialogs/about.rs | 16 ++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index c0d16b99e..984a806e8 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -200,6 +200,9 @@ pub enum LeastWidth { DialogSideButton, /// `size.rail.width` per column: a tool rail of this many columns, as wide as the shell slot that holds it. Rail(std::num::NonZeroU8), + /// `size.dialog.least` and `size.dialog.wrap` together: a wide dialog, as wide as a dialog's least content beside a + /// paragraph's line (an About dialog whose tabs hold credit tables). + WideDialog, /// Five `size.rail.width`: a page's side menu (a File page's list of pages), wide enough that its rows read as a /// band beside the page, not as buttons cut to their labels. SideMenu, @@ -214,6 +217,7 @@ impl LeastWidth { LeastWidth::DialogButton => tokens.size.dialog.button, LeastWidth::DialogSideButton => tokens.size.dialog.side_button, LeastWidth::Rail(columns) => tokens.size.rail.width * f32::from(columns.get()), + LeastWidth::WideDialog => tokens.size.dialog.least + tokens.size.dialog.wrap, LeastWidth::SideMenu => tokens.size.rail.width * 5.0, } } diff --git a/crates/ui-panels/src/dialog/modal.rs b/crates/ui-panels/src/dialog/modal.rs index c7af4e7db..6e63d48e2 100644 --- a/crates/ui-panels/src/dialog/modal.rs +++ b/crates/ui-panels/src/dialog/modal.rs @@ -245,6 +245,14 @@ impl<'a> Dialog<'a> { self } + /// The least width of the dialog's content from the size role `least`, in place of `size.dialog.least`: a wide + /// dialog (`LeastWidth::WideDialog`) whose tabs hold tables. + #[must_use] + pub fn least_width(mut self, least: crate::contract::LeastWidth) -> Self { + self.props = self.props.least_width(least); + self + } + /// The dialog reports the alert-dialog role instead of the dialog role. #[must_use] pub(super) fn alert(mut self) -> Self { diff --git a/crates/ui-patterns/src/patterns/form_dialogs/about.rs b/crates/ui-patterns/src/patterns/form_dialogs/about.rs index f035242f8..49b4beb8e 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/about.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/about.rs @@ -13,8 +13,8 @@ use crate::buttons::{Button, IconButton, Link}; use crate::choice::Segmented; use crate::contract::Gap; use crate::contract::{ - Bind, CollectionEvent, ColumnEvent, ColumnSort, ColumnSpec, Entry, NoValue, Outcome, Props as _, Remember as _, Scroll, SelectMode, Show as _, - ShowCollection as _, ShowContainer as _, clicked, + Bind, CollectionEvent, ColumnEvent, ColumnSort, ColumnSpec, Entry, LeastWidth, NoValue, Outcome, Props as _, Remember as _, Scroll, SelectMode, + Show as _, ShowCollection as _, ShowContainer as _, clicked, }; use crate::dialog::{Dialog, DialogId, DialogOutput, DialogResult, DialogStack, FieldRefusal, StackDialog, dialog_id}; use crate::display::{Divider, Shade, Text}; @@ -298,6 +298,10 @@ impl<'a> AboutDialog<'a> { if let Some(open) = open { dialog = dialog.opened(open); } + // The listed layout is a wide dialog, as WordCraft's About, whose tabs hold the credit tables. + if layout == AboutLayout::Listed { + dialog = dialog.least_width(LeastWidth::WideDialog); + } let shown_dialog = dialog.show(ui, |ui, cx| { let mut kept = if cx.appeared() { View::default() } else { cx.memory::().clone() }; // A bound tab is the caller's each pass, so a tab set from outside shows on the next pass. diff --git a/crates/ui-patterns/tests/it/form_dialogs/about.rs b/crates/ui-patterns/tests/it/form_dialogs/about.rs index 302674a9e..ab6909f04 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/about.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/about.rs @@ -71,6 +71,22 @@ fn the_listed_about_tab_stands_one_item_to_a_line_and_closes_with_close() { assert_eq!(links.borrow().as_slice(), ["https://example.org".to_owned()]); } +/// The listed layout is a wide dialog (`LeastWidth::WideDialog`), as WordCraft's About: wider than the centred one +/// with the same text. +#[trial] +fn the_listed_about_is_a_wide_dialog() { + let width = |layout: AboutLayout| { + let mut fixture = Fixture::new(move |ui| { + let info = AboutInfo::new("PhotoCraft", "An image editor.", "1.0"); + let _ = AboutDialog::new(&info, &CREDITS).layout(layout).show(ui); + }); + fixture.room(Vec2::new(1400.0, 1000.0)).idle(30); + fixture.by_role(Role::DIALOG).first().expect("the dialog shows").rect.width() + }; + let (listed, centred) = (width(AboutLayout::Listed), width(AboutLayout::Centred)); + assert!(listed > centred + 200.0, "the listed About is a wide dialog: {listed} against {centred}"); +} + #[trial] fn about_tab_is_a_field() { let host = Rc::new(RefCell::new(DialogHost::new()));