diff options
author | 2022-05-26 23:07:34 +0200 | |
---|---|---|
committer | 2022-05-26 23:07:34 +0200 | |
commit | cf0230072c01ea9523f4d98a3656f5c975b3f347 (patch) | |
tree | ed24c6b90c6e319129e5fe963d50593846aaab72 | |
parent | 7f3b7075db68a215f4331b4bfba1c8ddd1c4d7f3 (diff) | |
download | iced-cf0230072c01ea9523f4d98a3656f5c975b3f347.tar.gz iced-cf0230072c01ea9523f4d98a3656f5c975b3f347.tar.bz2 iced-cf0230072c01ea9523f4d98a3656f5c975b3f347.zip |
Rename `Variant` to `Style` and `Style` to `Appearance`
-rw-r--r-- | examples/component/src/main.rs | 2 | ||||
-rw-r--r-- | examples/pure/component/src/main.rs | 4 | ||||
-rw-r--r-- | native/src/widget/button.rs | 38 | ||||
-rw-r--r-- | native/src/widget/slider.rs | 22 | ||||
-rw-r--r-- | pure/src/helpers.rs | 1 | ||||
-rw-r--r-- | pure/src/widget/button.rs | 15 | ||||
-rw-r--r-- | pure/src/widget/slider.rs | 12 | ||||
-rw-r--r-- | src/pure/widget.rs | 2 | ||||
-rw-r--r-- | src/widget.rs | 2 | ||||
-rw-r--r-- | style/src/button.rs | 26 | ||||
-rw-r--r-- | style/src/slider.rs | 10 | ||||
-rw-r--r-- | style/src/theme.rs | 56 |
12 files changed, 91 insertions, 99 deletions
diff --git a/examples/component/src/main.rs b/examples/component/src/main.rs index d863c58f..ec7c658f 100644 --- a/examples/component/src/main.rs +++ b/examples/component/src/main.rs @@ -96,7 +96,6 @@ mod numeric_input { where Renderer: 'a + text::Renderer, Renderer::Theme: button::StyleSheet, - <Renderer::Theme as button::StyleSheet>::Variant: Default + Copy, { type Event = Event; @@ -175,7 +174,6 @@ mod numeric_input { Message: 'a, Renderer: text::Renderer + 'a, Renderer::Theme: button::StyleSheet, - <Renderer::Theme as button::StyleSheet>::Variant: Default + Copy, { fn from(numeric_input: NumericInput<'a, Message>) -> Self { component::view(numeric_input) diff --git a/examples/pure/component/src/main.rs b/examples/pure/component/src/main.rs index 2f98f768..2c065231 100644 --- a/examples/pure/component/src/main.rs +++ b/examples/pure/component/src/main.rs @@ -90,8 +90,6 @@ mod numeric_input { where Renderer: text::Renderer + 'static, Renderer::Theme: widget::button::StyleSheet, - <Renderer::Theme as widget::button::StyleSheet>::Variant: - Default + Copy, { type State = (); type Event = Event; @@ -163,8 +161,6 @@ mod numeric_input { Message: 'a, Renderer: 'static + text::Renderer, Renderer::Theme: widget::button::StyleSheet, - <Renderer::Theme as widget::button::StyleSheet>::Variant: - Default + Copy, { fn from(numeric_input: NumericInput<Message>) -> Self { pure::component(numeric_input) diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index 09c59cbe..d4e88424 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -12,7 +12,7 @@ use crate::{ Rectangle, Shell, Vector, Widget, }; -pub use iced_style::button::{Style, StyleSheet}; +pub use iced_style::button::{Appearance, StyleSheet}; /// A generic widget that produces a message when pressed. /// @@ -66,7 +66,7 @@ where width: Length, height: Length, padding: Padding, - variant: <Renderer::Theme as StyleSheet>::Variant, + style: <Renderer::Theme as StyleSheet>::Style, } impl<'a, Message, Renderer> Button<'a, Message, Renderer> @@ -74,7 +74,6 @@ where Message: Clone, Renderer: crate::Renderer, Renderer::Theme: StyleSheet, - <Renderer::Theme as StyleSheet>::Variant: Default, { /// Creates a new [`Button`] with some local [`State`] and the given /// content. @@ -89,7 +88,7 @@ where width: Length::Shrink, height: Length::Shrink, padding: Padding::new(5), - variant: <Renderer::Theme as StyleSheet>::Variant::default(), + style: Default::default(), } } @@ -118,12 +117,12 @@ where self } - /// Sets the style variant of this [`Button`]. + /// Sets the style of this [`Button`]. pub fn style( mut self, - variant: <Renderer::Theme as StyleSheet>::Variant, + style: <Renderer::Theme as StyleSheet>::Style, ) -> Self { - self.variant = variant; + self.style = style; self } } @@ -196,29 +195,34 @@ pub fn update<'a, Message: Clone>( } /// Draws a [`Button`]. -pub fn draw<'a, Renderer: crate::Renderer, Variant>( +pub fn draw<'a, Renderer: crate::Renderer>( renderer: &mut Renderer, bounds: Rectangle, cursor_position: Point, is_enabled: bool, - style_sheet: &dyn StyleSheet<Variant = Variant>, - variation: Variant, + style_sheet: &dyn StyleSheet< + Style = <Renderer::Theme as StyleSheet>::Style, + >, + style: <Renderer::Theme as StyleSheet>::Style, state: impl FnOnce() -> &'a State, -) -> Style { +) -> Appearance +where + Renderer::Theme: StyleSheet, +{ let is_mouse_over = bounds.contains(cursor_position); let styling = if !is_enabled { - style_sheet.disabled(variation) + style_sheet.disabled(style) } else if is_mouse_over { let state = state(); if state.is_pressed { - style_sheet.pressed(variation) + style_sheet.pressed(style) } else { - style_sheet.hovered(variation) + style_sheet.hovered(style) } } else { - style_sheet.active(variation) + style_sheet.active(style) }; if styling.background.is_some() || styling.border_width > 0.0 { @@ -295,7 +299,6 @@ where Message: Clone, Renderer: crate::Renderer, Renderer::Theme: StyleSheet, - <Renderer::Theme as StyleSheet>::Variant: Copy, { fn width(&self) -> Length { self.width @@ -378,7 +381,7 @@ where cursor_position, self.on_press.is_some(), theme, - self.variant, + self.style, || &self.state, ); @@ -410,7 +413,6 @@ where Message: 'a + Clone, Renderer: 'a + crate::Renderer, Renderer::Theme: StyleSheet, - <Renderer::Theme as StyleSheet>::Variant: Copy, { fn from( button: Button<'a, Message, Renderer>, diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index f42bca28..7042e0ad 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -13,7 +13,7 @@ use crate::{ use std::ops::RangeInclusive; -pub use iced_style::slider::{Handle, HandleShape, Style, StyleSheet}; +pub use iced_style::slider::{Appearance, Handle, HandleShape, StyleSheet}; /// An horizontal bar and a handle that selects a single value from a range of /// values. @@ -53,7 +53,7 @@ where on_release: Option<Message>, width: Length, height: u16, - variant: <Renderer::Theme as StyleSheet>::Variant, + style: <Renderer::Theme as StyleSheet>::Style, } impl<'a, T, Message, Renderer> Slider<'a, T, Message, Renderer> @@ -105,7 +105,7 @@ where on_release: None, width: Length::Fill, height: Self::DEFAULT_HEIGHT, - variant: Default::default(), + style: Default::default(), } } @@ -135,9 +135,9 @@ where /// Sets the style of the [`Slider`]. pub fn style( mut self, - variant: impl Into<<Renderer::Theme as StyleSheet>::Variant>, + style: impl Into<<Renderer::Theme as StyleSheet>::Style>, ) -> Self { - self.variant = variant.into(); + self.style = style.into(); self } @@ -243,8 +243,8 @@ pub fn draw<T, R>( state: &State, value: T, range: &RangeInclusive<T>, - style_sheet: &dyn StyleSheet<Variant = <R::Theme as StyleSheet>::Variant>, - variant: <R::Theme as StyleSheet>::Variant, + style_sheet: &dyn StyleSheet<Style = <R::Theme as StyleSheet>::Style>, + style: <R::Theme as StyleSheet>::Style, ) where T: Into<f64> + Copy, R: crate::Renderer, @@ -254,11 +254,11 @@ pub fn draw<T, R>( let is_mouse_over = bounds.contains(cursor_position); let style = if state.is_dragging { - style_sheet.dragging(variant) + style_sheet.dragging(style) } else if is_mouse_over { - style_sheet.hovered(variant) + style_sheet.hovered(style) } else { - style_sheet.active(variant) + style_sheet.active(style) }; let rail_y = bounds.y + (bounds.height / 2.0).round(); @@ -434,7 +434,7 @@ where self.value, &self.range, theme, - self.variant, + self.style, ) } diff --git a/pure/src/helpers.rs b/pure/src/helpers.rs index 71ae7635..d8741b09 100644 --- a/pure/src/helpers.rs +++ b/pure/src/helpers.rs @@ -54,7 +54,6 @@ pub fn button<'a, Message, Renderer>( where Renderer: iced_native::Renderer, Renderer::Theme: widget::button::StyleSheet, - <Renderer::Theme as widget::button::StyleSheet>::Variant: Default, { widget::Button::new(content) } diff --git a/pure/src/widget/button.rs b/pure/src/widget/button.rs index 45f4a6aa..dd7688e2 100644 --- a/pure/src/widget/button.rs +++ b/pure/src/widget/button.rs @@ -12,7 +12,7 @@ use iced_native::{ Clipboard, Layout, Length, Padding, Point, Rectangle, Shell, }; -pub use iced_style::button::{Style, StyleSheet}; +pub use iced_style::button::{Appearance, StyleSheet}; use button::State; @@ -60,14 +60,13 @@ where width: Length, height: Length, padding: Padding, - variant: <Renderer::Theme as StyleSheet>::Variant, + style: <Renderer::Theme as StyleSheet>::Style, } impl<'a, Message, Renderer> Button<'a, Message, Renderer> where Renderer: iced_native::Renderer, Renderer::Theme: StyleSheet, - <Renderer::Theme as StyleSheet>::Variant: Default, { /// Creates a new [`Button`] with the given content. pub fn new(content: impl Into<Element<'a, Message, Renderer>>) -> Self { @@ -77,7 +76,7 @@ where width: Length::Shrink, height: Length::Shrink, padding: Padding::new(5), - variant: <Renderer::Theme as StyleSheet>::Variant::default(), + style: <Renderer::Theme as StyleSheet>::Style::default(), } } @@ -110,9 +109,9 @@ where /// Sets the style variant of this [`Button`]. pub fn style( mut self, - variant: <Renderer::Theme as StyleSheet>::Variant, + style: <Renderer::Theme as StyleSheet>::Style, ) -> Self { - self.variant = variant; + self.style = style; self } } @@ -123,7 +122,6 @@ where Message: 'a + Clone, Renderer: 'a + iced_native::Renderer, Renderer::Theme: StyleSheet, - <Renderer::Theme as StyleSheet>::Variant: Copy, { fn tag(&self) -> tree::Tag { tree::Tag::of::<State>() @@ -217,7 +215,7 @@ where cursor_position, self.on_press.is_some(), theme, - self.variant, + self.style, || tree.state.downcast_ref::<State>(), ); @@ -269,7 +267,6 @@ where Message: Clone + 'a, Renderer: iced_native::Renderer + 'a, Renderer::Theme: StyleSheet, - <Renderer::Theme as StyleSheet>::Variant: Copy, { fn into(self) -> Element<'a, Message, Renderer> { Element::new(self) diff --git a/pure/src/widget/slider.rs b/pure/src/widget/slider.rs index a6deda41..9bc32f08 100644 --- a/pure/src/widget/slider.rs +++ b/pure/src/widget/slider.rs @@ -11,7 +11,7 @@ use iced_native::{Clipboard, Layout, Length, Point, Rectangle, Shell, Size}; use std::ops::RangeInclusive; -pub use iced_style::slider::{Handle, HandleShape, Style, StyleSheet}; +pub use iced_style::slider::{Appearance, Handle, HandleShape, StyleSheet}; /// An horizontal bar and a handle that selects a single value from a range of /// values. @@ -49,7 +49,7 @@ where on_release: Option<Message>, width: Length, height: u16, - variant: <Renderer::Theme as StyleSheet>::Variant, + style: <Renderer::Theme as StyleSheet>::Style, } impl<'a, T, Message, Renderer> Slider<'a, T, Message, Renderer> @@ -94,7 +94,7 @@ where on_release: None, width: Length::Fill, height: Self::DEFAULT_HEIGHT, - variant: Default::default(), + style: Default::default(), } } @@ -124,9 +124,9 @@ where /// Sets the style of the [`Slider`]. pub fn style( mut self, - variant: impl Into<<Renderer::Theme as StyleSheet>::Variant>, + style: impl Into<<Renderer::Theme as StyleSheet>::Style>, ) -> Self { - self.variant = variant.into(); + self.style = style.into(); self } @@ -216,7 +216,7 @@ where self.value, &self.range, theme, - self.variant, + self.style, ) } diff --git a/src/pure/widget.rs b/src/pure/widget.rs index 1c0a32a6..e91cf56a 100644 --- a/src/pure/widget.rs +++ b/src/pure/widget.rs @@ -14,7 +14,7 @@ pub type Text<Theme = crate::Theme> = pub mod button { //! Allow your users to perform actions by pressing a button. - pub use iced_pure::widget::button::{Style, StyleSheet}; + pub use iced_pure::widget::button::{Appearance, StyleSheet}; /// A widget that produces a message when clicked. pub type Button<'a, Message, Theme = crate::Theme> = diff --git a/src/widget.rs b/src/widget.rs index e40ed108..51a498b0 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -30,7 +30,7 @@ pub mod button { //! Allow your users to perform actions by pressing a button. //! //! A [`Button`] has some local [`State`]. - pub use iced_native::widget::button::{State, Style, StyleSheet}; + pub use iced_native::widget::button::{Appearance, State, StyleSheet}; /// A widget that produces a message when clicked. pub type Button<'a, Message, Theme = crate::Theme> = 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 |