fix(about): match section spacing to designs
Also makes the buttons use the `Button::Link` class.
This commit is contained in:
parent
e6326a28d7
commit
227f7a76b1
1 changed files with 40 additions and 55 deletions
|
|
@ -15,7 +15,7 @@ pub struct About {
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
/// The application's icon name.
|
/// The application's icon name.
|
||||||
icon: Option<String>,
|
icon: Option<String>,
|
||||||
/// The application’s version.
|
/// The application's version.
|
||||||
version: Option<String>,
|
version: Option<String>,
|
||||||
/// Name of the application's author.
|
/// Name of the application's author.
|
||||||
author: Option<String>,
|
author: Option<String>,
|
||||||
|
|
@ -45,76 +45,61 @@ pub struct About {
|
||||||
links: Vec<(String, String)>,
|
links: Vec<(String, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_contributors(contributors: Vec<(&str, &str)>) -> Vec<(String, String)> {
|
||||||
|
contributors
|
||||||
|
.into_iter()
|
||||||
|
.map(|(name, email)| (name.to_string(), format!("mailto:{email}")))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> About {
|
impl<'a> About {
|
||||||
/// Artists who contributed to the application.
|
/// Artists who contributed to the application.
|
||||||
pub fn artists(mut self, artists: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
pub fn artists(mut self, artists: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
||||||
let artists: Vec<(&'a str, &'a str)> = artists.into();
|
self.artists = add_contributors(artists.into());
|
||||||
self.artists = artists
|
|
||||||
.into_iter()
|
|
||||||
.map(|(k, v)| (k.to_string(), format!("mailto:{v}")))
|
|
||||||
.collect();
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Designers who contributed to the application.
|
/// Designers who contributed to the application.
|
||||||
pub fn designers(mut self, designers: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
pub fn designers(mut self, designers: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
||||||
let designers: Vec<(&'a str, &'a str)> = designers.into();
|
self.designers = add_contributors(designers.into());
|
||||||
self.designers = designers
|
|
||||||
.into_iter()
|
|
||||||
.map(|(k, v)| (k.to_string(), format!("mailto:{v}")))
|
|
||||||
.collect();
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Developers who contributed to the application.
|
/// Developers who contributed to the application.
|
||||||
pub fn developers(mut self, developers: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
pub fn developers(mut self, developers: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
||||||
let developers: Vec<(&'a str, &'a str)> = developers.into();
|
self.developers = add_contributors(developers.into());
|
||||||
self.developers = developers
|
|
||||||
.into_iter()
|
|
||||||
.map(|(k, v)| (k.to_string(), format!("mailto:{v}")))
|
|
||||||
.collect();
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Documenters who contributed to the application.
|
/// Documenters who contributed to the application.
|
||||||
pub fn documenters(mut self, documenters: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
pub fn documenters(mut self, documenters: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
||||||
let documenters: Vec<(&'a str, &'a str)> = documenters.into();
|
self.documenters = add_contributors(documenters.into());
|
||||||
self.documenters = documenters
|
|
||||||
.into_iter()
|
|
||||||
.map(|(k, v)| (k.to_string(), format!("mailto:{v}")))
|
|
||||||
.collect();
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translators who contributed to the application.
|
/// Translators who contributed to the application.
|
||||||
pub fn translators(mut self, translators: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
pub fn translators(mut self, translators: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
||||||
let translators: Vec<(&'a str, &'a str)> = translators.into();
|
self.translators = add_contributors(translators.into());
|
||||||
self.translators = translators
|
|
||||||
.into_iter()
|
|
||||||
.map(|(k, v)| (k.to_string(), format!("mailto:{v}")))
|
|
||||||
.collect();
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Links associated with the application.
|
/// Links associated with the application.
|
||||||
pub fn links<T: Into<String>>(mut self, links: impl Into<Vec<(T, &'a str)>>) -> Self {
|
pub fn links<K: Into<String>, V: Into<String>>(
|
||||||
let links: Vec<(T, &'a str)> = links.into();
|
mut self,
|
||||||
|
links: impl IntoIterator<Item = (K, V)>,
|
||||||
|
) -> Self {
|
||||||
self.links = links
|
self.links = links
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (k.into(), v.to_string()))
|
.map(|(name, url)| (name.into(), url.into()))
|
||||||
.collect();
|
.collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn license_url(&self) -> Option<String> {
|
fn license_url(&self) -> Option<String> {
|
||||||
let license: &dyn License = match self.license.as_ref() {
|
self.license.as_ref().and_then(|license_str| {
|
||||||
Some(license) => license.parse().ok()?,
|
let license: &dyn License = license_str.parse().ok()?;
|
||||||
None => return None,
|
Some(format!("https://spdx.org/licenses/{}.html", license.id()))
|
||||||
};
|
})
|
||||||
|
|
||||||
self.license
|
|
||||||
.as_ref()
|
|
||||||
.map(|_| format!("https://spdx.org/licenses/{}.html", license.id()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,14 +109,12 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
on_url_press: impl Fn(String) -> Message,
|
on_url_press: impl Fn(String) -> Message,
|
||||||
) -> Element<'a, Message> {
|
) -> Element<'a, Message> {
|
||||||
let cosmic_theme::Spacing {
|
let cosmic_theme::Spacing {
|
||||||
space_xxs,
|
space_xxs, space_m, ..
|
||||||
space_xs,
|
} = crate::theme::spacing();
|
||||||
..
|
|
||||||
} = crate::theme::active().cosmic().spacing;
|
|
||||||
|
|
||||||
let section = |list: &'a Vec<(String, String)>, title: &'a str| {
|
let section = |list: &'a Vec<(String, String)>, title: &'a str| {
|
||||||
(!list.is_empty()).then_some({
|
(!list.is_empty()).then_some({
|
||||||
let developers: Vec<Element<Message>> =
|
let items: Vec<Element<Message>> =
|
||||||
list.iter()
|
list.iter()
|
||||||
.map(|(name, url)| {
|
.map(|(name, url)| {
|
||||||
widget::button::custom(
|
widget::button::custom(
|
||||||
|
|
@ -141,16 +124,15 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
.push_maybe((!url.is_empty()).then_some(
|
.push_maybe((!url.is_empty()).then_some(
|
||||||
crate::widget::icon::from_name("link-symbolic").icon(),
|
crate::widget::icon::from_name("link-symbolic").icon(),
|
||||||
))
|
))
|
||||||
.padding(space_xxs)
|
|
||||||
.align_y(Alignment::Center),
|
.align_y(Alignment::Center),
|
||||||
)
|
)
|
||||||
.class(crate::theme::Button::Text)
|
.class(crate::theme::Button::Link)
|
||||||
.on_press(on_url_press(url.clone()))
|
.on_press(on_url_press(url.clone()))
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.into()
|
.into()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
widget::settings::section().title(title).extend(developers)
|
widget::settings::section().title(title).extend(items)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -159,15 +141,14 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
.icon
|
.icon
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|icon| crate::desktop::IconSource::Name(icon.clone()).as_cosmic_icon());
|
.map(|icon| crate::desktop::IconSource::Name(icon.clone()).as_cosmic_icon());
|
||||||
|
let author = about.author.as_ref().map(widget::text::body);
|
||||||
|
let version = about.version.as_ref().map(widget::button::standard);
|
||||||
let links_section = section(&about.links, "Links");
|
let links_section = section(&about.links, "Links");
|
||||||
let developers_section = section(&about.developers, "Developers");
|
let developers_section = section(&about.developers, "Developers");
|
||||||
let designers_section = section(&about.designers, "Designers");
|
let designers_section = section(&about.designers, "Designers");
|
||||||
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 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| {
|
||||||
let url = about.license_url();
|
let url = about.license_url();
|
||||||
widget::settings::section().title("License").add(
|
widget::settings::section().title("License").add(
|
||||||
|
|
@ -179,10 +160,9 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
url.is_some()
|
url.is_some()
|
||||||
.then_some(crate::widget::icon::from_name("link-symbolic").icon()),
|
.then_some(crate::widget::icon::from_name("link-symbolic").icon()),
|
||||||
)
|
)
|
||||||
.padding(space_xxs)
|
|
||||||
.align_y(Alignment::Center),
|
.align_y(Alignment::Center),
|
||||||
)
|
)
|
||||||
.class(crate::theme::Button::Text)
|
.class(crate::theme::Button::Link)
|
||||||
.on_press(on_url_press(url.unwrap_or_default()))
|
.on_press(on_url_press(url.unwrap_or_default()))
|
||||||
.width(Length::Fill),
|
.width(Length::Fill),
|
||||||
)
|
)
|
||||||
|
|
@ -191,10 +171,15 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
let comments = about.comments.as_ref().map(widget::text::body);
|
let comments = about.comments.as_ref().map(widget::text::body);
|
||||||
|
|
||||||
widget::column()
|
widget::column()
|
||||||
.push_maybe(application_icon)
|
.push(
|
||||||
.push_maybe(application_name)
|
widget::column()
|
||||||
.push_maybe(author)
|
.push_maybe(application_icon)
|
||||||
.push_maybe(version)
|
.push_maybe(application_name)
|
||||||
|
.push_maybe(author)
|
||||||
|
.push_maybe(version)
|
||||||
|
.align_x(Alignment::Center)
|
||||||
|
.spacing(space_xxs),
|
||||||
|
)
|
||||||
.push_maybe(license)
|
.push_maybe(license)
|
||||||
.push_maybe(links_section)
|
.push_maybe(links_section)
|
||||||
.push_maybe(developers_section)
|
.push_maybe(developers_section)
|
||||||
|
|
@ -205,7 +190,7 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
.push_maybe(comments)
|
.push_maybe(comments)
|
||||||
.push_maybe(copyright)
|
.push_maybe(copyright)
|
||||||
.align_x(Alignment::Center)
|
.align_x(Alignment::Center)
|
||||||
.spacing(space_xs)
|
.spacing(space_m)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue