diff options
author | 2022-05-26 23:07:34 +0200 | |
---|---|---|
committer | 2022-05-26 23:07:34 +0200 | |
commit | cf0230072c01ea9523f4d98a3656f5c975b3f347 (patch) | |
tree | ed24c6b90c6e319129e5fe963d50593846aaab72 /style | |
parent | 7f3b7075db68a215f4331b4bfba1c8ddd1c4d7f3 (diff) | |
download | iced-cf0230072c01ea9523f4d98a3656f5c975b3f347.tar.gz iced-cf0230072c01ea9523f4d98a3656f5c975b3f347.tar.bz2 iced-cf0230072c01ea9523f4d98a3656f5c975b3f347.zip |
Rename `Variant` to `Style` and `Style` to `Appearance`
Diffstat (limited to 'style')
-rw-r--r-- | style/src/button.rs | 26 | ||||
-rw-r--r-- | style/src/slider.rs | 10 | ||||
-rw-r--r-- | style/src/theme.rs | 56 |
3 files changed, 46 insertions, 46 deletions
diff --git a/style/src/button.rs b/style/src/button.rs index 9f00185c..c63a6b71 100644 --- a/style/src/button.rs +++ b/style/src/button.rs @@ -3,7 +3,7 @@ use iced_core::{Background, Color, Vector}; /// The appearance of a button. #[derive(Debug, Clone, Copy)] -pub struct Style { +pub struct Appearance { pub shadow_offset: Vector, pub background: Option<Background>, pub border_radius: f32, @@ -12,7 +12,7 @@ pub struct Style { pub text_color: Color, } -impl std::default::Default for Style { +impl std::default::Default for Appearance { fn default() -> Self { Self { shadow_offset: Vector::default(), @@ -27,30 +27,30 @@ impl std::default::Default for Style { /// A set of rules that dictate the style of a button. pub trait StyleSheet { - type Variant; + type Style: Default + Copy; - fn active(&self, variant: Self::Variant) -> Style; + fn active(&self, style: Self::Style) -> Appearance; - fn hovered(&self, variant: Self::Variant) -> Style { - let active = self.active(variant); + fn hovered(&self, style: Self::Style) -> Appearance { + let active = self.active(style); - Style { + Appearance { shadow_offset: active.shadow_offset + Vector::new(0.0, 1.0), ..active } } - fn pressed(&self, variant: Self::Variant) -> Style { - Style { + fn pressed(&self, style: Self::Style) -> Appearance { + Appearance { shadow_offset: Vector::default(), - ..self.active(variant) + ..self.active(style) } } - fn disabled(&self, variant: Self::Variant) -> Style { - let active = self.active(variant); + fn disabled(&self, style: Self::Style) -> Appearance { + let active = self.active(style); - Style { + Appearance { shadow_offset: Vector::default(), background: active.background.map(|background| match background { Background::Color(color) => Background::Color(Color { diff --git a/style/src/slider.rs b/style/src/slider.rs index 2bf0de73..0ff0449b 100644 --- a/style/src/slider.rs +++ b/style/src/slider.rs @@ -3,7 +3,7 @@ use iced_core::Color; /// The appearance of a slider. #[derive(Debug, Clone, Copy)] -pub struct Style { +pub struct Appearance { pub rail_colors: (Color, Color), pub handle: Handle, } @@ -26,14 +26,14 @@ pub enum HandleShape { /// A set of rules that dictate the style of a slider. pub trait StyleSheet { - type Variant: Default + Copy; + type Style: Default + Copy; /// Produces the style of an active slider. - fn active(&self, variant: Self::Variant) -> Style; + fn active(&self, style: Self::Style) -> Appearance; /// Produces the style of an hovered slider. - fn hovered(&self, variant: Self::Variant) -> Style; + fn hovered(&self, style: Self::Style) -> Appearance; /// Produces the style of a slider that is being dragged. - fn dragging(&self, variant: Self::Variant) -> Style; + fn dragging(&self, style: Self::Style) -> Appearance; } diff --git a/style/src/theme.rs b/style/src/theme.rs index 9cfbd1d5..df67f594 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -66,49 +66,49 @@ impl Default for Button { } impl button::StyleSheet for Theme { - type Variant = Button; + type Style = Button; - fn active(&self, variant: Self::Variant) -> button::Style { + fn active(&self, style: Self::Style) -> button::Appearance { let palette = self.extended_palette(); - let style = button::Style { + let appearance = button::Appearance { border_radius: 2.0, - ..button::Style::default() + ..button::Appearance::default() }; - match variant { - Button::Primary => button::Style { + match style { + Button::Primary => button::Appearance { background: Some(palette.primary.strong.into()), text_color: palette.primary.text, - ..style + ..appearance }, - Button::Secondary => button::Style { + Button::Secondary => button::Appearance { background: Some(palette.background.weak.into()), text_color: palette.background.text, - ..style + ..appearance }, - Button::Positive => button::Style { + Button::Positive => button::Appearance { background: Some(palette.success.base.into()), text_color: palette.success.text, - ..style + ..appearance }, - Button::Destructive => button::Style { + Button::Destructive => button::Appearance { background: Some(palette.danger.base.into()), text_color: palette.danger.text, - ..style + ..appearance }, - Button::Text => button::Style { + Button::Text => button::Appearance { text_color: palette.background.text, - ..style + ..appearance }, } } - fn hovered(&self, variant: Self::Variant) -> button::Style { - let active = self.active(variant); + fn hovered(&self, style: Self::Style) -> button::Appearance { + let active = self.active(style); let palette = self.extended_palette(); - let background = match variant { + let background = match style { Button::Primary => Some(palette.primary.base), Button::Secondary => Some(palette.background.strong), Button::Positive => Some(palette.success.strong), @@ -116,7 +116,7 @@ impl button::StyleSheet for Theme { Button::Text => None, }; - button::Style { + button::Appearance { background: background.map(Background::from), ..active } @@ -124,9 +124,9 @@ impl button::StyleSheet for Theme { } impl slider::StyleSheet for Theme { - type Variant = (); + type Style = (); - fn active(&self, _variant: Self::Variant) -> slider::Style { + fn active(&self, _style: Self::Style) -> slider::Appearance { let palette = self.extended_palette(); let handle = slider::Handle { @@ -139,7 +139,7 @@ impl slider::StyleSheet for Theme { border_width: 1.0, }; - slider::Style { + slider::Appearance { rail_colors: (palette.primary.base, palette.background.base), handle: slider::Handle { color: palette.background.base, @@ -149,11 +149,11 @@ impl slider::StyleSheet for Theme { } } - fn hovered(&self, variant: Self::Variant) -> slider::Style { - let active = self.active(variant); + fn hovered(&self, style: Self::Style) -> slider::Appearance { + let active = self.active(style); let palette = self.extended_palette(); - slider::Style { + slider::Appearance { handle: slider::Handle { color: palette.primary.weak, ..active.handle @@ -162,11 +162,11 @@ impl slider::StyleSheet for Theme { } } - fn dragging(&self, variant: Self::Variant) -> slider::Style { - let active = self.active(variant); + fn dragging(&self, style: Self::Style) -> slider::Appearance { + let active = self.active(style); let palette = self.extended_palette(); - slider::Style { + slider::Appearance { handle: slider::Handle { color: palette.primary.base, ..active.handle |