refactor: about page as a widget
This commit is contained in:
parent
6f53b68be5
commit
d8357d0ea3
8 changed files with 239 additions and 240 deletions
|
|
@ -6,9 +6,6 @@
|
|||
//! Check out our [application](https://github.com/pop-os/libcosmic/tree/master/examples/application)
|
||||
//! example in our repository.
|
||||
|
||||
#[cfg(feature = "desktop")]
|
||||
pub mod about;
|
||||
|
||||
pub mod command;
|
||||
mod core;
|
||||
pub mod cosmic;
|
||||
|
|
@ -76,7 +73,6 @@ use {
|
|||
|
||||
#[cfg(feature = "desktop")]
|
||||
use {
|
||||
crate::app::about::About,
|
||||
crate::widget,
|
||||
iced::{alignment::Vertical, Alignment},
|
||||
std::collections::BTreeMap,
|
||||
|
|
@ -602,90 +598,6 @@ where
|
|||
panic!("no view for window {id:?}");
|
||||
}
|
||||
|
||||
#[cfg(feature = "desktop")]
|
||||
/// Provides information about the application.
|
||||
fn about(&self) -> Option<&About> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(feature = "desktop")]
|
||||
/// Constructs the view for the about section.
|
||||
fn about_view<'a>(&'a self) -> Option<Element<'a, crate::app::cosmic::Message>> {
|
||||
let about = self.about()?;
|
||||
|
||||
let spacing = crate::theme::active().cosmic().spacing;
|
||||
|
||||
let section = |list: &'a BTreeMap<String, String>, title: &'a str| {
|
||||
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.clone()))
|
||||
.width(Length::Fill)
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
Some(widget::settings::section().title(title).extend(developers))
|
||||
}
|
||||
};
|
||||
|
||||
let application_name = about.application_name.as_ref().map(widget::text::title3);
|
||||
let application_icon = about
|
||||
.application_icon
|
||||
.as_ref()
|
||||
.map(|icon| crate::desktop::IconSource::Name(icon.clone()).as_cosmic_icon());
|
||||
|
||||
let links_section = section(&about.links, "Links");
|
||||
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 developer_name = about.developer_name.as_ref().map(widget::text);
|
||||
let version = about.version.as_ref().map(widget::button::standard);
|
||||
let license = about.license_type.as_ref().map(widget::button::standard);
|
||||
let copyright = about.copyright.as_ref().map(widget::text::body);
|
||||
let comments = about.comments.as_ref().map(widget::text::body);
|
||||
|
||||
let about = widget::scrollable(
|
||||
widget::column()
|
||||
.push_maybe(application_icon)
|
||||
.push_maybe(application_name)
|
||||
.push_maybe(developer_name)
|
||||
.push(
|
||||
widget::row()
|
||||
.push_maybe(version)
|
||||
.push_maybe(license)
|
||||
.spacing(spacing.space_xs),
|
||||
)
|
||||
.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(comments)
|
||||
.push_maybe(copyright)
|
||||
.align_x(Alignment::Center)
|
||||
.spacing(spacing.space_xs)
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.into();
|
||||
Some(about)
|
||||
}
|
||||
|
||||
/// Overrides the default style for applications
|
||||
fn style(&self) -> Option<iced_runtime::Appearance> {
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue