diff options
author | 2021-10-18 16:02:30 +0700 | |
---|---|---|
committer | 2021-10-18 16:02:30 +0700 | |
commit | 3140cdc4babcefc444f1c1d30eb0f5f4ed1df054 (patch) | |
tree | b3ea963a73118d5f0bfd7d875ba776ee51466f9b /examples | |
parent | 95acc1deb89c4e75b513edb0f4d53b83c7f75b30 (diff) | |
download | iced-3140cdc4babcefc444f1c1d30eb0f5f4ed1df054.tar.gz iced-3140cdc4babcefc444f1c1d30eb0f5f4ed1df054.tar.bz2 iced-3140cdc4babcefc444f1c1d30eb0f5f4ed1df054.zip |
Wire up styling to `Button` in `iced_native`
Diffstat (limited to 'examples')
-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 | 40 | ||||
-rw-r--r-- | examples/tour/src/main.rs | 4 |
7 files changed, 36 insertions, 40 deletions
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index ee425f44..3e94bd44 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 844b604d..4126485d 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 c99240a1..c9930158 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 dc8a4de7..e6743620 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 d8254dd9..38ab0411 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); + .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, } } } diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 11f23fd4..1734772d 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() } @@ -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), diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index b5af48c7..176d275c 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), ); } |