-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
18 changed files
with
544 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
pub use corner::*; | ||
pub use cosmic_palette::*; | ||
pub use derivation::*; | ||
pub use mode::*; | ||
pub use spacing::*; | ||
pub use theme::*; | ||
|
||
mod corner; | ||
mod cosmic_palette; | ||
mod derivation; | ||
mod mode; | ||
mod spacing; | ||
mod theme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use cosmic_config::{Config, ConfigGet, ConfigSet, CosmicConfigEntry}; | ||
|
||
/// ID for the ThemeMode config | ||
pub const THEME_MODE_ID: &str = "com.system76.CosmicTheme.Mode"; | ||
|
||
/// The config for cosmic theme dark / light settings | ||
#[derive( | ||
Debug, Clone, Copy, PartialEq, Eq, cosmic_config::cosmic_config_derive::CosmicConfigEntry, | ||
)] | ||
pub struct ThemeMode { | ||
/// The theme dark mode setting. | ||
pub is_dark: bool, | ||
/// The theme auto-switch dark and light mode setting. | ||
pub auto_switch: bool, | ||
} | ||
|
||
impl Default for ThemeMode { | ||
fn default() -> Self { | ||
Self { | ||
is_dark: true, | ||
auto_switch: false, | ||
} | ||
} | ||
} | ||
|
||
impl ThemeMode { | ||
/// Check if the theme is currently using dark mode | ||
pub fn is_dark(config: &Config) -> Result<bool, cosmic_config::Error> { | ||
config.get::<bool>("is_dark") | ||
} | ||
|
||
/// version of the theme | ||
pub fn version() -> u64 { | ||
1 | ||
} | ||
|
||
/// Set auto-switch from light to dark mode | ||
pub fn set_auto_switch(config: &Config, value: bool) -> Result<(), cosmic_config::Error> { | ||
config.set("auto_switch", value) | ||
} | ||
|
||
/// Get the config for the theme mode | ||
pub fn config() -> Result<Config, cosmic_config::Error> { | ||
Config::new(THEME_MODE_ID, Self::version()) | ||
} | ||
} |
Oops, something went wrong.