From cf0230072c01ea9523f4d98a3656f5c975b3f347 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 26 May 2022 23:07:34 +0200 Subject: Rename `Variant` to `Style` and `Style` to `Appearance` --- examples/component/src/main.rs | 2 -- examples/pure/component/src/main.rs | 4 --- native/src/widget/button.rs | 38 +++++++++++++------------ native/src/widget/slider.rs | 22 +++++++-------- pure/src/helpers.rs | 1 - pure/src/widget/button.rs | 15 ++++------ pure/src/widget/slider.rs | 12 ++++---- src/pure/widget.rs | 2 +- src/widget.rs | 2 +- style/src/button.rs | 26 ++++++++--------- style/src/slider.rs | 10 +++---- 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, - ::Variant: Default + Copy, { type Event = Event; @@ -175,7 +174,6 @@ mod numeric_input { Message: 'a, Renderer: text::Renderer + 'a, Renderer::Theme: 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, - ::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, - ::Variant: - Default + Copy, { fn from(numeric_input: NumericInput) -> 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: ::Variant, + style: ::Style, } impl<'a, Message, Renderer> Button<'a, Message, Renderer> @@ -74,7 +74,6 @@ where Message: Clone, Renderer: crate::Renderer, Renderer::Theme: 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: ::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: ::Variant, + style: ::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, - variation: Variant, + style_sheet: &dyn StyleSheet< + Style = ::Style, + >, + style: ::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, - ::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, - ::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, width: Length, height: u16, - variant: ::Variant, + style: ::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<::Variant>, + style: impl Into<::Style>, ) -> Self { - self.variant = variant.into(); + self.style = style.into(); self } @@ -243,8 +243,8 @@ pub fn draw( state: &State, value: T, range: &RangeInclusive, - style_sheet: &dyn StyleSheet::Variant>, - variant: ::Variant, + style_sheet: &dyn StyleSheet