feat: theme helper methods
This commit is contained in:
parent
6699aa4756
commit
a8a2e4ad26
3 changed files with 45 additions and 1 deletions
|
|
@ -11,9 +11,13 @@ use std::sync::Arc;
|
|||
|
||||
pub use self::segmented_button::SegmentedButton;
|
||||
|
||||
use cosmic_config::config_subscription;
|
||||
use cosmic_config::CosmicConfigEntry;
|
||||
use cosmic_theme::util::CssColor;
|
||||
use cosmic_theme::Component;
|
||||
use cosmic_theme::LayeredTheme;
|
||||
use iced_core::renderer::BorderRadius;
|
||||
use iced_futures::Subscription;
|
||||
use iced_style::application;
|
||||
use iced_style::button;
|
||||
use iced_style::checkbox;
|
||||
|
|
@ -1112,3 +1116,42 @@ impl text_input::StyleSheet for Theme {
|
|||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn theme() -> Theme {
|
||||
let Ok(helper) = crate::cosmic_config::Config::new(
|
||||
crate::cosmic_theme::NAME,
|
||||
crate::cosmic_theme::Theme::<CssColor>::version(),
|
||||
) else {
|
||||
return crate::theme::Theme::dark();
|
||||
};
|
||||
let t = crate::cosmic_theme::Theme::get_entry(&helper).map_or_else(
|
||||
|(errors, theme)| {
|
||||
for err in errors {
|
||||
tracing::error!("{:?}", err);
|
||||
}
|
||||
theme.into_srgba()
|
||||
},
|
||||
crate::cosmic_theme::Theme::into_srgba,
|
||||
);
|
||||
crate::theme::Theme::custom(Arc::new(t))
|
||||
}
|
||||
|
||||
pub fn theme_subscription(id: u64) -> Subscription<crate::theme::Theme> {
|
||||
config_subscription::<u64, crate::cosmic_theme::Theme<CssColor>>(
|
||||
id,
|
||||
crate::cosmic_theme::NAME.into(),
|
||||
crate::cosmic_theme::Theme::<CssColor>::version(),
|
||||
)
|
||||
.map(|(_, res)| {
|
||||
let theme = res.map_or_else(
|
||||
|(errors, theme)| {
|
||||
for err in errors {
|
||||
tracing::error!("{:?}", err);
|
||||
}
|
||||
theme.into_srgba()
|
||||
},
|
||||
crate::cosmic_theme::Theme::into_srgba,
|
||||
);
|
||||
crate::theme::Theme::custom(Arc::new(theme))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue