diff options
Diffstat (limited to 'style/src')
-rw-r--r-- | style/src/menu.rs | 17 | ||||
-rw-r--r-- | style/src/pick_list.rs | 65 | ||||
-rw-r--r-- | style/src/theme.rs | 58 |
3 files changed, 73 insertions, 67 deletions
diff --git a/style/src/menu.rs b/style/src/menu.rs index 90985b8f..b1dd5ea0 100644 --- a/style/src/menu.rs +++ b/style/src/menu.rs @@ -2,7 +2,7 @@ use iced_core::{Background, Color}; /// The appearance of a menu. #[derive(Debug, Clone, Copy)] -pub struct Style { +pub struct Appearance { pub text_color: Color, pub background: Background, pub border_width: f32, @@ -11,15 +11,8 @@ pub struct Style { pub selected_background: Background, } -impl std::default::Default for Style { - fn default() -> Self { - Self { - text_color: Color::BLACK, - background: Background::Color([0.87, 0.87, 0.87].into()), - border_width: 1.0, - border_color: [0.7, 0.7, 0.7].into(), - selected_text_color: Color::WHITE, - selected_background: Background::Color([0.4, 0.4, 1.0].into()), - } - } +pub trait StyleSheet { + type Style: Default + Copy; + + fn appearance(&self, style: Self::Style) -> Appearance; } diff --git a/style/src/pick_list.rs b/style/src/pick_list.rs index ad96b201..2bafe932 100644 --- a/style/src/pick_list.rs +++ b/style/src/pick_list.rs @@ -1,9 +1,12 @@ -use crate::menu; use iced_core::{Background, Color}; +use crate::container; +use crate::menu; +use crate::scrollable; + /// The appearance of a pick list. #[derive(Debug, Clone, Copy)] -pub struct Style { +pub struct Appearance { pub text_color: Color, pub placeholder_color: Color, pub background: Background, @@ -13,60 +16,14 @@ pub struct Style { pub icon_size: f32, } -impl std::default::Default for Style { - fn default() -> Self { - Self { - text_color: Color::BLACK, - placeholder_color: [0.4, 0.4, 0.4].into(), - background: Background::Color([0.87, 0.87, 0.87].into()), - border_radius: 0.0, - border_width: 1.0, - border_color: [0.7, 0.7, 0.7].into(), - icon_size: 0.7, - } - } -} - /// A set of rules that dictate the style of a container. -pub trait StyleSheet { - fn menu(&self) -> menu::Style; +pub trait StyleSheet: + container::StyleSheet + menu::StyleSheet + scrollable::StyleSheet +{ + type Style: Default + Copy + Into<<Self as menu::StyleSheet>::Style>; - fn active(&self) -> Style; + fn active(&self, style: <Self as StyleSheet>::Style) -> Appearance; /// Produces the style of a container. - fn hovered(&self) -> Style; -} - -struct Default; - -impl StyleSheet for Default { - fn menu(&self) -> menu::Style { - menu::Style::default() - } - - fn active(&self) -> Style { - Style::default() - } - - fn hovered(&self) -> Style { - Style { - border_color: Color::BLACK, - ..self.active() - } - } -} - -impl<'a> std::default::Default for Box<dyn StyleSheet + 'a> { - fn default() -> Self { - Box::new(Default) - } -} - -impl<'a, T> From<T> for Box<dyn StyleSheet + 'a> -where - T: 'a + StyleSheet, -{ - fn from(style: T) -> Self { - Box::new(style) - } + fn hovered(&self, style: <Self as StyleSheet>::Style) -> Appearance; } diff --git a/style/src/theme.rs b/style/src/theme.rs index 0e9a5964..b1e18c55 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -6,7 +6,9 @@ use crate::application; use crate::button; use crate::checkbox; use crate::container; +use crate::menu; use crate::pane_grid; +use crate::pick_list; use crate::progress_bar; use crate::radio; use crate::rule; @@ -328,6 +330,61 @@ impl slider::StyleSheet for Theme { } /* + * Menu + */ +impl menu::StyleSheet for Theme { + type Style = (); + + fn appearance(&self, _style: Self::Style) -> menu::Appearance { + let palette = self.extended_palette(); + + menu::Appearance { + text_color: palette.background.weak.text, + background: palette.background.weak.color.into(), + border_width: 1.0, + border_color: palette.background.strong.color, + selected_text_color: palette.primary.strong.text, + selected_background: palette.primary.strong.color.into(), + } + } +} + +/* + * Pick List + */ +impl pick_list::StyleSheet for Theme { + type Style = (); + + fn active(&self, _style: ()) -> pick_list::Appearance { + 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, + border_radius: 2.0, + border_width: 1.0, + border_color: palette.background.strong.color, + icon_size: 0.7, + } + } + + fn hovered(&self, _style: ()) -> pick_list::Appearance { + 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, + border_radius: 2.0, + border_width: 1.0, + border_color: palette.primary.strong.color, + icon_size: 0.7, + } + } +} + +/* * Radio */ impl radio::StyleSheet for Theme { @@ -506,7 +563,6 @@ impl rule::StyleSheet for Theme { /* * Scrollable */ - impl scrollable::StyleSheet for Theme { type Style = (); |