Wire up styling to Button in iced_native
This commit is contained in:
parent
95acc1deb8
commit
3140cdc4ba
12 changed files with 55 additions and 96 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);
|
||||
.style(self.theme.into());
|
||||
|
||||
let slider = Slider::new(
|
||||
&mut self.slider,
|
||||
|
|
@ -203,11 +203,11 @@ mod style {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Theme> for Box<dyn button::StyleSheet> {
|
||||
impl From<Theme> for &'static dyn button::StyleSheet {
|
||||
fn from(theme: Theme) -> Self {
|
||||
match theme {
|
||||
Theme::Light => light::Button.into(),
|
||||
Theme::Dark => dark::Button.into(),
|
||||
Theme::Light => &light::Button,
|
||||
Theme::Dark => &dark::Button,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
@ -363,8 +363,10 @@ impl Controls {
|
|||
let filter_button = |state, label, filter, current_filter| {
|
||||
let label = Text::new(label).size(16);
|
||||
let button =
|
||||
Button::new(state, label).style(style::Button::Filter {
|
||||
selected: filter == current_filter,
|
||||
Button::new(state, label).style(if filter == current_filter {
|
||||
&style::Button::FilterSelected
|
||||
} else {
|
||||
&style::Button::FilterActive
|
||||
});
|
||||
|
||||
button.on_press(Message::FilterChanged(filter)).padding(8)
|
||||
|
|
@ -602,7 +604,8 @@ mod style {
|
|||
use iced::{button, Background, Color, Vector};
|
||||
|
||||
pub enum Button {
|
||||
Filter { selected: bool },
|
||||
FilterActive,
|
||||
FilterSelected,
|
||||
Icon,
|
||||
Destructive,
|
||||
}
|
||||
|
|
@ -610,20 +613,15 @@ mod style {
|
|||
impl button::StyleSheet for Button {
|
||||
fn active(&self) -> button::Style {
|
||||
match self {
|
||||
Button::Filter { selected } => {
|
||||
if *selected {
|
||||
button::Style {
|
||||
background: Some(Background::Color(
|
||||
Color::from_rgb(0.2, 0.2, 0.7),
|
||||
)),
|
||||
border_radius: 10.0,
|
||||
text_color: Color::WHITE,
|
||||
..button::Style::default()
|
||||
}
|
||||
} else {
|
||||
button::Style::default()
|
||||
}
|
||||
}
|
||||
Button::FilterActive => button::Style::default(),
|
||||
Button::FilterSelected => button::Style {
|
||||
background: Some(Background::Color(Color::from_rgb(
|
||||
0.2, 0.2, 0.7,
|
||||
))),
|
||||
border_radius: 10.0,
|
||||
text_color: Color::WHITE,
|
||||
..button::Style::default()
|
||||
},
|
||||
Button::Icon => button::Style {
|
||||
text_color: Color::from_rgb(0.5, 0.5, 0.5),
|
||||
..button::Style::default()
|
||||
|
|
@ -646,9 +644,7 @@ mod style {
|
|||
button::Style {
|
||||
text_color: match self {
|
||||
Button::Icon => Color::from_rgb(0.2, 0.2, 0.7),
|
||||
Button::Filter { selected } if !selected => {
|
||||
Color::from_rgb(0.2, 0.2, 0.7)
|
||||
}
|
||||
Button::FilterActive => Color::from_rgb(0.2, 0.2, 0.7),
|
||||
_ => active.text_color,
|
||||
},
|
||||
shadow_offset: active.shadow_offset + Vector::new(0.0, 1.0),
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue