Reintroduce Box for style_sheet in Button
This commit is contained in:
parent
661cb5736e
commit
d36ce33a95
10 changed files with 42 additions and 30 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue