feat: theme helper methods
This commit is contained in:
parent
6699aa4756
commit
a8a2e4ad26
3 changed files with 45 additions and 1 deletions
|
|
@ -29,6 +29,7 @@ sctk = { package = "smithay-client-toolkit", git = "https://github.com/pop-os/cl
|
||||||
slotmap = "1.0.6"
|
slotmap = "1.0.6"
|
||||||
fraction = "0.13.0"
|
fraction = "0.13.0"
|
||||||
cosmic-config = { path = "cosmic-config" }
|
cosmic-config = { path = "cosmic-config" }
|
||||||
|
tracing = "0.1"
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
freedesktop-icons = "0.2.2"
|
freedesktop-icons = "0.2.2"
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ pub trait LayeredTheme {
|
||||||
|
|
||||||
impl<C> Theme<C> {
|
impl<C> Theme<C> {
|
||||||
/// version of the theme
|
/// version of the theme
|
||||||
pub fn version() -> u32 {
|
pub fn version() -> u64 {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,13 @@ use std::sync::Arc;
|
||||||
|
|
||||||
pub use self::segmented_button::SegmentedButton;
|
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::Component;
|
||||||
use cosmic_theme::LayeredTheme;
|
use cosmic_theme::LayeredTheme;
|
||||||
use iced_core::renderer::BorderRadius;
|
use iced_core::renderer::BorderRadius;
|
||||||
|
use iced_futures::Subscription;
|
||||||
use iced_style::application;
|
use iced_style::application;
|
||||||
use iced_style::button;
|
use iced_style::button;
|
||||||
use iced_style::checkbox;
|
use iced_style::checkbox;
|
||||||
|
|
@ -1112,3 +1116,42 @@ impl text_input::StyleSheet for Theme {
|
||||||
todo!()
|
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