diff options
author | 2024-03-20 16:44:50 +0100 | |
---|---|---|
committer | 2024-03-20 16:44:50 +0100 | |
commit | 2b00e8b1457b0ccbafe12db3dbd6431c2c72f275 (patch) | |
tree | 3df829ecf6128115800a8f44c899b1743383c7f1 /core/src/theme.rs | |
parent | af6bc4643df83c4695f0954aa3fdd258988a77cf (diff) | |
parent | 9db6ac8f202ebdc1453edee01da0b30aee0949d8 (diff) | |
download | iced-2b00e8b1457b0ccbafe12db3dbd6431c2c72f275.tar.gz iced-2b00e8b1457b0ccbafe12db3dbd6431c2c72f275.tar.bz2 iced-2b00e8b1457b0ccbafe12db3dbd6431c2c72f275.zip |
Merge pull request #2343 from iced-rs/auto-detect-theme
Introduce `auto-detect-theme` feature
Diffstat (limited to 'core/src/theme.rs')
-rw-r--r-- | core/src/theme.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/core/src/theme.rs b/core/src/theme.rs index 948aaf83..6b2c04da 100644 --- a/core/src/theme.rs +++ b/core/src/theme.rs @@ -7,10 +7,9 @@ use std::fmt; use std::sync::Arc; /// A built-in theme. -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq)] pub enum Theme { /// The built-in light variant. - #[default] Light, /// The built-in dark variant. Dark, @@ -161,6 +160,28 @@ impl Theme { } } +impl Default for Theme { + fn default() -> Self { + #[cfg(feature = "auto-detect-theme")] + { + use once_cell::sync::Lazy; + + static DEFAULT: Lazy<Theme> = + Lazy::new(|| match dark_light::detect() { + dark_light::Mode::Dark => Theme::Dark, + dark_light::Mode::Light | dark_light::Mode::Default => { + Theme::Light + } + }); + + DEFAULT.clone() + } + + #[cfg(not(feature = "auto-detect-theme"))] + Theme::Light + } +} + impl fmt::Display for Theme { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { |