From dac7e82e0bff128097653fe05829b2d576fcdb2f Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 28 Apr 2025 10:56:49 +0200 Subject: refactor(material_theme)!: make `Theme` an enum with `Custom` variant --- crates/material_theme/src/container.rs | 119 ++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 46 deletions(-) (limited to 'crates/material_theme/src/container.rs') diff --git a/crates/material_theme/src/container.rs b/crates/material_theme/src/container.rs index a14cfd5..5c253ad 100644 --- a/crates/material_theme/src/container.rs +++ b/crates/material_theme/src/container.rs @@ -1,5 +1,5 @@ use iced_widget::container::{Catalog, Style, StyleFn}; -use iced_widget::core::{Background, border}; +use iced_widget::core::{Background, Border, border}; use super::Theme; @@ -23,151 +23,178 @@ pub fn transparent(_theme: &Theme) -> Style { } pub fn primary(theme: &Theme) -> Style { - let colors = theme.colorscheme.primary; + let primary = theme.colors().primary; + Style { - background: Some(Background::Color(colors.color)), - text_color: Some(colors.on_primary), + background: Some(Background::Color(primary.color)), + text_color: Some(primary.on_primary), border: border::rounded(4), ..Style::default() } } pub fn primary_container(theme: &Theme) -> Style { - let colors = theme.colorscheme.primary; + let primary = theme.colors().primary; + Style { - background: Some(Background::Color(colors.primary_container)), - text_color: Some(colors.on_primary_container), + background: Some(Background::Color(primary.primary_container)), + text_color: Some(primary.on_primary_container), border: border::rounded(8), ..Style::default() } } pub fn secondary(theme: &Theme) -> Style { - let colors = theme.colorscheme.secondary; + let secondary = theme.colors().secondary; + Style { - background: Some(Background::Color(colors.color)), - text_color: Some(colors.on_secondary), + background: Some(Background::Color(secondary.color)), + text_color: Some(secondary.on_secondary), border: border::rounded(4), ..Style::default() } } pub fn secondary_container(theme: &Theme) -> Style { - let colors = theme.colorscheme.secondary; + let secondary = theme.colors().secondary; + Style { - background: Some(Background::Color(colors.secondary_container)), - text_color: Some(colors.on_secondary_container), + background: Some(Background::Color(secondary.secondary_container)), + text_color: Some(secondary.on_secondary_container), border: border::rounded(8), ..Style::default() } } pub fn tertiary(theme: &Theme) -> Style { - let colors = theme.colorscheme.tertiary; + let tertiary = theme.colors().tertiary; + Style { - background: Some(Background::Color(colors.color)), - text_color: Some(colors.on_tertiary), + background: Some(Background::Color(tertiary.color)), + text_color: Some(tertiary.on_tertiary), border: border::rounded(4), ..Style::default() } } pub fn tertiary_container(theme: &Theme) -> Style { - let colors = theme.colorscheme.tertiary; + let tertiary = theme.colors().tertiary; + Style { - background: Some(Background::Color(colors.tertiary_container)), - text_color: Some(colors.on_tertiary_container), + background: Some(Background::Color(tertiary.tertiary_container)), + text_color: Some(tertiary.on_tertiary_container), border: border::rounded(8), ..Style::default() } } pub fn error(theme: &Theme) -> Style { - let colors = theme.colorscheme.error; + let error = theme.colors().error; + Style { - background: Some(Background::Color(colors.color)), - text_color: Some(colors.on_error), + background: Some(Background::Color(error.color)), + text_color: Some(error.on_error), border: border::rounded(4), ..Style::default() } } pub fn error_container(theme: &Theme) -> Style { - let colors = theme.colorscheme.error; + let error = theme.colors().error; + Style { - background: Some(Background::Color(colors.error_container)), - text_color: Some(colors.on_error_container), + background: Some(Background::Color(error.error_container)), + text_color: Some(error.on_error_container), border: border::rounded(8), ..Style::default() } } pub fn surface(theme: &Theme) -> Style { - let colors = theme.colorscheme.surface; + let surface = theme.colors().surface; + Style { - background: Some(Background::Color(colors.color)), - text_color: Some(colors.on_surface), + background: Some(Background::Color(surface.color)), + text_color: Some(surface.on_surface), border: border::rounded(4), ..Style::default() } } pub fn surface_container_lowest(theme: &Theme) -> Style { - let colors = theme.colorscheme.surface; + let surface = theme.colors().surface; + Style { - background: Some(Background::Color(colors.surface_container.lowest)), - text_color: Some(colors.on_surface), + background: Some(Background::Color(surface.surface_container.lowest)), + text_color: Some(surface.on_surface), border: border::rounded(8), ..Style::default() } } pub fn surface_container_low(theme: &Theme) -> Style { - let colors = theme.colorscheme.surface; + let surface = theme.colors().surface; + Style { - background: Some(Background::Color(colors.surface_container.low)), - text_color: Some(colors.on_surface), + background: Some(Background::Color(surface.surface_container.low)), + text_color: Some(surface.on_surface), border: border::rounded(8), ..Style::default() } } pub fn surface_container(theme: &Theme) -> Style { - let colors = theme.colorscheme.surface; + let surface = theme.colors().surface; + Style { - background: Some(Background::Color(colors.surface_container.base)), - text_color: Some(colors.on_surface), + background: Some(Background::Color(surface.surface_container.base)), + text_color: Some(surface.on_surface), border: border::rounded(8), ..Style::default() } } pub fn surface_container_high(theme: &Theme) -> Style { - let colors = theme.colorscheme.surface; + let surface = theme.colors().surface; + Style { - background: Some(Background::Color(colors.surface_container.high)), - text_color: Some(colors.on_surface), + background: Some(Background::Color(surface.surface_container.high)), + text_color: Some(surface.on_surface), border: border::rounded(8), ..Style::default() } } pub fn surface_container_highest(theme: &Theme) -> Style { - let colors = theme.colorscheme.surface; + let surface = theme.colors().surface; + Style { - background: Some(Background::Color(colors.surface_container.highest)), - text_color: Some(colors.on_surface), + background: Some(Background::Color(surface.surface_container.highest)), + text_color: Some(surface.on_surface), border: border::rounded(8), ..Style::default() } } pub fn inverse_surface(theme: &Theme) -> Style { - let colors = theme.colorscheme.inverse; + let inverse = theme.colors().inverse; + Style { - background: Some(Background::Color(colors.inverse_surface)), - text_color: Some(colors.inverse_on_surface), + background: Some(Background::Color(inverse.inverse_surface)), + text_color: Some(inverse.inverse_on_surface), border: border::rounded(4), ..Style::default() } } + +pub fn outlined(theme: &Theme) -> Style { + let base = transparent(theme); + + Style { + border: Border { + color: theme.colors().outline.color, + ..base.border + }, + ..base + } +} -- cgit v1.2.3