Implement custom helper for theme::Button

This commit is contained in:
Héctor Ramón Jiménez 2023-05-19 03:43:11 +02:00
parent 59663d2e45
commit 96aa0379d5
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
2 changed files with 15 additions and 8 deletions

View file

@ -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)),
);
}

View file

@ -139,6 +139,15 @@ pub enum Button {
Custom(Box<dyn button::StyleSheet<Style = Theme>>),
}
impl Button {
/// Creates a custom [`Button`] style variant.
pub fn custom(
style_sheet: impl button::StyleSheet<Style = Theme> + 'static,
) -> Self {
Self::Custom(Box::new(style_sheet))
}
}
impl button::StyleSheet for Theme {
type Style = Button;