chore(about): styling fixes
Also reduces code duplication a bit.
This commit is contained in:
parent
0059fe182b
commit
5cd7742413
1 changed files with 76 additions and 86 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
Element, fl,
|
||||
Apply, Element, fl,
|
||||
iced::{Alignment, Length},
|
||||
widget::{self, horizontal_space},
|
||||
};
|
||||
|
|
@ -22,7 +22,7 @@ pub struct About {
|
|||
copyright: Option<String>,
|
||||
/// The license name.
|
||||
license: Option<String>,
|
||||
/// The license url. If None spdx.org url is used.
|
||||
/// The license url.
|
||||
license_url: Option<String>,
|
||||
/// Artists who contributed to the application.
|
||||
#[setters(skip)]
|
||||
|
|
@ -51,36 +51,28 @@ fn add_contributors(contributors: Vec<(&str, &str)>) -> Vec<(String, String)> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
macro_rules! set_contributors {
|
||||
($field:ident, $doc:expr) => {
|
||||
#[doc = $doc]
|
||||
pub fn $field(mut self, contributors: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
||||
self.$field = add_contributors(contributors.into());
|
||||
self
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<'a> About {
|
||||
/// Artists who contributed to the application.
|
||||
pub fn artists(mut self, artists: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
||||
self.artists = add_contributors(artists.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Designers who contributed to the application.
|
||||
pub fn designers(mut self, designers: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
||||
self.designers = add_contributors(designers.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Developers who contributed to the application.
|
||||
pub fn developers(mut self, developers: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
||||
self.developers = add_contributors(developers.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Documenters who contributed to the application.
|
||||
pub fn documenters(mut self, documenters: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
||||
self.documenters = add_contributors(documenters.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Translators who contributed to the application.
|
||||
pub fn translators(mut self, translators: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
||||
self.translators = add_contributors(translators.into());
|
||||
self
|
||||
}
|
||||
set_contributors!(artists, "Artists who contributed to the application.");
|
||||
set_contributors!(designers, "Designers who contributed to the application.");
|
||||
set_contributors!(developers, "Developers who contributed to the application.");
|
||||
set_contributors!(
|
||||
documenters,
|
||||
"Documenters who contributed to the application."
|
||||
);
|
||||
set_contributors!(
|
||||
translators,
|
||||
"Translators who contributed to the application."
|
||||
);
|
||||
|
||||
/// Links associated with the application.
|
||||
pub fn links<K: Into<String>, V: Into<String>>(
|
||||
|
|
@ -104,88 +96,86 @@ pub fn about<'a, Message: Clone + 'static>(
|
|||
space_xxs, space_m, ..
|
||||
} = crate::theme::spacing();
|
||||
|
||||
let section_button = |name: &'a str, url: &'a str| -> Element<'a, Message> {
|
||||
widget::row()
|
||||
.push(widget::text(name))
|
||||
.push(horizontal_space())
|
||||
.push_maybe(
|
||||
(!url.is_empty()).then_some(crate::widget::icon::from_name("link-symbolic").icon()),
|
||||
)
|
||||
.align_y(Alignment::Center)
|
||||
.apply(widget::button::custom)
|
||||
.class(crate::theme::Button::Link)
|
||||
.on_press(on_url_press(url))
|
||||
.width(Length::Fill)
|
||||
.into()
|
||||
};
|
||||
|
||||
let section = |list: &'a Vec<(String, String)>, title: String| {
|
||||
(!list.is_empty()).then_some({
|
||||
let items: Vec<Element<Message>> =
|
||||
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(),
|
||||
))
|
||||
.align_y(Alignment::Center),
|
||||
)
|
||||
.class(crate::theme::Button::Link)
|
||||
.on_press(on_url_press(url))
|
||||
.width(Length::Fill)
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
let items: Vec<Element<Message>> = list
|
||||
.iter()
|
||||
.map(|(name, url)| section_button(name, url))
|
||||
.collect();
|
||||
widget::settings::section().title(title).extend(items)
|
||||
})
|
||||
};
|
||||
|
||||
let application_name = about.name.as_ref().map(widget::text::title3);
|
||||
let application_icon = about.icon.as_ref().map(|i| {
|
||||
i.clone()
|
||||
.icon()
|
||||
.content_fit(iced::ContentFit::Contain)
|
||||
.width(Length::Fixed(128.))
|
||||
.height(Length::Fixed(128.))
|
||||
});
|
||||
let author = about.author.as_ref().map(widget::text::body);
|
||||
let version = about.version.as_ref().map(widget::button::standard);
|
||||
let header_children: Vec<Element<Message>> = [
|
||||
about.icon.as_ref().map(|i| {
|
||||
i.clone()
|
||||
.icon()
|
||||
.size(256)
|
||||
.width(Length::Fixed(128.))
|
||||
.height(Length::Fixed(128.))
|
||||
.content_fit(iced::ContentFit::Contain)
|
||||
.into()
|
||||
}),
|
||||
about.name.as_ref().map(|n| widget::text::title3(n).into()),
|
||||
about.author.as_ref().map(|a| widget::text::body(a).into()),
|
||||
about.version.as_ref().map(|v| {
|
||||
widget::button::standard(v)
|
||||
.apply(widget::container)
|
||||
.padding([space_xxs, 0, 0, 0])
|
||||
.into()
|
||||
}),
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect();
|
||||
let header = (!header_children.is_empty())
|
||||
.then_some(widget::column::with_children(header_children).align_x(Alignment::Center));
|
||||
|
||||
let links_section = section(&about.links, fl!("links"));
|
||||
let developers_section = section(&about.developers, fl!("developers"));
|
||||
let designers_section = section(&about.designers, fl!("designers"));
|
||||
let artists_section = section(&about.artists, fl!("artists"));
|
||||
let translators_section = section(&about.translators, fl!("translators"));
|
||||
let documenters_section = section(&about.documenters, fl!("documenters"));
|
||||
let license = about.license.as_ref().map(|license| {
|
||||
let url = about.license_url.as_deref();
|
||||
widget::settings::section().title(fl!("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()),
|
||||
)
|
||||
.align_y(Alignment::Center),
|
||||
)
|
||||
.class(crate::theme::Button::Link)
|
||||
.on_press(on_url_press(url.unwrap_or_default()))
|
||||
.width(Length::Fill),
|
||||
let license_section = about.license.as_ref().and_then(|license| {
|
||||
let url = about.license_url.as_deref().unwrap_or_default();
|
||||
Some(
|
||||
widget::settings::section()
|
||||
.title(fl!("license"))
|
||||
.add(section_button(license, url)),
|
||||
)
|
||||
});
|
||||
let copyright = about.copyright.as_ref().map(widget::text::body);
|
||||
let comments = about.comments.as_ref().map(widget::text::body);
|
||||
|
||||
widget::column()
|
||||
.push(
|
||||
widget::column()
|
||||
.push_maybe(application_icon)
|
||||
.push_maybe(application_name)
|
||||
.push_maybe(author)
|
||||
.push_maybe(version)
|
||||
.align_x(Alignment::Center)
|
||||
.spacing(space_xxs),
|
||||
)
|
||||
.push_maybe(license)
|
||||
.push_maybe(header)
|
||||
.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_section)
|
||||
.push_maybe(comments)
|
||||
.push_maybe(copyright)
|
||||
.align_x(Alignment::Center)
|
||||
.spacing(space_m)
|
||||
.width(Length::Fill)
|
||||
.align_x(Alignment::Center)
|
||||
.into()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue