feat: support for custom & system themes + move cosmic-theme to libcosmic
This commit is contained in:
parent
259bba4d19
commit
bf1c474d08
26 changed files with 2639 additions and 44 deletions
|
|
@ -1,6 +1,7 @@
|
|||
/// Copyright 2022 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
use cosmic::{
|
||||
cosmic_config::config_subscription,
|
||||
font::load_fonts,
|
||||
iced::{self, Application, Command, Length, Subscription},
|
||||
iced::{
|
||||
|
|
@ -9,15 +10,20 @@ use cosmic::{
|
|||
window::{self, close, drag, minimize, toggle_maximize},
|
||||
},
|
||||
keyboard_nav,
|
||||
theme::{self, Theme},
|
||||
theme::{self, CosmicTheme, CosmicThemeCss, Theme},
|
||||
widget::{
|
||||
header_bar, icon, list, nav_bar, nav_bar_toggle, scrollable, segmented_button, settings,
|
||||
warning, IconSource,
|
||||
},
|
||||
Element, ElementExt,
|
||||
};
|
||||
use log::error;
|
||||
use std::{
|
||||
sync::atomic::{AtomicU32, Ordering},
|
||||
borrow::Cow,
|
||||
sync::{
|
||||
atomic::{AtomicU32, Ordering},
|
||||
Arc,
|
||||
},
|
||||
vec,
|
||||
};
|
||||
|
||||
|
|
@ -154,6 +160,7 @@ pub struct Window {
|
|||
warning_message: String,
|
||||
scale_factor: f64,
|
||||
scale_factor_string: String,
|
||||
system_theme: Arc<CosmicTheme>,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
|
@ -198,6 +205,7 @@ pub enum Message {
|
|||
ToggleNavBarCondensed,
|
||||
ToggleWarning,
|
||||
FontsLoaded,
|
||||
SystemTheme(CosmicTheme),
|
||||
}
|
||||
|
||||
impl From<Page> for Message {
|
||||
|
|
@ -375,6 +383,16 @@ impl Application for Window {
|
|||
Subscription::batch(vec![
|
||||
window_break.map(|_| Message::CondensedViewToggle),
|
||||
keyboard_nav::subscription().map(Message::KeyboardNav),
|
||||
config_subscription::<_, CosmicThemeCss>(0, Cow::from("com.system76.CosmicTheme"), 1)
|
||||
.map(|(_, update)| match update {
|
||||
Ok(t) => Message::SystemTheme(t.into_srgba()),
|
||||
Err((errors, t)) => {
|
||||
for error in errors {
|
||||
error!("{:?}", error);
|
||||
}
|
||||
Message::SystemTheme(t.into_srgba())
|
||||
}
|
||||
}),
|
||||
])
|
||||
}
|
||||
|
||||
|
|
@ -395,7 +413,13 @@ impl Application for Window {
|
|||
Some(demo::Output::Debug(debug)) => self.debug = debug,
|
||||
Some(demo::Output::ScalingFactor(factor)) => self.set_scale_factor(factor),
|
||||
Some(demo::Output::ThemeChanged(theme)) => {
|
||||
self.theme = theme;
|
||||
self.theme = match theme {
|
||||
demo::ThemeVariant::Light => Theme::light(),
|
||||
demo::ThemeVariant::Dark => Theme::dark(),
|
||||
demo::ThemeVariant::HighContrastDark => Theme::dark_hc(),
|
||||
demo::ThemeVariant::HighContrastLight => Theme::light_hc(),
|
||||
demo::ThemeVariant::Custom => Theme::custom(self.system_theme.clone()),
|
||||
};
|
||||
}
|
||||
Some(demo::Output::ToggleWarning) => self.toggle_warning(),
|
||||
None => (),
|
||||
|
|
@ -425,6 +449,9 @@ impl Application for Window {
|
|||
},
|
||||
Message::ToggleWarning => self.toggle_warning(),
|
||||
Message::FontsLoaded => {}
|
||||
Message::SystemTheme(t) => {
|
||||
self.system_theme = Arc::new(t);
|
||||
}
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
|
@ -572,6 +599,6 @@ impl Application for Window {
|
|||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme
|
||||
self.theme.clone()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue