diff options
-rw-r--r-- | examples/game_of_life/src/main.rs | 6 | ||||
-rw-r--r-- | examples/pane_grid/src/main.rs | 10 | ||||
-rw-r--r-- | examples/pokedex/src/main.rs | 2 | ||||
-rw-r--r-- | examples/stopwatch/src/main.rs | 6 | ||||
-rw-r--r-- | examples/styling/src/main.rs | 8 | ||||
-rw-r--r-- | examples/todos/src/main.rs | 8 | ||||
-rw-r--r-- | examples/tour/src/main.rs | 4 | ||||
-rw-r--r-- | native/src/widget/button.rs | 9 | ||||
-rw-r--r-- | style/src/button.rs | 13 | ||||
-rw-r--r-- | web/src/widget/button.rs | 6 |
10 files changed, 42 insertions, 30 deletions
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 2c027421..3b5bfa5a 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -834,12 +834,12 @@ impl Controls { Text::new(if is_playing { "Pause" } else { "Play" }), ) .on_press(Message::TogglePlayback) - .style(&style::Button), + .style(style::Button), ) .push( Button::new(&mut self.next_button, Text::new("Next")) .on_press(Message::Next) - .style(&style::Button), + .style(style::Button), ); let speed_controls = Row::new() @@ -883,7 +883,7 @@ impl Controls { .push( Button::new(&mut self.clear_button, Text::new("Clear")) .on_press(Message::Clear) - .style(&style::Clear), + .style(style::Clear), ) .into() } diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index 4126485d..844b604d 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -158,7 +158,7 @@ impl Application for Example { let pin_button = Button::new(&mut pane.pin_button, Text::new(text).size(14)) .on_press(Message::TogglePin(id)) - .style(&style::Button::Pin) + .style(style::Button::Pin) .padding(3); let title = Row::with_children(vec![ @@ -316,13 +316,13 @@ impl Content { split_horizontally, "Split horizontally", Message::Split(pane_grid::Axis::Horizontal, pane), - &style::Button::Primary, + style::Button::Primary, )) .push(button( split_vertically, "Split vertically", Message::Split(pane_grid::Axis::Vertical, pane), - &style::Button::Primary, + style::Button::Primary, )); if total_panes > 1 && !is_pinned { @@ -330,7 +330,7 @@ impl Content { close, "Close", Message::Close(pane), - &style::Button::Destructive, + style::Button::Destructive, )); } @@ -364,7 +364,7 @@ impl Controls { ) -> Element<Message> { let mut button = Button::new(&mut self.close, Text::new("Close").size(14)) - .style(&style::Button::Control) + .style(style::Button::Control) .padding(3); if total_panes > 1 && !is_pinned { button = button.on_press(Message::Close(pane)); diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index c9930158..c99240a1 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -243,7 +243,7 @@ impl From<reqwest::Error> for Error { fn button<'a>(state: &'a mut button::State, text: &str) -> Button<'a, Message> { Button::new(state, Text::new(text)) .padding(10) - .style(&style::Button::Primary) + .style(style::Button::Primary) } mod style { diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs index e6743620..dc8a4de7 100644 --- a/examples/stopwatch/src/main.rs +++ b/examples/stopwatch/src/main.rs @@ -112,15 +112,15 @@ impl Application for Stopwatch { let toggle_button = { let (label, color) = match self.state { - State::Idle => ("Start", &style::Button::Primary), - State::Ticking { .. } => ("Stop", &style::Button::Destructive), + State::Idle => ("Start", style::Button::Primary), + State::Ticking { .. } => ("Stop", style::Button::Destructive), }; button(&mut self.toggle, label, color).on_press(Message::Toggle) }; let reset_button = - button(&mut self.reset, "Reset", &style::Button::Secondary) + button(&mut self.reset, "Reset", style::Button::Secondary) .on_press(Message::Reset); let controls = Row::new() diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 5ce54e23..9e31c383 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -82,7 +82,7 @@ impl Sandbox for Styling { let button = Button::new(&mut self.button, Text::new("Submit")) .padding(10) .on_press(Message::ButtonPressed) - .style(self.theme.into()); + .style(self.theme); let slider = Slider::new( &mut self.slider, @@ -203,11 +203,11 @@ mod style { } } - impl From<Theme> for &'static dyn button::StyleSheet { + impl<'a> From<Theme> for Box<dyn button::StyleSheet + 'a> { fn from(theme: Theme) -> Self { match theme { - Theme::Light => &light::Button, - Theme::Dark => &dark::Button, + Theme::Light => light::Button.into(), + Theme::Dark => dark::Button.into(), } } } diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 1734772d..5ad8c208 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -304,7 +304,7 @@ impl Task { Button::new(edit_button, edit_icon()) .on_press(TaskMessage::Edit) .padding(10) - .style(&style::Button::Icon), + .style(style::Button::Icon), ) .into() } @@ -335,7 +335,7 @@ impl Task { ) .on_press(TaskMessage::Delete) .padding(10) - .style(&style::Button::Destructive), + .style(style::Button::Destructive), ) .into() } @@ -364,9 +364,9 @@ impl Controls { let label = Text::new(label).size(16); let button = Button::new(state, label).style(if filter == current_filter { - &style::Button::FilterSelected + style::Button::FilterSelected } else { - &style::Button::FilterActive + style::Button::FilterActive }); button.on_press(Message::FilterChanged(filter)).padding(8) diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 176d275c..b5af48c7 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -64,7 +64,7 @@ impl Sandbox for Tour { controls = controls.push( button(back_button, "Back") .on_press(Message::BackPressed) - .style(&style::Button::Secondary), + .style(style::Button::Secondary), ); } @@ -74,7 +74,7 @@ impl Sandbox for Tour { controls = controls.push( button(next_button, "Next") .on_press(Message::NextPressed) - .style(&style::Button::Primary), + .style(style::Button::Primary), ); } diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index a577fe84..588833a4 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -66,7 +66,7 @@ pub struct Button<'a, Message, Renderer> { min_width: u32, min_height: u32, padding: Padding, - style_sheet: &'a dyn StyleSheet, + style_sheet: Box<dyn StyleSheet + 'a>, } impl<'a, Message, Renderer> Button<'a, Message, Renderer> @@ -131,8 +131,11 @@ where } /// Sets the style of the [`Button`]. - pub fn style(mut self, style_sheet: &'a dyn StyleSheet) -> Self { - self.style_sheet = style_sheet; + pub fn style( + mut self, + style_sheet: impl Into<Box<dyn StyleSheet + 'a>>, + ) -> Self { + self.style_sheet = style_sheet.into(); self } } diff --git a/style/src/button.rs b/style/src/button.rs index 608f344b..ff4f61c3 100644 --- a/style/src/button.rs +++ b/style/src/button.rs @@ -80,8 +80,17 @@ impl StyleSheet for Default { } } -impl std::default::Default for &'static dyn StyleSheet { +impl std::default::Default for Box<dyn StyleSheet> { fn default() -> Self { - &Default + Box::new(Default) + } +} + +impl<'a, T> From<T> for Box<dyn StyleSheet + 'a> +where + T: StyleSheet + 'a, +{ + fn from(style_sheet: T) -> Self { + Box::new(style_sheet) } } diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index 1ae78201..88137607 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -51,7 +51,7 @@ pub struct Button<'a, Message> { #[allow(dead_code)] min_height: u32, padding: Padding, - style: &'a dyn StyleSheet, + style: Box<dyn StyleSheet + 'a>, } impl<'a, Message> Button<'a, Message> { @@ -104,8 +104,8 @@ impl<'a, Message> Button<'a, Message> { } /// Sets the style of the [`Button`]. - pub fn style(mut self, style: &'a dyn StyleSheet) -> Self { - self.style = style; + pub fn style(mut self, style: impl Into<Box<dyn StyleSheet + 'a>>) -> Self { + self.style = style.into(); self } |