From 76ff6288ce6c005c4400f0df263b56a1d2da1732 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 15:35:42 -0800 Subject: [PATCH] About: a Licenses tab shows the app's third-party license texts AboutDialog and HostedAbout take license texts through a new `licenses` option. When an app gives any, the dialog shows a Licenses tab after Models and before the app's own tabs. The tab lists the licenses by name in a License picker when there are several, and shows the picked license's full text, monospace and selectable, in a vertically scrolling stack. Without licenses the dialog has no Licenses tab, as before. - `AboutLicense::new(name, text)` holds one license. - `AboutDialog::licenses(&[AboutLicense])` and `HostedAbout::licenses(impl IntoIterator)`. - `AboutTab::Licenses`; the hosted dialog's `tab` field takes and reports "licenses" while the dialog has licenses, and refuses it otherwise. - The picked license is kept in the dialog's container while it is open. Trials: the tab's place in the strip, the first license on opening and the picker's choice; the tab's absence without licenses and the `tab` field. The about_dialog_licenses story shows the tab with one license and with two. --- .../src/patterns/form_dialogs/about.rs | 108 ++++++++++++++---- .../patterns/form_dialogs/about/credits.rs | 21 +++- .../patterns/form_dialogs/about/stories.rs | 28 ++++- .../src/patterns/form_dialogs/mod.rs | 4 +- .../tests/it/form_dialogs/about.rs | 65 ++++++++++- 5 files changed, 197 insertions(+), 29 deletions(-) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/about.rs b/crates/ui-patterns/src/patterns/form_dialogs/about.rs index 01d82e842..19155ad4c 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/about.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/about.rs @@ -1,5 +1,5 @@ //! `AboutDialog`: Help > About in one window for every app, with the app's own data. Tabs About, Contributors and -//! Models, then the app's own tabs. +//! Models, then Licenses when the app gives license texts, then the app's own tabs. mod contributors; mod credits; @@ -7,7 +7,7 @@ mod credits; pub(crate) mod stories; pub use contributors::{CommitShare, ContributorSort, NameMode}; -pub use credits::{AboutInfo, AboutLink, Contributor, Credits, ModelCredit}; +pub use credits::{AboutInfo, AboutLicense, AboutLink, Contributor, Credits, ModelCredit}; use crate::buttons::{Button, IconButton, Link}; use crate::choice::Segmented; @@ -29,6 +29,7 @@ use crate::sections::{DialogRole, FooterButton}; use crate::style::TypeRole; use crate::table::Table; use crate::tabs::{Tab, TabKind, TabStrip}; +use crate::text::SelectableText; use contributors::{Writer, sorted_indices}; use craft_behavior::{ColumnKey, ColumnWidth, EditEvent, IconId, Mixed, SelectionChange, keyed}; use craft_theme::Variant; @@ -45,6 +46,9 @@ craft_ui::words! { about_tab: "aboutDialog.tab" = "About"; contributors_tab: "aboutDialog.contributors" = "Contributors"; models_tab: "aboutDialog.models" = "Models"; + licenses_tab: "aboutDialog.licenses" = "Licenses"; + /// The name of the Licenses tab's picker, which lists the licenses by name. + license: "aboutDialog.license" = "License"; /// The footer button of the listed layout ([`AboutLayout::Listed`]). close: "aboutDialog.close" = "Close"; version: template "aboutDialog.version" = "Version {version}"; @@ -106,7 +110,9 @@ pub enum AboutTab { Contributors, /// The credited AI models. Models, - /// The app's own tab at this position in the app's tabs, shown after Models. + /// The app's third-party license texts, shown after Models when the app gives any. + Licenses, + /// The app's own tab at this position in the app's tabs, shown after Models and Licenses. App(u8), } @@ -123,7 +129,7 @@ pub enum AboutLayout { Listed, } -/// A tab the app adds after Models: a name for the hosted dialog's `tab` field, a title and a body. +/// A tab the app adds after Models and Licenses: a name for the hosted dialog's `tab` field, a title and a body. /// /// The body is `Send` because a [`HostedAbout`] lives on the dialog stack, which needs its dialogs `Send`. pub struct AboutAppTab { @@ -148,6 +154,8 @@ struct View { descending: bool, /// The contributors show as a table; the grab bag of name links otherwise. table: bool, + /// The position of the license the Licenses tab shows. + license: usize, } /// The Models table's columns, the first of which holds the row label. @@ -235,12 +243,15 @@ impl Outcome for AboutOutput { /// header press sorts by its column, activating a row (Enter or a double click) reports the profile URL, and the /// row's tooltip is the summary. /// - **Models.** A table of the credited models with their commits, share of all commits and lines. -/// - **App tabs.** The app's own [`AboutAppTab`]s ([`app_tabs`](AboutDialog::app_tabs)) follow Models, each body in a -/// vertically scrolling stack. +/// - **Licenses.** Shown only when the app gives [`AboutLicense`]s ([`licenses`](AboutDialog::licenses)): a License +/// picker that lists them by name when there are several, then the picked license's full text, monospace and +/// selectable, in a vertically scrolling stack. +/// - **App tabs.** The app's own [`AboutAppTab`]s ([`app_tabs`](AboutDialog::app_tabs)) follow Models and Licenses, +/// each body in a vertically scrolling stack. /// -/// The name mode, the sort order and the view are kept in the dialog's container while it is open, and so is the tab -/// unless [`tab`](AboutDialog::tab) binds it. Links are reported -/// in [`AboutOutput::link`] and never opened from here. Enter and Escape close the dialog. +/// The name mode, the sort order, the view and the picked license are kept in the dialog's container while it is open, +/// and so is the tab unless [`tab`](AboutDialog::tab) binds it. Links are reported in [`AboutOutput::link`] and never +/// opened from here. Enter and Escape close the dialog. #[must_use = "show the dialog with `show`"] #[derive(crate::contract::Pattern, crate::contract::Props)] pub struct AboutDialog<'a> { @@ -252,7 +263,10 @@ pub struct AboutDialog<'a> { /// Binds the shown tab to `tab`; the dialog opens on it. #[prop] tab: Option>, - /// The app's own tabs, shown after Models. + /// The third-party license texts the Licenses tab shows; without any the dialog has no Licenses tab. + #[prop] + licenses: Option<&'a [AboutLicense]>, + /// The app's own tabs, shown after Models and Licenses. #[prop] app_tabs: Option<&'a mut [AboutAppTab]>, /// How the About tab lays out the info, and the footer button that goes with it. @@ -263,12 +277,13 @@ pub struct AboutDialog<'a> { impl<'a> AboutDialog<'a> { /// The dialog over `info` and `credits`, opening on the About tab. pub fn new(info: &'a AboutInfo, credits: &'a Credits) -> Self { - AboutDialog { info, credits, open: None, tab: None, app_tabs: None, layout: AboutLayout::default() } + AboutDialog { info, credits, open: None, tab: None, licenses: None, app_tabs: None, layout: AboutLayout::default() } } /// Shows the dialog. pub fn show(self, ui: &mut Ui) -> AboutOutput { - let AboutDialog { info, credits, open, tab, mut app_tabs, layout } = self; + let AboutDialog { info, credits, open, tab, licenses, mut app_tabs, layout } = self; + let licenses = licenses.unwrap_or_default(); // The strip shows the titles while the body draws a tab, so it reads its own copy of them. let app_titles: Vec