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::{
|
use crate::{
|
||||||
Element, fl,
|
Apply, Element, fl,
|
||||||
iced::{Alignment, Length},
|
iced::{Alignment, Length},
|
||||||
widget::{self, horizontal_space},
|
widget::{self, horizontal_space},
|
||||||
};
|
};
|
||||||
|
|
@ -22,7 +22,7 @@ pub struct About {
|
||||||
copyright: Option<String>,
|
copyright: Option<String>,
|
||||||
/// The license name.
|
/// The license name.
|
||||||
license: Option<String>,
|
license: Option<String>,
|
||||||
/// The license url. If None spdx.org url is used.
|
/// The license url.
|
||||||
license_url: Option<String>,
|
license_url: Option<String>,
|
||||||
/// Artists who contributed to the application.
|
/// Artists who contributed to the application.
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
|
|
@ -51,36 +51,28 @@ fn add_contributors(contributors: Vec<(&str, &str)>) -> Vec<(String, String)> {
|
||||||
.collect()
|
.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 {
|
impl<'a> About {
|
||||||
/// Artists who contributed to the application.
|
set_contributors!(artists, "Artists who contributed to the application.");
|
||||||
pub fn artists(mut self, artists: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
set_contributors!(designers, "Designers who contributed to the application.");
|
||||||
self.artists = add_contributors(artists.into());
|
set_contributors!(developers, "Developers who contributed to the application.");
|
||||||
self
|
set_contributors!(
|
||||||
}
|
documenters,
|
||||||
|
"Documenters 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 {
|
set_contributors!(
|
||||||
self.designers = add_contributors(designers.into());
|
translators,
|
||||||
self
|
"Translators 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 {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Links associated with the application.
|
/// Links associated with the application.
|
||||||
pub fn links<K: Into<String>, V: Into<String>>(
|
pub fn links<K: Into<String>, V: Into<String>>(
|
||||||
|
|
@ -104,88 +96,86 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
space_xxs, space_m, ..
|
space_xxs, space_m, ..
|
||||||
} = crate::theme::spacing();
|
} = 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| {
|
let section = |list: &'a Vec<(String, String)>, title: String| {
|
||||||
(!list.is_empty()).then_some({
|
(!list.is_empty()).then_some({
|
||||||
let items: Vec<Element<Message>> =
|
let items: Vec<Element<Message>> = list
|
||||||
list.iter()
|
.iter()
|
||||||
.map(|(name, url)| {
|
.map(|(name, url)| section_button(name, url))
|
||||||
widget::button::custom(
|
.collect();
|
||||||
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();
|
|
||||||
widget::settings::section().title(title).extend(items)
|
widget::settings::section().title(title).extend(items)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
let application_name = about.name.as_ref().map(widget::text::title3);
|
let header_children: Vec<Element<Message>> = [
|
||||||
let application_icon = about.icon.as_ref().map(|i| {
|
about.icon.as_ref().map(|i| {
|
||||||
i.clone()
|
i.clone()
|
||||||
.icon()
|
.icon()
|
||||||
.content_fit(iced::ContentFit::Contain)
|
.size(256)
|
||||||
.width(Length::Fixed(128.))
|
.width(Length::Fixed(128.))
|
||||||
.height(Length::Fixed(128.))
|
.height(Length::Fixed(128.))
|
||||||
});
|
.content_fit(iced::ContentFit::Contain)
|
||||||
let author = about.author.as_ref().map(widget::text::body);
|
.into()
|
||||||
let version = about.version.as_ref().map(widget::button::standard);
|
}),
|
||||||
|
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 links_section = section(&about.links, fl!("links"));
|
||||||
let developers_section = section(&about.developers, fl!("developers"));
|
let developers_section = section(&about.developers, fl!("developers"));
|
||||||
let designers_section = section(&about.designers, fl!("designers"));
|
let designers_section = section(&about.designers, fl!("designers"));
|
||||||
let artists_section = section(&about.artists, fl!("artists"));
|
let artists_section = section(&about.artists, fl!("artists"));
|
||||||
let translators_section = section(&about.translators, fl!("translators"));
|
let translators_section = section(&about.translators, fl!("translators"));
|
||||||
let documenters_section = section(&about.documenters, fl!("documenters"));
|
let documenters_section = section(&about.documenters, fl!("documenters"));
|
||||||
let license = about.license.as_ref().map(|license| {
|
let license_section = about.license.as_ref().and_then(|license| {
|
||||||
let url = about.license_url.as_deref();
|
let url = about.license_url.as_deref().unwrap_or_default();
|
||||||
widget::settings::section().title(fl!("license")).add(
|
Some(
|
||||||
widget::button::custom(
|
widget::settings::section()
|
||||||
widget::row()
|
.title(fl!("license"))
|
||||||
.push(widget::text(license))
|
.add(section_button(license, url)),
|
||||||
.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 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);
|
||||||
|
|
||||||
widget::column()
|
widget::column()
|
||||||
.push(
|
.push_maybe(header)
|
||||||
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(links_section)
|
.push_maybe(links_section)
|
||||||
.push_maybe(developers_section)
|
.push_maybe(developers_section)
|
||||||
.push_maybe(designers_section)
|
.push_maybe(designers_section)
|
||||||
.push_maybe(artists_section)
|
.push_maybe(artists_section)
|
||||||
.push_maybe(translators_section)
|
.push_maybe(translators_section)
|
||||||
.push_maybe(documenters_section)
|
.push_maybe(documenters_section)
|
||||||
|
.push_maybe(license_section)
|
||||||
.push_maybe(comments)
|
.push_maybe(comments)
|
||||||
.push_maybe(copyright)
|
.push_maybe(copyright)
|
||||||
.align_x(Alignment::Center)
|
|
||||||
.spacing(space_m)
|
.spacing(space_m)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
|
.align_x(Alignment::Center)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue