diff --git a/crates/ui-patterns/src/patterns/form_dialogs/about.rs b/crates/ui-patterns/src/patterns/form_dialogs/about.rs index 01d82e842..57f4cae2c 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/about.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/about.rs @@ -114,7 +114,8 @@ pub enum AboutTab { #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum AboutLayout { - /// The blurb, the version, the community button and the link row centred, the built-with line faint; OK closes. + /// The blurb and the version, then the community button and the link row centred, then the built-with line faint, + /// the blocks set apart by the section gap; OK closes. #[default] Centred, /// From the start edge, one item to a line: the app's name as a heading, the version, the blurb, the community @@ -304,7 +305,7 @@ impl<'a> AboutDialog<'a> { } let before = kept.tab; *view.borrow_mut() = kept; - Stack::new().header(|ui, _| shown.tabs(ui, &title, &app_titles, &view)).show(ui, |ui, _| { + Stack::new().header(|ui, _| shown.tabs(ui, &title, &app_titles, &view)).fill_width().show(ui, |ui, _| { let tab = view.borrow().tab; let app = match tab { AboutTab::App(at) => app_tabs.as_deref_mut().and_then(|tabs| tabs.get_mut(usize::from(at))), @@ -398,26 +399,32 @@ impl Shown<'_> { }); return; } - Stack::new().show(ui, |ui, _| { - Text::new(info.blurb.clone()).show(ui); - Text::new(words.version.fill(&[("version", info.version.as_str())])).show(ui); - Row::new().align(RowAlign::Center).show(ui, |ui, _| { - if let Some(community) = &info.community - && clicked(&Button::new(community.label.clone()).variant(Variant::PRIMARY).id_salt("community").show(ui)) - { - *link.borrow_mut() = Some(community.url.clone()); - } + // Four blocks set apart by the section gap: the blurb and version at the start edge, the community button and + // the link row each centred across the body, the built-with line at the start edge. + Stack::new().gap(Gap::Section).fill_width().show(ui, |ui, _| { + Stack::new().show(ui, |ui, _| { + Text::new(info.blurb.clone()).show(ui); + Text::new(words.version.fill(&[("version", info.version.as_str())])).show(ui); }); - Row::new().align(RowAlign::Center).show(ui, |ui, _| { - for (at, item) in info.links.iter().enumerate() { - if at > 0 { - Text::new("·").shade(Shade::Faint).show(ui); + if let Some(community) = &info.community { + Row::new().fill_width().align(RowAlign::Center).show(ui, |ui, _| { + if clicked(&Button::new(community.label.clone()).variant(Variant::PRIMARY).id_salt("community").show(ui)) { + *link.borrow_mut() = Some(community.url.clone()); } - if clicked(&Link::new(item.label.clone()).id_salt(("link", at)).show(ui)) { - *link.borrow_mut() = Some(item.url.clone()); + }); + } + if !info.links.is_empty() { + Row::new().fill_width().align(RowAlign::Center).show(ui, |ui, _| { + for (at, item) in info.links.iter().enumerate() { + if at > 0 { + Text::new("·").shade(Shade::Faint).show(ui); + } + if clicked(&Link::new(item.label.clone()).id_salt(("link", at)).show(ui)) { + *link.borrow_mut() = Some(item.url.clone()); + } } - } - }); + }); + } Text::new(info.built_with.clone()).shade(Shade::Faint).show(ui); }); } diff --git a/crates/ui-patterns/tests/it/form_dialogs/about.rs b/crates/ui-patterns/tests/it/form_dialogs/about.rs index 18a8d3928..cfa699c89 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/about.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/about.rs @@ -95,6 +95,38 @@ fn the_listed_about_sets_its_blocks_apart() { assert!(before_caption > within + 1.0, "the built-with line stands apart from the links: {before_caption} against {within}"); } +// The centred layout (the default) sets its blocks apart: the gap from the version to the community button, from the +// button to the link row and from the link row to the built-with line is wider than the one from the blurb to the +// version. The button and the link row stand centred in the dialog, also when the dialog is wider than its lines. +#[trial] +fn the_centred_about_sets_its_blocks_apart_and_centres_the_button_and_links() { + let info = AboutInfo::new("PhotoCraft", "An image editor.", "1.0") + .community(AboutLink::new("Chat", "https://chat.example")) + .links([AboutLink::new("Website", "https://example.org"), AboutLink::new("Source", "https://example.org/source")]) + .built_with("MIT"); + let mut fixture = Fixture::new(move |ui| { + let _ = AboutDialog::new(&info, &CREDITS).show(ui); + }); + fixture.room(Vec2::new(1400.0, 1000.0)).idle(30); + let [chat, website, source] = ["Chat", "Website", "Source"].map(|name| fixture.by_label(name).expect("every link shows").rect); + let painted = |text: &str| fixture.texts().iter().find(|painted| painted.text == text).map(|painted| painted.rect).expect("the text shows"); + let (blurb, version, caption) = (painted("An image editor."), painted("Version 1.0"), painted("MIT")); + let within = version.top() - blurb.bottom(); + for (gap, what) in [ + (chat.top() - version.bottom(), "the button stands apart from the version"), + (website.top() - chat.bottom(), "the links stand apart from the button"), + (caption.top() - source.bottom(), "the built-with line stands apart from the links"), + ] { + assert!(gap > within + 1.0, "{what}: {gap} against {within}"); + } + // Centred across the body: the button and the link row share one middle, the dialog's. + let middle = fixture.by_role(Role::DIALOG).first().expect("the dialog shows").rect.center().x; + let links = website.union(source); + assert!((chat.center().x - links.center().x).abs() < 1.0, "the button and the link row share a middle: {chat:?}, {links:?}"); + assert!((chat.center().x - middle).abs() < 1.0, "the button is centred: {} against {middle}", chat.center().x); + assert!(blurb.left() < chat.left() - 10.0, "the blurb still starts at the start edge"); +} + /// The listed layout is a wide dialog (`LeastWidth::WideDialog`), as WordCraft's About: wider than the centred one /// with the same text. #[trial]