From 1f0a0c235a7729cf2d5716efeecb9c4dc972fdfa Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 5 Mar 2024 02:08:19 +0100 Subject: Simplify theming for `Checkbox` widget --- style/src/theme.rs | 151 ----------------------------------------------------- 1 file changed, 151 deletions(-) (limited to 'style/src/theme.rs') diff --git a/style/src/theme.rs b/style/src/theme.rs index f967aebc..81303e68 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -4,7 +4,6 @@ pub mod palette; pub use palette::Palette; use crate::application; -use crate::checkbox; use crate::container; use crate::core::widget::text; use crate::menu; @@ -284,156 +283,6 @@ impl application::Appearance> application::StyleSheet for T { } } -/// The style of a checkbox. -#[derive(Default)] -pub enum Checkbox { - /// The primary style. - #[default] - Primary, - /// The secondary style. - Secondary, - /// The success style. - Success, - /// The danger style. - Danger, - /// A custom style. - Custom(Box>), -} - -impl checkbox::StyleSheet for Theme { - type Style = Checkbox; - - fn active( - &self, - style: &Self::Style, - is_checked: bool, - ) -> checkbox::Appearance { - let palette = self.extended_palette(); - - match style { - Checkbox::Primary => checkbox_appearance( - palette.primary.strong.text, - palette.background.base, - palette.primary.strong, - is_checked, - ), - Checkbox::Secondary => checkbox_appearance( - palette.background.base.text, - palette.background.base, - palette.background.strong, - is_checked, - ), - Checkbox::Success => checkbox_appearance( - palette.success.base.text, - palette.background.base, - palette.success.base, - is_checked, - ), - Checkbox::Danger => checkbox_appearance( - palette.danger.base.text, - palette.background.base, - palette.danger.base, - is_checked, - ), - Checkbox::Custom(custom) => custom.active(self, is_checked), - } - } - - fn hovered( - &self, - style: &Self::Style, - is_checked: bool, - ) -> checkbox::Appearance { - let palette = self.extended_palette(); - - match style { - Checkbox::Primary => checkbox_appearance( - palette.primary.strong.text, - palette.background.weak, - palette.primary.base, - is_checked, - ), - Checkbox::Secondary => checkbox_appearance( - palette.background.base.text, - palette.background.weak, - palette.background.strong, - is_checked, - ), - Checkbox::Success => checkbox_appearance( - palette.success.base.text, - palette.background.weak, - palette.success.base, - is_checked, - ), - Checkbox::Danger => checkbox_appearance( - palette.danger.base.text, - palette.background.weak, - palette.danger.base, - is_checked, - ), - Checkbox::Custom(custom) => custom.hovered(self, is_checked), - } - } - - fn disabled( - &self, - style: &Self::Style, - is_checked: bool, - ) -> checkbox::Appearance { - let palette = self.extended_palette(); - - match style { - Checkbox::Primary => checkbox_appearance( - palette.primary.strong.text, - palette.background.weak, - palette.background.strong, - is_checked, - ), - Checkbox::Secondary => checkbox_appearance( - palette.background.strong.color, - palette.background.weak, - palette.background.weak, - is_checked, - ), - Checkbox::Success => checkbox_appearance( - palette.success.base.text, - palette.background.weak, - palette.success.weak, - is_checked, - ), - Checkbox::Danger => checkbox_appearance( - palette.danger.base.text, - palette.background.weak, - palette.danger.weak, - is_checked, - ), - Checkbox::Custom(custom) => custom.active(self, is_checked), - } - } -} - -fn checkbox_appearance( - icon_color: Color, - base: palette::Pair, - accent: palette::Pair, - is_checked: bool, -) -> checkbox::Appearance { - checkbox::Appearance { - background: Background::Color(if is_checked { - accent.color - } else { - base.color - }), - icon_color, - border: Border { - radius: 2.0.into(), - width: 1.0, - color: accent.color, - }, - text_color: None, - } -} - /// The style of a container. #[derive(Default)] pub enum Container { -- cgit