improv: moved license to a section and added docs
This commit is contained in:
parent
dd8f73f9ba
commit
861ae6545f
1 changed files with 57 additions and 40 deletions
|
|
@ -26,7 +26,7 @@ pub struct About {
|
||||||
comments: Option<String>,
|
comments: Option<String>,
|
||||||
/// The application's copyright.
|
/// The application's copyright.
|
||||||
copyright: Option<String>,
|
copyright: Option<String>,
|
||||||
/// The license text.
|
/// The license name.
|
||||||
license: Option<String>,
|
license: Option<String>,
|
||||||
/// Artists who contributed to the application.
|
/// Artists who contributed to the application.
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
|
|
@ -49,15 +49,7 @@ pub struct About {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> About {
|
impl<'a> About {
|
||||||
pub fn links(mut self, links: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
/// Artists who contributed to the application.
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn artists(mut self, artists: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
pub fn artists(mut self, artists: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
||||||
let artists: BTreeMap<&'a str, &'a str> = artists.into();
|
let artists: BTreeMap<&'a str, &'a str> = artists.into();
|
||||||
self.artists = artists
|
self.artists = artists
|
||||||
|
|
@ -67,6 +59,7 @@ impl<'a> About {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Designers who contributed to the application.
|
||||||
pub fn designers(mut self, designers: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
pub fn designers(mut self, designers: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
||||||
let designers: BTreeMap<&'a str, &'a str> = designers.into();
|
let designers: BTreeMap<&'a str, &'a str> = designers.into();
|
||||||
self.designers = designers
|
self.designers = designers
|
||||||
|
|
@ -76,6 +69,7 @@ impl<'a> About {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Developers who contributed to the application.
|
||||||
pub fn developers(mut self, developers: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
pub fn developers(mut self, developers: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
||||||
let developers: BTreeMap<&'a str, &'a str> = developers.into();
|
let developers: BTreeMap<&'a str, &'a str> = developers.into();
|
||||||
self.developers = developers
|
self.developers = developers
|
||||||
|
|
@ -85,6 +79,7 @@ impl<'a> About {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Documenters who contributed to the application.
|
||||||
pub fn documenters(mut self, documenters: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
pub fn documenters(mut self, documenters: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
||||||
let documenters: BTreeMap<&'a str, &'a str> = documenters.into();
|
let documenters: BTreeMap<&'a str, &'a str> = documenters.into();
|
||||||
self.documenters = documenters
|
self.documenters = documenters
|
||||||
|
|
@ -94,6 +89,7 @@ impl<'a> About {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Translators who contributed to the application.
|
||||||
pub fn translators(mut self, translators: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
pub fn translators(mut self, translators: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
||||||
let translators: BTreeMap<&'a str, &'a str> = translators.into();
|
let translators: BTreeMap<&'a str, &'a str> = translators.into();
|
||||||
self.translators = translators
|
self.translators = translators
|
||||||
|
|
@ -103,6 +99,16 @@ impl<'a> About {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Links associated with the application.
|
||||||
|
pub fn links(mut self, links: impl Into<BTreeMap<&'a str, &'a str>>) -> 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<String> {
|
fn license_url(&self) -> Option<String> {
|
||||||
let license: &dyn License = match self.license.as_ref() {
|
let license: &dyn License = match self.license.as_ref() {
|
||||||
Some(license) => license.parse().ok()?,
|
Some(license) => license.parse().ok()?,
|
||||||
|
|
@ -123,28 +129,28 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
let spacing = crate::theme::active().cosmic().spacing;
|
let spacing = crate::theme::active().cosmic().spacing;
|
||||||
|
|
||||||
let section = |list: &'a BTreeMap<String, String>, title: &'a str| {
|
let section = |list: &'a BTreeMap<String, String>, title: &'a str| {
|
||||||
if list.is_empty() {
|
(!list.is_empty()).then_some({
|
||||||
None
|
let developers: Vec<Element<Message>> =
|
||||||
} else {
|
list.iter()
|
||||||
let developers: Vec<Element<Message>> = list
|
|
||||||
.iter()
|
|
||||||
.map(|(name, url)| {
|
.map(|(name, url)| {
|
||||||
widget::button::custom(
|
widget::button::custom(
|
||||||
widget::row()
|
widget::row()
|
||||||
.push(widget::text(name))
|
.push(widget::text(name))
|
||||||
.push(horizontal_space())
|
.push(horizontal_space())
|
||||||
.push(crate::widget::icon::from_name("link-symbolic").icon())
|
.push_maybe((!url.is_empty()).then_some(
|
||||||
|
crate::widget::icon::from_name("link-symbolic").icon(),
|
||||||
|
))
|
||||||
.padding(spacing.space_xxs)
|
.padding(spacing.space_xxs)
|
||||||
.align_y(Vertical::Center),
|
.align_y(Vertical::Center),
|
||||||
)
|
)
|
||||||
.class(crate::theme::Button::Text)
|
.class(crate::theme::Button::Text)
|
||||||
.on_press(on_url_press(url.to_string()))
|
.on_press(on_url_press(url.clone()))
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.into()
|
.into()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Some(widget::settings::section().title(title).extend(developers))
|
widget::settings::section().title(title).extend(developers)
|
||||||
}
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
let application_name = about.name.as_ref().map(widget::text::title3);
|
let application_name = about.name.as_ref().map(widget::text::title3);
|
||||||
|
|
@ -159,11 +165,26 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
let artists_section = section(&about.artists, "Artists");
|
let artists_section = section(&about.artists, "Artists");
|
||||||
let translators_section = section(&about.translators, "Translators");
|
let translators_section = section(&about.translators, "Translators");
|
||||||
let documenters_section = section(&about.documenters, "Documenters");
|
let documenters_section = section(&about.documenters, "Documenters");
|
||||||
|
|
||||||
let author = about.author.as_ref().map(widget::text);
|
let author = about.author.as_ref().map(widget::text);
|
||||||
let version = about.version.as_ref().map(widget::button::standard);
|
let version = about.version.as_ref().map(widget::button::standard);
|
||||||
let license = about.license.as_ref().map(|license| {
|
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 copyright = about.copyright.as_ref().map(widget::text::body);
|
||||||
let comments = about.comments.as_ref().map(widget::text::body);
|
let comments = about.comments.as_ref().map(widget::text::body);
|
||||||
|
|
@ -173,12 +194,8 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
.push_maybe(application_icon)
|
.push_maybe(application_icon)
|
||||||
.push_maybe(application_name)
|
.push_maybe(application_name)
|
||||||
.push_maybe(author)
|
.push_maybe(author)
|
||||||
.push(
|
|
||||||
widget::row()
|
|
||||||
.push_maybe(version)
|
.push_maybe(version)
|
||||||
.push_maybe(license)
|
.push_maybe(license)
|
||||||
.spacing(spacing.space_xs),
|
|
||||||
)
|
|
||||||
.push_maybe(links_section)
|
.push_maybe(links_section)
|
||||||
.push_maybe(developers_section)
|
.push_maybe(developers_section)
|
||||||
.push_maybe(designers_section)
|
.push_maybe(designers_section)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue