From 0ccf7cba9cc73d106ae01cbaa40bd0940a037f0f Mon Sep 17 00:00:00 2001 From: Eduardo Flores Date: Sat, 9 Nov 2024 20:32:19 +0100 Subject: [PATCH] improv: moved license to a section and added docs --- examples/about/src/main.rs | 2 +- src/widget/about.rs | 89 +++++++++++++++++++++++--------------- 2 files changed, 55 insertions(+), 36 deletions(-) diff --git a/examples/about/src/main.rs b/examples/about/src/main.rs index 14a278057d1..de4fff2a5dc 100644 --- a/examples/about/src/main.rs +++ b/examples/about/src/main.rs @@ -68,7 +68,7 @@ impl cosmic::Application for App { .icon(Self::APP_ID) .version("0.1.0") .author("System 76") - .license("GPL-3.0-only") + .license("GPL-3.0-oly") .developers([("Michael Murphy", "mmstick@system76.com")]) .links([ ("Website", "https://system76.com/cosmic"), diff --git a/src/widget/about.rs b/src/widget/about.rs index 7a28479fb87..3092f208d73 100644 --- a/src/widget/about.rs +++ b/src/widget/about.rs @@ -26,7 +26,7 @@ pub struct About { comments: Option, /// The application's copyright. copyright: Option, - /// The license text. + /// The license name. license: Option, /// Artists who contributed to the application. #[setters(skip)] @@ -49,15 +49,7 @@ pub struct About { } impl<'a> About { - pub fn links(mut self, links: impl Into>) -> Self { - let links: BTreeMap<&'a str, &'a str> = links.into(); - self.links = links - .into_iter() - .map(|(k, v)| (k.to_string(), v.to_string())) - .collect(); - self - } - + /// Artists who contributed to the application. pub fn artists(mut self, artists: impl Into>) -> Self { let artists: BTreeMap<&'a str, &'a str> = artists.into(); self.artists = artists @@ -67,6 +59,7 @@ impl<'a> About { self } + /// Designers who contributed to the application. pub fn designers(mut self, designers: impl Into>) -> Self { let designers: BTreeMap<&'a str, &'a str> = designers.into(); self.designers = designers @@ -76,6 +69,7 @@ impl<'a> About { self } + /// Developers who contributed to the application. pub fn developers(mut self, developers: impl Into>) -> Self { let developers: BTreeMap<&'a str, &'a str> = developers.into(); self.developers = developers @@ -85,6 +79,7 @@ impl<'a> About { self } + /// Documenters who contributed to the application. pub fn documenters(mut self, documenters: impl Into>) -> Self { let documenters: BTreeMap<&'a str, &'a str> = documenters.into(); self.documenters = documenters @@ -94,6 +89,7 @@ impl<'a> About { self } + /// Translators who contributed to the application. pub fn translators(mut self, translators: impl Into>) -> Self { let translators: BTreeMap<&'a str, &'a str> = translators.into(); self.translators = translators @@ -103,6 +99,16 @@ impl<'a> About { self } + /// Links associated with the application. + pub fn links(mut self, links: impl Into>) -> Self { + let links: BTreeMap<&'a str, &'a str> = links.into(); + self.links = links + .into_iter() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect(); + self + } + fn license_url(&self) -> Option { let license: &dyn License = match self.license.as_ref() { Some(license) => license.parse().ok()?, @@ -126,23 +132,25 @@ pub fn about<'a, Message: Clone + 'static>( if list.is_empty() { None } else { - let developers: Vec> = list - .iter() - .map(|(name, url)| { - widget::button::custom( - widget::row() - .push(widget::text(name)) - .push(horizontal_space()) - .push(crate::widget::icon::from_name("link-symbolic").icon()) - .padding(spacing.space_xxs) - .align_y(Vertical::Center), - ) - .class(crate::theme::Button::Text) - .on_press(on_url_press(url.to_string())) - .width(Length::Fill) - .into() - }) - .collect(); + let developers: Vec> = + list.iter() + .map(|(name, url)| { + widget::button::custom( + widget::row() + .push(widget::text(name)) + .push(horizontal_space()) + .push_maybe((!url.is_empty()).then_some( + crate::widget::icon::from_name("link-symbolic").icon(), + )) + .padding(spacing.space_xxs) + .align_y(Vertical::Center), + ) + .class(crate::theme::Button::Text) + .on_press(on_url_press(url.clone())) + .width(Length::Fill) + .into() + }) + .collect(); Some(widget::settings::section().title(title).extend(developers)) } }; @@ -159,11 +167,26 @@ pub fn about<'a, Message: Clone + 'static>( let artists_section = section(&about.artists, "Artists"); let translators_section = section(&about.translators, "Translators"); let documenters_section = section(&about.documenters, "Documenters"); - let author = about.author.as_ref().map(widget::text); let version = about.version.as_ref().map(widget::button::standard); let license = about.license.as_ref().map(|license| { - widget::button::standard(license).on_press_maybe(about.license_url().map(on_url_press)) + let url = about.license_url(); + widget::settings::section().title("License").add( + widget::button::custom( + widget::row() + .push(widget::text(license)) + .push(horizontal_space()) + .push_maybe( + url.is_some() + .then_some(crate::widget::icon::from_name("link-symbolic").icon()), + ) + .padding(spacing.space_xxs) + .align_y(Vertical::Center), + ) + .class(crate::theme::Button::Text) + .on_press(on_url_press(url.unwrap_or(String::new()))) + .width(Length::Fill), + ) }); let copyright = about.copyright.as_ref().map(widget::text::body); let comments = about.comments.as_ref().map(widget::text::body); @@ -173,18 +196,14 @@ pub fn about<'a, Message: Clone + 'static>( .push_maybe(application_icon) .push_maybe(application_name) .push_maybe(author) - .push( - widget::row() - .push_maybe(version) - .push_maybe(license) - .spacing(spacing.space_xs), - ) + .push_maybe(version) .push_maybe(links_section) .push_maybe(developers_section) .push_maybe(designers_section) .push_maybe(artists_section) .push_maybe(translators_section) .push_maybe(documenters_section) + .push_maybe(license) .push_maybe(comments) .push_maybe(copyright) .align_x(Alignment::Center)