diff options
author | 2019-10-08 03:13:41 +0200 | |
---|---|---|
committer | 2019-10-08 03:13:41 +0200 | |
commit | 10e10e5e06841574425d2633f1c2916733f7b4ff (patch) | |
tree | 0407a0136973a201fe44bfc1a94268544a2f8eb5 /examples | |
parent | a0234d5bcea5b25f575af01d3a8e0296b2d0395c (diff) | |
download | iced-10e10e5e06841574425d2633f1c2916733f7b4ff.tar.gz iced-10e10e5e06841574425d2633f1c2916733f7b4ff.tar.bz2 iced-10e10e5e06841574425d2633f1c2916733f7b4ff.zip |
Make `iced_core::Button` customizable
Now it supports:
- Any kind of content
- Custom border radius
- Custom background
Diffstat (limited to 'examples')
-rw-r--r-- | examples/tour.rs | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/examples/tour.rs b/examples/tour.rs index 5f24eb87..96590c0e 100644 --- a/examples/tour.rs +++ b/examples/tour.rs @@ -1,7 +1,7 @@ use iced::{ - button, slider, text::HorizontalAlignment, Align, Button, Checkbox, Color, - Column, Element, Image, Justify, Length, Radio, Row, Slider, Text, - UserInterface, + button, slider, text::HorizontalAlignment, Align, Background, Button, + Checkbox, Color, Column, Element, Image, Justify, Length, Radio, Row, + Slider, Text, UserInterface, }; pub fn main() { @@ -59,9 +59,8 @@ impl UserInterface for Tour { if steps.has_previous() { controls = controls.push( - Button::new(back_button, "Back") - .on_press(Message::BackPressed) - .class(button::Class::Secondary), + secondary_button(back_button, "Back") + .on_press(Message::BackPressed), ); } @@ -69,7 +68,8 @@ impl UserInterface for Tour { if steps.can_continue() { controls = controls.push( - Button::new(next_button, "Next").on_press(Message::NextPressed), + primary_button(next_button, "Next") + .on_press(Message::NextPressed), ); } @@ -546,6 +546,44 @@ impl<'a> Step { } } +fn button<'a, Message>( + state: &'a mut button::State, + label: &str, +) -> Button<'a, Message> { + Button::new( + state, + Text::new(label) + .color(Color::WHITE) + .horizontal_alignment(HorizontalAlignment::Center), + ) + .padding(10) + .border_radius(10) +} + +fn primary_button<'a, Message>( + state: &'a mut button::State, + label: &str, +) -> Button<'a, Message> { + button(state, label).background(Background::Color(Color { + r: 0.3, + g: 0.3, + b: 0.8, + a: 1.0, + })) +} + +fn secondary_button<'a, Message>( + state: &'a mut button::State, + label: &str, +) -> Button<'a, Message> { + button(state, label).background(Background::Color(Color { + r: 0.8, + g: 0.8, + b: 0.8, + a: 1.0, + })) +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Language { Rust, |