diff options
author | 2024-03-24 11:13:45 +0900 | |
---|---|---|
committer | 2024-03-24 11:13:45 +0900 | |
commit | 4334e63ba1dd88b367f3b7f2790b7869d11d12c0 (patch) | |
tree | 7a02d84426a54a5a5283f5ad101cc803442998fd /core | |
parent | f3a1c785b2743e9c48c3d28df0c6772ce579d7c8 (diff) | |
parent | 3013463baa71504488a20436beb3db87ecb66df0 (diff) | |
download | iced-4334e63ba1dd88b367f3b7f2790b7869d11d12c0.tar.gz iced-4334e63ba1dd88b367f3b7f2790b7869d11d12c0.tar.bz2 iced-4334e63ba1dd88b367f3b7f2790b7869d11d12c0.zip |
Merge branch 'iced-rs:master' into viewer_content_fit
Diffstat (limited to '')
-rw-r--r-- | core/Cargo.toml | 6 | ||||
-rw-r--r-- | core/src/theme.rs | 25 | ||||
-rw-r--r-- | core/src/window/settings/wasm.rs | 12 |
3 files changed, 40 insertions, 3 deletions
diff --git a/core/Cargo.toml b/core/Cargo.toml index c273fcb4..29a95ad7 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -10,6 +10,9 @@ homepage.workspace = true categories.workspace = true keywords.workspace = true +[features] +auto-detect-theme = ["dep:dark-light"] + [dependencies] bitflags.workspace = true glam.workspace = true @@ -22,6 +25,9 @@ thiserror.workspace = true web-time.workspace = true xxhash-rust.workspace = true +dark-light.workspace = true +dark-light.optional = true + [target.'cfg(windows)'.dependencies] raw-window-handle.workspace = true 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 { diff --git a/core/src/window/settings/wasm.rs b/core/src/window/settings/wasm.rs index 8e0f1bbc..30e60b6a 100644 --- a/core/src/window/settings/wasm.rs +++ b/core/src/window/settings/wasm.rs @@ -1,11 +1,21 @@ //! Platform specific settings for WebAssembly. /// The platform specific window settings of an application. -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct PlatformSpecific { /// The identifier of a DOM element that will be replaced with the /// application. /// /// If set to `None`, the application will be appended to the HTML body. + /// + /// By default, it is set to `"iced"`. pub target: Option<String>, } + +impl Default for PlatformSpecific { + fn default() -> Self { + Self { + target: Some(String::from("iced")), + } + } +} |