diff options
| author | pml68 <contact@pml68.dev> | 2025-06-26 12:16:52 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-06-26 12:16:52 +0200 |
| commit | 00c6cf80cb9c4587700078a062a6b32873b6f8ff (patch) | |
| tree | 9aad054c784b51d4a0bc97c928b89da7dbcab863 /crates/material_theme/src/checkbox.rs | |
| parent | feat: update for hot reloading support (diff) | |
| download | iced-builder-00c6cf80cb9c4587700078a062a6b32873b6f8ff.tar.gz | |
feat: extract `material_theme` into separate repo (`pml68/iced_material`)
Diffstat (limited to '')
| -rw-r--r-- | crates/material_theme/src/checkbox.rs | 115 |
1 files changed, 0 insertions, 115 deletions
diff --git a/crates/material_theme/src/checkbox.rs b/crates/material_theme/src/checkbox.rs deleted file mode 100644 index 7a3729c..0000000 --- a/crates/material_theme/src/checkbox.rs +++ /dev/null @@ -1,115 +0,0 @@ -use iced_widget::checkbox::{Catalog, Status, Style, StyleFn}; -use iced_widget::core::{Background, Border, Color, border}; - -use super::Theme; -use crate::utils::{HOVERED_LAYER_OPACITY, disabled_text, mix}; - -impl Catalog for Theme { - type Class<'a> = StyleFn<'a, Self>; - - fn default<'a>() -> Self::Class<'a> { - Box::new(default) - } - - fn style(&self, class: &Self::Class<'_>, status: Status) -> Style { - class(self, status) - } -} - -pub fn styled( - background_color: Color, - background_unchecked: Option<Color>, - icon_color: Color, - border_color: Color, - text_color: Option<Color>, - is_checked: bool, -) -> Style { - Style { - background: Background::Color(if is_checked { - background_color - } else { - background_unchecked.unwrap_or(Color::TRANSPARENT) - }), - icon_color, - border: if is_checked { - border::rounded(2) - } else { - Border { - color: border_color, - width: 2.0, - radius: 2.into(), - } - }, - text_color, - } -} - -pub fn default(theme: &Theme, status: Status) -> Style { - let surface = theme.colors().surface; - let primary = theme.colors().primary; - - match status { - Status::Active { is_checked } => styled( - primary.color, - None, - primary.on_primary, - surface.on_surface_variant, - Some(surface.on_surface), - is_checked, - ), - Status::Hovered { is_checked } => styled( - mix(primary.color, surface.on_surface, HOVERED_LAYER_OPACITY), - Some(Color { - a: HOVERED_LAYER_OPACITY, - ..surface.on_surface - }), - primary.on_primary, - surface.on_surface_variant, - Some(surface.on_surface), - is_checked, - ), - Status::Disabled { is_checked } => styled( - disabled_text(surface.on_surface), - None, - surface.color, - disabled_text(surface.on_surface), - Some(surface.on_surface), - is_checked, - ), - } -} - -pub fn error(theme: &Theme, status: Status) -> Style { - let surface = theme.colors().surface; - let error = theme.colors().error; - - match status { - Status::Active { is_checked } => styled( - error.color, - None, - error.on_error, - error.color, - Some(error.color), - is_checked, - ), - Status::Hovered { is_checked } => styled( - mix(error.color, surface.on_surface, HOVERED_LAYER_OPACITY), - Some(Color { - a: HOVERED_LAYER_OPACITY, - ..error.color - }), - error.on_error, - error.color, - Some(error.color), - is_checked, - ), - Status::Disabled { is_checked } => styled( - disabled_text(surface.on_surface), - None, - surface.color, - disabled_text(surface.on_surface), - Some(surface.on_surface), - is_checked, - ), - } -} |
