From 96aa0379d58ff799493097e3bd0572f9a87da453 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 19 May 2023 03:43:11 +0200 Subject: Implement `custom` helper for `theme::Button` --- examples/tour/src/main.rs | 14 ++++++-------- style/src/theme.rs | 9 +++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index a40f0f33..257a4def 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -57,11 +57,9 @@ impl Sandbox for Tour { if steps.has_previous() { controls = controls.push( - button("Back").on_press(Message::BackPressed).style( - theme::Button::Custom(Box::new( - CustomButtonStyle::Secondary, - )), - ), + button("Back") + .on_press(Message::BackPressed) + .style(theme::Button::custom(CustomButtonStyle::Secondary)), ); } @@ -69,9 +67,9 @@ impl Sandbox for Tour { if steps.can_continue() { controls = controls.push( - button("Next").on_press(Message::NextPressed).style( - theme::Button::Custom(Box::new(CustomButtonStyle::Primary)), - ), + button("Next") + .on_press(Message::NextPressed) + .style(theme::Button::custom(CustomButtonStyle::Primary)), ); } diff --git a/style/src/theme.rs b/style/src/theme.rs index c9835ca3..477bd27b 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -139,6 +139,15 @@ pub enum Button { Custom(Box>), } +impl Button { + /// Creates a custom [`Button`] style variant. + pub fn custom( + style_sheet: impl button::StyleSheet