fix: return reference to About
This commit is contained in:
parent
8b296ebe8f
commit
3dc8c49f40
2 changed files with 93 additions and 80 deletions
|
|
@ -32,19 +32,46 @@ pub struct About {
|
||||||
/// The license from a list of known licenses.
|
/// The license from a list of known licenses.
|
||||||
pub license_type: Option<String>,
|
pub license_type: Option<String>,
|
||||||
/// The URL of the application’s support page.
|
/// The URL of the application’s support page.
|
||||||
|
#[setters(skip)]
|
||||||
pub support_url: Option<String>,
|
pub support_url: Option<String>,
|
||||||
/// The URL of the application’s repository.
|
/// The URL of the application’s repository.
|
||||||
|
#[setters(skip)]
|
||||||
pub repository_url: Option<String>,
|
pub repository_url: Option<String>,
|
||||||
/// Translators who contributed to the application.
|
/// Translators who contributed to the application.
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
pub translators: BTreeMap<String, String>,
|
pub translators: BTreeMap<String, String>,
|
||||||
|
/// Links associated with the application.
|
||||||
|
#[setters(skip)]
|
||||||
|
pub links: BTreeMap<String, String>,
|
||||||
/// The application’s version.
|
/// The application’s version.
|
||||||
pub version: Option<String>,
|
pub version: Option<String>,
|
||||||
/// The application’s website.
|
/// The application’s website.
|
||||||
|
#[setters(skip)]
|
||||||
pub website: Option<String>,
|
pub website: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl About {
|
impl About {
|
||||||
|
pub fn set_repository_url(mut self, repository_url: impl Into<String>) -> Self {
|
||||||
|
let repository_url = repository_url.into();
|
||||||
|
self.repository_url = Some(repository_url.clone());
|
||||||
|
self.links.insert("Repository".into(), repository_url);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_support_url(mut self, support_url: impl Into<String>) -> Self {
|
||||||
|
let support_url = support_url.into();
|
||||||
|
self.support_url = Some(support_url.clone());
|
||||||
|
self.links.insert("Support".into(), support_url);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_website(mut self, website: impl Into<String>) -> Self {
|
||||||
|
let website = website.into();
|
||||||
|
self.website = Some(website.clone());
|
||||||
|
self.links.insert("Website".into(), website);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_artists(mut self, artists: impl Into<BTreeMap<String, String>>) -> Self {
|
pub fn set_artists(mut self, artists: impl Into<BTreeMap<String, String>>) -> Self {
|
||||||
let artists: BTreeMap<String, String> = artists.into();
|
let artists: BTreeMap<String, String> = artists.into();
|
||||||
self.artists = artists
|
self.artists = artists
|
||||||
|
|
|
||||||
146
src/app/mod.rs
146
src/app/mod.rs
|
|
@ -604,98 +604,84 @@ where
|
||||||
|
|
||||||
#[cfg(feature = "desktop")]
|
#[cfg(feature = "desktop")]
|
||||||
/// Provides information about the application.
|
/// Provides information about the application.
|
||||||
fn about(&self) -> Option<About> {
|
fn about(&self) -> Option<&About> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "desktop")]
|
#[cfg(feature = "desktop")]
|
||||||
/// Constructs the view for the about section.
|
/// Constructs the view for the about section.
|
||||||
fn about_view<'a>(&self) -> Element<'a, crate::app::cosmic::Message> {
|
fn about_view<'a>(&'a self) -> Option<Element<'a, crate::app::cosmic::Message>> {
|
||||||
if let Some(about) = self.about() {
|
let about = self.about()?;
|
||||||
let spacing = crate::theme::active().cosmic().spacing;
|
|
||||||
|
|
||||||
let section = |list: BTreeMap<String, String>, title: &'a str| {
|
let spacing = crate::theme::active().cosmic().spacing;
|
||||||
if list.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
let developers: Vec<Element<crate::app::cosmic::Message>> = list
|
|
||||||
.into_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(crate::app::cosmic::Message::OpenUrl(url))
|
|
||||||
.width(Length::Fill)
|
|
||||||
.into()
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
Some(widget::settings::section().title(title).extend(developers))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let application_name = about.application_name.map(widget::text::title3);
|
let section = |list: &'a BTreeMap<String, String>, title: &'a str| {
|
||||||
let application_icon = about
|
if list.is_empty() {
|
||||||
.application_icon
|
None
|
||||||
.map(|icon| crate::desktop::IconSource::Name(icon).as_cosmic_icon());
|
} else {
|
||||||
|
let developers: Vec<Element<crate::app::cosmic::Message>> = list
|
||||||
let mut links: BTreeMap<String, String> = BTreeMap::new();
|
.into_iter()
|
||||||
|
.map(|(name, url)| {
|
||||||
if let Some(website) = about.website {
|
widget::button::custom(
|
||||||
links.insert("Website".into(), website);
|
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(crate::app::cosmic::Message::OpenUrl(url.clone()))
|
||||||
|
.width(Length::Fill)
|
||||||
|
.into()
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
Some(widget::settings::section().title(title).extend(developers))
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(repository_url) = about.repository_url {
|
let application_name = about.application_name.as_ref().map(widget::text::title3);
|
||||||
links.insert("Repository".into(), repository_url);
|
let application_icon = about
|
||||||
}
|
.application_icon
|
||||||
|
.as_ref()
|
||||||
|
.map(|icon| crate::desktop::IconSource::Name(icon.clone()).as_cosmic_icon());
|
||||||
|
|
||||||
if let Some(support_url) = about.support_url {
|
let links_section = section(&about.links, "Links");
|
||||||
links.insert("Support".into(), support_url);
|
let developers_section = section(&about.developers, "Developers");
|
||||||
}
|
let designers_section = section(&about.designers, "Designers");
|
||||||
|
let artists_section = section(&about.artists, "Artists");
|
||||||
|
let translators_section = section(&about.translators, "Translators");
|
||||||
|
let documenters_section = section(&about.documenters, "Documenters");
|
||||||
|
|
||||||
let links_section = section(links, "Links");
|
let developer_name = about.developer_name.as_ref().map(widget::text);
|
||||||
let developers_section = section(about.developers, "Developers");
|
let version = about.version.as_ref().map(widget::button::standard);
|
||||||
let designers_section = section(about.designers, "Designers");
|
let license = about.license_type.as_ref().map(widget::button::standard);
|
||||||
let artists_section = section(about.artists, "Artists");
|
let copyright = about.copyright.as_ref().map(widget::text::body);
|
||||||
let translators_section = section(about.translators, "Translators");
|
let comments = about.comments.as_ref().map(widget::text::body);
|
||||||
let documenters_section = section(about.documenters, "Documenters");
|
|
||||||
|
|
||||||
let developer_name = about.developer_name.map(widget::text);
|
let about = widget::column()
|
||||||
let version = about.version.map(widget::button::standard);
|
.push_maybe(application_icon)
|
||||||
let license = about.license_type.map(widget::button::standard);
|
.push_maybe(application_name)
|
||||||
let copyright = about.copyright.map(widget::text::body);
|
.push_maybe(developer_name)
|
||||||
let comments = about.comments.map(widget::text::body);
|
.push(
|
||||||
|
widget::row()
|
||||||
widget::column()
|
.push_maybe(version)
|
||||||
.push_maybe(application_icon)
|
.push_maybe(license)
|
||||||
.push_maybe(application_name)
|
.spacing(spacing.space_xs),
|
||||||
.push_maybe(developer_name)
|
)
|
||||||
.push(
|
.push_maybe(links_section)
|
||||||
widget::row()
|
.push_maybe(developers_section)
|
||||||
.push_maybe(version)
|
.push_maybe(designers_section)
|
||||||
.push_maybe(license)
|
.push_maybe(artists_section)
|
||||||
.spacing(spacing.space_xs),
|
.push_maybe(translators_section)
|
||||||
)
|
.push_maybe(documenters_section)
|
||||||
.push_maybe(links_section)
|
.push_maybe(comments)
|
||||||
.push_maybe(developers_section)
|
.push_maybe(copyright)
|
||||||
.push_maybe(designers_section)
|
.align_x(Alignment::Center)
|
||||||
.push_maybe(artists_section)
|
.spacing(spacing.space_xs)
|
||||||
.push_maybe(translators_section)
|
.width(Length::Fill)
|
||||||
.push_maybe(documenters_section)
|
.into();
|
||||||
.push_maybe(comments)
|
Some(about)
|
||||||
.push_maybe(copyright)
|
|
||||||
.align_x(Alignment::Center)
|
|
||||||
.spacing(spacing.space_xs)
|
|
||||||
.width(Length::Fill)
|
|
||||||
.into()
|
|
||||||
} else {
|
|
||||||
crate::widget::text("Test").into()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Overrides the default style for applications
|
/// Overrides the default style for applications
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue