summaryrefslogtreecommitdiff
path: root/crates/material_theme/src/lib.rs
diff options
context:
space:
mode:
authorpml68 <contact@pml68.dev>2025-04-25 11:30:46 +0200
committerpml68 <contact@pml68.dev>2025-04-25 11:30:57 +0200
commitf9f854f124d4676e8c79adeda6bfaceba586805f (patch)
tree2906bff72f25e3df7f9fd4fb4363c6e07eae99c6 /crates/material_theme/src/lib.rs
parentrefactor(material_theme): make `Theme` `Copy`, add `Theme::ALL` constant (diff)
downloadiced-builder-f9f854f124d4676e8c79adeda6bfaceba586805f.tar.gz
feat(material_theme): create an iced `Palette` for `iced::theme::Base` impl
Diffstat (limited to '')
-rw-r--r--crates/material_theme/src/lib.rs44
1 files changed, 28 insertions, 16 deletions
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 {