feat: add support for dark / light mode switching (#178)
* feat: add support for dark / light mode switching and simultaneouscustom light / dark mode themes * refactor(color-picker): optional initial color and fallback color * refactor: used FixedPortion for layout of the settings item This makes sure that the control always has at least the specified portion of the available space * refactor: make all members of the ThemeBuilder public * refactor: add and update palette colors * fix(theme): typo and derive PartialEq for ThemeBuilder * fix: update color picker usage * feat: add more variables to the theme * fix: radius on headerbar * fix: Theme CosmicConfigEntry impl * chore: specify rev of taffy * fix: theme CosmicConfigEntry missing variables * fix: apply theme type when theme mode changes * wip: add plus icon to empty color picker button * chore: fix rev and imports * refactor(color-picker): allow custom size for the icon * refactor(color_picker): make color_button public * update iced
This commit is contained in:
parent
a91deacff5
commit
7cc791a3f5
18 changed files with 542 additions and 164 deletions
|
|
@ -4,11 +4,11 @@
|
|||
//! Contains the [`Theme`] type and its widget stylesheet implementations.
|
||||
|
||||
pub mod style;
|
||||
use cosmic_theme::ThemeMode;
|
||||
pub use style::*;
|
||||
|
||||
use cosmic_config::config_subscription;
|
||||
use cosmic_config::CosmicConfigEntry;
|
||||
use cosmic_theme::util::CssColor;
|
||||
use cosmic_theme::Component;
|
||||
use cosmic_theme::LayeredTheme;
|
||||
use iced_futures::Subscription;
|
||||
|
|
@ -68,10 +68,15 @@ pub fn is_high_contrast() -> bool {
|
|||
}
|
||||
|
||||
/// Watches for changes to the system's theme preference.
|
||||
pub fn subscription(id: u64) -> Subscription<crate::theme::Theme> {
|
||||
config_subscription::<u64, crate::cosmic_theme::Theme<Srgba>>(
|
||||
id,
|
||||
crate::cosmic_theme::NAME.into(),
|
||||
pub fn subscription(id: u64, is_dark: bool) -> Subscription<crate::theme::Theme> {
|
||||
config_subscription::<_, crate::cosmic_theme::Theme<Srgba>>(
|
||||
(id, is_dark),
|
||||
if is_dark {
|
||||
cosmic_theme::DARK_THEME_ID
|
||||
} else {
|
||||
cosmic_theme::LIGHT_THEME_ID
|
||||
}
|
||||
.into(),
|
||||
crate::cosmic_theme::Theme::<Srgba>::version(),
|
||||
)
|
||||
.map(|(_, res)| {
|
||||
|
|
@ -88,10 +93,21 @@ pub fn subscription(id: u64) -> Subscription<crate::theme::Theme> {
|
|||
|
||||
/// Loads the preferred system theme from `cosmic-config`.
|
||||
pub fn system_preference() -> Theme {
|
||||
let Ok(helper) = crate::cosmic_config::Config::new(
|
||||
crate::cosmic_theme::NAME,
|
||||
crate::cosmic_theme::Theme::<CssColor>::version(),
|
||||
) else {
|
||||
let Ok(mode_config) = ThemeMode::config() else {
|
||||
return Theme::dark();
|
||||
};
|
||||
|
||||
let Ok(is_dark) = ThemeMode::is_dark(&mode_config) else {
|
||||
return Theme::dark();
|
||||
};
|
||||
|
||||
let helper = if is_dark {
|
||||
crate::cosmic_theme::Theme::<Srgba>::dark_config()
|
||||
} else {
|
||||
crate::cosmic_theme::Theme::<Srgba>::light_config()
|
||||
};
|
||||
|
||||
let Ok(helper) = helper else {
|
||||
return Theme::dark();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -412,7 +412,12 @@ impl container::StyleSheet for Theme {
|
|||
.add_stop(0.0, header_top.into())
|
||||
.add_stop(1.0, header_bottom.into()),
|
||||
))),
|
||||
border_radius: BorderRadius::from([16.0, 16.0, 0.0, 0.0]),
|
||||
border_radius: BorderRadius::from([
|
||||
palette.corner_radii.radius_xs[0],
|
||||
palette.corner_radii.radius_xs[3],
|
||||
0.0,
|
||||
0.0,
|
||||
]),
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue