diff options
| author | 2024-03-05 02:08:19 +0100 | |
|---|---|---|
| committer | 2024-03-05 02:08:19 +0100 | |
| commit | 1f0a0c235a7729cf2d5716efeecb9c4dc972fdfa (patch) | |
| tree | 77118b43726c9321d05190cb2e7963594e0f80a3 /style/src | |
| parent | f4a4845ddbdced81ae4ff60bfa19f0e602d84709 (diff) | |
| download | iced-1f0a0c235a7729cf2d5716efeecb9c4dc972fdfa.tar.gz iced-1f0a0c235a7729cf2d5716efeecb9c4dc972fdfa.tar.bz2 iced-1f0a0c235a7729cf2d5716efeecb9c4dc972fdfa.zip  | |
Simplify theming for `Checkbox` widget
Diffstat (limited to '')
| -rw-r--r-- | style/src/button.rs | 1 | ||||
| -rw-r--r-- | style/src/checkbox.rs | 37 | ||||
| -rw-r--r-- | style/src/lib.rs | 2 | ||||
| -rw-r--r-- | style/src/theme.rs | 151 | 
4 files changed, 0 insertions, 191 deletions
diff --git a/style/src/button.rs b/style/src/button.rs deleted file mode 100644 index 8b137891..00000000 --- a/style/src/button.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/style/src/checkbox.rs b/style/src/checkbox.rs deleted file mode 100644 index 5e1c8374..00000000 --- a/style/src/checkbox.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! Change the appearance of a checkbox. -use iced_core::{Background, Border, Color}; - -/// The appearance of a checkbox. -#[derive(Debug, Clone, Copy)] -pub struct Appearance { -    /// The [`Background`] of the checkbox. -    pub background: Background, -    /// The icon [`Color`] of the checkbox. -    pub icon_color: Color, -    /// The [`Border`] of hte checkbox. -    pub border: Border, -    /// The text [`Color`] of the checkbox. -    pub text_color: Option<Color>, -} - -/// A set of rules that dictate the style of a checkbox. -pub trait StyleSheet { -    /// The supported style of the [`StyleSheet`]. -    type Style: Default; - -    /// Produces the active [`Appearance`] of a checkbox. -    fn active(&self, style: &Self::Style, is_checked: bool) -> Appearance; - -    /// Produces the hovered [`Appearance`] of a checkbox. -    fn hovered(&self, style: &Self::Style, is_checked: bool) -> Appearance; - -    /// Produces the disabled [`Appearance`] of a checkbox. -    fn disabled(&self, style: &Self::Style, is_checked: bool) -> Appearance { -        let active = self.active(style, is_checked); - -        Appearance { -            background: active.background.transparentize(0.5), -            ..active -        } -    } -} diff --git a/style/src/lib.rs b/style/src/lib.rs index 17ba09c4..1b2ce444 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -17,8 +17,6 @@  pub use iced_core as core;  pub mod application; -pub mod button; -pub mod checkbox;  pub mod container;  pub mod menu;  pub mod pane_grid; 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<T: Fn(&Theme) -> 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<dyn checkbox::StyleSheet<Style = Theme>>), -} - -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 {  | 
