use iced_widget::core::Color; use iced_widget::toggler::{Catalog, Status, Style, StyleFn}; use super::Theme; use crate::utils::{ HOVERED_LAYER_OPACITY, disabled_container, 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, foreground: Color, text_color: Color, border: Option, ) -> Style { Style { background, background_border_width: if border.is_some() { 2.0 } else { 0.0 }, background_border_color: border.unwrap_or(Color::TRANSPARENT), foreground, foreground_border_width: 2.0, foreground_border_color: Color::TRANSPARENT, text_color: Some(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_toggled } => { if is_toggled { styled(primary.color, primary.text, surface.text, None) } else { styled( surface.container.highest, theme.colors().outline.color, surface.text, Some(theme.colors().outline.color), ) } } Status::Hovered { is_toggled } => { if is_toggled { styled(primary.color, primary.container, surface.text, None) } else { styled( mix( surface.container.highest, surface.text, HOVERED_LAYER_OPACITY, ), surface.text_variant, surface.text, Some(theme.colors().outline.color), ) } } Status::Disabled { is_toggled } => { if is_toggled { styled( disabled_container(surface.text), disabled_text(surface.color), surface.text, None, ) } else { styled( disabled_container(surface.container.highest), disabled_text(surface.text), surface.text, Some(disabled_text(surface.text)), ) } } } }