diff options
author | 2024-03-06 17:08:28 +0100 | |
---|---|---|
committer | 2024-03-06 17:08:57 +0100 | |
commit | 597a41cea73f078eda04eb3ff40cfda5d37d6135 (patch) | |
tree | 216779f151b68952fd5d668065dc900be08e3e99 /style | |
parent | 9b2fd6416775cb27af69e34fb20063d28b4314eb (diff) | |
download | iced-597a41cea73f078eda04eb3ff40cfda5d37d6135.tar.gz iced-597a41cea73f078eda04eb3ff40cfda5d37d6135.tar.bz2 iced-597a41cea73f078eda04eb3ff40cfda5d37d6135.zip |
Simplify theming for `PickList`, `ComboBox`, and `Menu` widgets
Diffstat (limited to 'style')
-rw-r--r-- | style/src/lib.rs | 2 | ||||
-rw-r--r-- | style/src/menu.rs | 26 | ||||
-rw-r--r-- | style/src/pick_list.rs | 29 | ||||
-rw-r--r-- | style/src/theme.rs | 108 |
4 files changed, 0 insertions, 165 deletions
diff --git a/style/src/lib.rs b/style/src/lib.rs index 695f8fb6..1aea2d80 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 menu; -pub mod pick_list; pub mod theme; pub use theme::Theme; diff --git a/style/src/menu.rs b/style/src/menu.rs deleted file mode 100644 index be60a3f8..00000000 --- a/style/src/menu.rs +++ /dev/null @@ -1,26 +0,0 @@ -//! Change the appearance of menus. -use iced_core::{Background, Border, Color}; - -/// The appearance of a menu. -#[derive(Debug, Clone, Copy)] -pub struct Appearance { - /// The text [`Color`] of the menu. - pub text_color: Color, - /// The [`Background`] of the menu. - pub background: Background, - /// The [`Border`] of the menu. - pub border: Border, - /// The text [`Color`] of a selected option in the menu. - pub selected_text_color: Color, - /// The background [`Color`] of a selected option in the menu. - pub selected_background: Background, -} - -/// The style sheet of a menu. -pub trait StyleSheet { - /// The supported style of the [`StyleSheet`]. - type Style: Default + Clone; - - /// Produces the [`Appearance`] of a menu. - fn appearance(&self, style: &Self::Style) -> Appearance; -} diff --git a/style/src/pick_list.rs b/style/src/pick_list.rs deleted file mode 100644 index 8f008f4a..00000000 --- a/style/src/pick_list.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! Change the appearance of a pick list. -use iced_core::{Background, Border, Color}; - -/// The appearance of a pick list. -#[derive(Debug, Clone, Copy)] -pub struct Appearance { - /// The text [`Color`] of the pick list. - pub text_color: Color, - /// The placeholder [`Color`] of the pick list. - pub placeholder_color: Color, - /// The handle [`Color`] of the pick list. - pub handle_color: Color, - /// The [`Background`] of the pick list. - pub background: Background, - /// The [`Border`] of the pick list. - pub border: Border, -} - -/// A set of rules that dictate the style of a container. -pub trait StyleSheet { - /// The supported style of the [`StyleSheet`]. - type Style: Default + Clone; - - /// Produces the active [`Appearance`] of a pick list. - fn active(&self, style: &<Self as StyleSheet>::Style) -> Appearance; - - /// Produces the hovered [`Appearance`] of a pick list. - fn hovered(&self, style: &<Self as StyleSheet>::Style) -> Appearance; -} diff --git a/style/src/theme.rs b/style/src/theme.rs index cac52acd..fd93f776 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -5,13 +5,8 @@ pub use palette::Palette; use crate::application; use crate::core::widget::text; -use crate::menu; -use crate::pick_list; - -use crate::core::Border; use std::fmt; -use std::rc::Rc; use std::sync::Arc; /// A built-in theme. @@ -271,107 +266,4 @@ impl<T: Fn(&Theme) -> application::Appearance> application::StyleSheet for T { } } -/// The style of a menu. -#[derive(Clone, Default)] -pub enum Menu { - /// The default style. - #[default] - Default, - /// A custom style. - Custom(Rc<dyn menu::StyleSheet<Style = Theme>>), -} - -impl menu::StyleSheet for Theme { - type Style = Menu; - - fn appearance(&self, style: &Self::Style) -> menu::Appearance { - match style { - Menu::Default => { - let palette = self.extended_palette(); - - menu::Appearance { - text_color: palette.background.weak.text, - background: palette.background.weak.color.into(), - border: Border { - width: 1.0, - radius: 0.0.into(), - color: palette.background.strong.color, - }, - selected_text_color: palette.primary.strong.text, - selected_background: palette.primary.strong.color.into(), - } - } - Menu::Custom(custom) => custom.appearance(self), - } - } -} - -impl From<PickList> for Menu { - fn from(pick_list: PickList) -> Self { - match pick_list { - PickList::Default => Self::Default, - PickList::Custom(_, menu) => Self::Custom(menu), - } - } -} - -/// The style of a pick list. -#[derive(Clone, Default)] -pub enum PickList { - /// The default style. - #[default] - Default, - /// A custom style. - Custom( - Rc<dyn pick_list::StyleSheet<Style = Theme>>, - Rc<dyn menu::StyleSheet<Style = Theme>>, - ), -} - -impl pick_list::StyleSheet for Theme { - type Style = PickList; - - fn active(&self, style: &Self::Style) -> pick_list::Appearance { - match style { - PickList::Default => { - let palette = self.extended_palette(); - - pick_list::Appearance { - text_color: palette.background.weak.text, - background: palette.background.weak.color.into(), - placeholder_color: palette.background.strong.color, - handle_color: palette.background.weak.text, - border: Border { - radius: 2.0.into(), - width: 1.0, - color: palette.background.strong.color, - }, - } - } - PickList::Custom(custom, _) => custom.active(self), - } - } - - fn hovered(&self, style: &Self::Style) -> pick_list::Appearance { - match style { - PickList::Default => { - let palette = self.extended_palette(); - - pick_list::Appearance { - text_color: palette.background.weak.text, - background: palette.background.weak.color.into(), - placeholder_color: palette.background.strong.color, - handle_color: palette.background.weak.text, - border: Border { - radius: 2.0.into(), - width: 1.0, - color: palette.primary.strong.color, - }, - } - } - PickList::Custom(custom, _) => custom.hovered(self), - } - } -} - impl text::StyleSheet for Theme {} |