summaryrefslogtreecommitdiffstats
path: root/core/src/theme.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2024-05-23 13:29:45 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2024-05-23 13:29:45 +0200
commitd8ba6b0673a33724a177f3a1ba59705527280142 (patch)
tree89482c8d1e3a03e00b3a8151abbb81e30ae5898c /core/src/theme.rs
parent72ed8bcc8def9956e25f3720a3095fc96bb2eef0 (diff)
parent468794d918eb06c1dbebb33c32b10017ad335f05 (diff)
downloadiced-d8ba6b0673a33724a177f3a1ba59705527280142.tar.gz
iced-d8ba6b0673a33724a177f3a1ba59705527280142.tar.bz2
iced-d8ba6b0673a33724a177f3a1ba59705527280142.zip
Merge branch 'master' into feat/text-macro
Diffstat (limited to 'core/src/theme.rs')
-rw-r--r--core/src/theme.rs25
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 {