summaryrefslogtreecommitdiff
path: root/crates/material_theme/src/button.rs
diff options
context:
space:
mode:
authorpml68 <contact@pml68.dev>2025-04-28 10:56:49 +0200
committerpml68 <contact@pml68.dev>2025-04-28 10:56:49 +0200
commitdac7e82e0bff128097653fe05829b2d576fcdb2f (patch)
tree6f36736e79eecd6904933c6876af1df58e6b605b /crates/material_theme/src/button.rs
parentfeat(material_theme): implement `image::Catalog` (under feature flag) (diff)
downloadiced-builder-dac7e82e0bff128097653fe05829b2d576fcdb2f.tar.gz
refactor(material_theme)!: make `Theme` an enum with `Custom` variant
Diffstat (limited to 'crates/material_theme/src/button.rs')
-rw-r--r--crates/material_theme/src/button.rs103
1 files changed, 33 insertions, 70 deletions
diff --git a/crates/material_theme/src/button.rs b/crates/material_theme/src/button.rs
index e1369eb..3f16bc7 100644
--- a/crates/material_theme/src/button.rs
+++ b/crates/material_theme/src/button.rs
@@ -3,8 +3,8 @@ use iced_widget::core::{Background, Border, Color, border};
use crate::Theme;
use crate::utils::{
- DISABLED_CONTAINER_OPACITY, DISABLED_TEXT_OPACITY, HOVERED_LAYER_OPACITY,
- PRESSED_LAYER_OPACITY, elevation, mix, shadow_from_elevation,
+ HOVERED_LAYER_OPACITY, PRESSED_LAYER_OPACITY, disabled_container,
+ disabled_text, elevation, mix, shadow_from_elevation,
};
impl Catalog for Theme {
@@ -20,9 +20,8 @@ impl Catalog for Theme {
}
fn button(
- foreground: Color,
background: Color,
- tone_overlay: Color,
+ foreground: Color,
disabled: Color,
shadow_color: Color,
elevation_level: u8,
@@ -40,7 +39,7 @@ fn button(
Status::Pressed => Style {
background: Some(Background::Color(mix(
background,
- tone_overlay,
+ foreground,
HOVERED_LAYER_OPACITY,
))),
..active
@@ -48,25 +47,18 @@ fn button(
Status::Hovered => Style {
background: Some(Background::Color(mix(
background,
- tone_overlay,
+ foreground,
PRESSED_LAYER_OPACITY,
))),
- text_color: foreground,
- border: border::rounded(400),
shadow: shadow_from_elevation(
elevation(elevation_level + 1),
shadow_color,
),
+ ..active
},
Status::Disabled => Style {
- background: Some(Background::Color(Color {
- a: DISABLED_CONTAINER_OPACITY,
- ..disabled
- })),
- text_color: Color {
- a: DISABLED_TEXT_OPACITY,
- ..disabled
- },
+ background: Some(Background::Color(disabled_container(disabled))),
+ text_color: disabled_text(disabled),
border: border::rounded(400),
..Default::default()
},
@@ -74,70 +66,46 @@ fn button(
}
pub fn elevated(theme: &Theme, status: Status) -> Style {
- let surface_colors = theme.colorscheme.surface;
+ let surface = theme.colors().surface;
- let foreground = theme.colorscheme.primary.color;
- let background = surface_colors.surface_container.low;
- let disabled = surface_colors.on_surface;
+ let foreground = theme.colors().primary.color;
+ let background = surface.surface_container.low;
+ let disabled = surface.on_surface;
- let shadow_color = theme.colorscheme.shadow;
+ let shadow_color = theme.colors().shadow;
- button(
- foreground,
- background,
- foreground,
- disabled,
- shadow_color,
- 1,
- status,
- )
+ button(background, foreground, disabled, shadow_color, 1, status)
}
pub fn filled(theme: &Theme, status: Status) -> Style {
- let primary_colors = theme.colorscheme.primary;
+ let primary = theme.colors().primary;
- let foreground = primary_colors.on_primary;
- let background = primary_colors.color;
- let disabled = theme.colorscheme.surface.on_surface;
+ let foreground = primary.on_primary;
+ let background = primary.color;
+ let disabled = theme.colors().surface.on_surface;
- let shadow_color = theme.colorscheme.shadow;
+ let shadow_color = theme.colors().shadow;
- button(
- foreground,
- background,
- foreground,
- disabled,
- shadow_color,
- 0,
- status,
- )
+ button(background, foreground, disabled, shadow_color, 0, status)
}
pub fn filled_tonal(theme: &Theme, status: Status) -> Style {
- let secondary_colors = theme.colorscheme.secondary;
+ let secondary = theme.colors().secondary;
- let foreground = secondary_colors.on_secondary_container;
- let background = secondary_colors.secondary_container;
- let disabled = theme.colorscheme.surface.on_surface;
- let shadow_color = theme.colorscheme.shadow;
+ let foreground = secondary.on_secondary_container;
+ let background = secondary.secondary_container;
+ let disabled = theme.colors().surface.on_surface;
+ let shadow_color = theme.colors().shadow;
- button(
- foreground,
- background,
- foreground,
- disabled,
- shadow_color,
- 0,
- status,
- )
+ button(background, foreground, disabled, shadow_color, 0, status)
}
pub fn outlined(theme: &Theme, status: Status) -> Style {
- let foreground = theme.colorscheme.primary.color;
+ let foreground = theme.colors().primary.color;
let background = Color::TRANSPARENT;
- let disabled = theme.colorscheme.surface.on_surface;
+ let disabled = theme.colors().surface.on_surface;
- let outline = theme.colorscheme.outline.color;
+ let outline = theme.colors().outline.color;
let border = match status {
Status::Active | Status::Pressed | Status::Hovered => Border {
@@ -146,17 +114,13 @@ pub fn outlined(theme: &Theme, status: Status) -> Style {
radius: 400.into(),
},
Status::Disabled => Border {
- color: Color {
- a: DISABLED_CONTAINER_OPACITY,
- ..disabled
- },
+ color: disabled_container(disabled),
width: 1.0,
radius: 400.into(),
},
};
let style = button(
- foreground,
background,
foreground,
disabled,
@@ -169,12 +133,11 @@ pub fn outlined(theme: &Theme, status: Status) -> Style {
}
pub fn text(theme: &Theme, status: Status) -> Style {
- let foreground = theme.colorscheme.primary.color;
+ let foreground = theme.colors().primary.color;
let background = Color::TRANSPARENT;
- let disabled = theme.colorscheme.surface.on_surface;
+ let disabled = theme.colors().surface.on_surface;
let style = button(
- foreground,
background,
foreground,
disabled,
@@ -185,7 +148,7 @@ pub fn text(theme: &Theme, status: Status) -> Style {
match status {
Status::Hovered | Status::Pressed => style,
- _ => Style {
+ Status::Active | Status::Disabled => Style {
background: None,
..style
},