diff options
Diffstat (limited to '')
| -rw-r--r-- | Cargo.toml | 3 | ||||
| -rw-r--r-- | crates/material_theme/src/lib.rs | 44 | ||||
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | theme_test/Cargo.toml | 1 |
4 files changed, 32 insertions, 18 deletions
@@ -43,7 +43,8 @@ toml = "0.8.20" [workspace.dependencies.iced] git = "https://github.com/pml68/iced" branch = "feat/rehighlight-on-redraw" -features = ["image", "svg", "advanced", "tokio", "lazy"] +default-features = false +features = ["wgpu", "tiny-skia", "web-colors", "auto-detect-theme", "image", "svg", "advanced", "tokio", "lazy"] [build-dependencies] iced_fontello = "0.13.2" diff --git a/crates/material_theme/src/lib.rs b/crates/material_theme/src/lib.rs index 25b6a9c..569b06c 100644 --- a/crates/material_theme/src/lib.rs +++ b/crates/material_theme/src/lib.rs @@ -29,6 +29,20 @@ pub mod text_input; pub mod toggler; pub mod utils; +#[allow(clippy::cast_precision_loss)] +macro_rules! from_argb { + ($hex:expr) => {{ + let hex = $hex as u32; + + let a = ((hex & 0xff000000) >> 24) as f32 / 255.0; + let r = (hex & 0x00ff0000) >> 16; + let g = (hex & 0x0000ff00) >> 8; + let b = (hex & 0x000000ff); + + ::iced_widget::core::color!(r as u8, g as u8, b as u8, a) + }}; +} + #[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Theme { @@ -89,8 +103,20 @@ impl Base for Theme { } fn palette(&self) -> Option<iced_widget::theme::Palette> { - // TODO: create a Palette - None + let colors = self.colorscheme; + + Some(iced_widget::theme::Palette { + background: colors.surface.color, + text: colors.surface.on_surface, + primary: colors.primary.color, + success: colors.primary.primary_container, + warning: utils::mix( + from_argb!(0xffffff00), + colors.primary.color, + 0.25, + ), + danger: colors.error.color, + }) } } @@ -134,20 +160,6 @@ pub struct ColorScheme { } #[allow(clippy::cast_precision_loss)] -macro_rules! from_argb { - ($hex:expr) => {{ - let hex = $hex as u32; - - let a = ((hex & 0xff000000) >> 24) as f32 / 255.0; - let r = (hex & 0x00ff0000) >> 16; - let g = (hex & 0x0000ff00) >> 8; - let b = (hex & 0x000000ff); - - ::iced_widget::core::color!(r as u8, g as u8, b as u8, a) - }}; -} - -#[allow(clippy::cast_precision_loss)] impl ColorScheme { const DARK: Self = Self { primary: Primary { diff --git a/src/main.rs b/src/main.rs index 0f1a1bf..5014077 100644 --- a/src/main.rs +++ b/src/main.rs @@ -146,8 +146,8 @@ impl IcedBuilder { Message::ConfigLoad(result) => match result { Ok(config) => { self.config = Arc::new(config); - self.theme.update(self.config.selected_theme().into()); + return if let Some(path) = self.config.last_project.clone() { if path.exists() && path.is_file() { diff --git a/theme_test/Cargo.toml b/theme_test/Cargo.toml index 29fcdc8..300a7af 100644 --- a/theme_test/Cargo.toml +++ b/theme_test/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] iced.workspace = true +iced.features = ["debug"] iced_anim.workspace = true iced_dialog.workspace = true material_theme = { path = "../crates/material_theme", features = ["dialog", "animate"] } |
