diff options
author | 2023-05-11 09:12:06 -0700 | |
---|---|---|
committer | 2023-05-11 11:13:44 -0700 | |
commit | 6551a0b2ab6c831dd1d3646ecf55180339275e22 (patch) | |
tree | de1e4a85b3176f94fd006fed190ef035d3202e49 /examples/tour/src/main.rs | |
parent | 669f7cc74b2e7918e86a8197916f503f2d3d9b93 (diff) | |
download | iced-6551a0b2ab6c831dd1d3646ecf55180339275e22.tar.gz iced-6551a0b2ab6c831dd1d3646ecf55180339275e22.tar.bz2 iced-6551a0b2ab6c831dd1d3646ecf55180339275e22.zip |
Added support for gradients as background variants + other optimizations.
Diffstat (limited to '')
-rw-r--r-- | examples/tour/src/main.rs | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 9c38ad0e..630b6359 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -1,11 +1,15 @@ -use iced::alignment; use iced::theme; +use iced::theme::Palette; use iced::widget::{ checkbox, column, container, horizontal_space, image, radio, row, scrollable, slider, text, text_input, toggler, vertical_space, }; use iced::widget::{Button, Column, Container, Slider}; -use iced::{Color, Element, Font, Length, Renderer, Sandbox, Settings}; +use iced::{alignment, widget, Theme}; +use iced::{ + Color, Degrees, Element, Font, Gradient, Length, Radians, Renderer, + Sandbox, Settings, +}; pub fn main() -> iced::Result { env_logger::init(); @@ -53,9 +57,11 @@ impl Sandbox for Tour { if steps.has_previous() { controls = controls.push( - button("Back") - .on_press(Message::BackPressed) - .style(theme::Button::Secondary), + button("Back").on_press(Message::BackPressed).style( + theme::Button::Custom(Box::new( + CustomButtonStyle::Secondary, + )), + ), ); } @@ -63,9 +69,9 @@ impl Sandbox for Tour { if steps.can_continue() { controls = controls.push( - button("Next") - .on_press(Message::NextPressed) - .style(theme::Button::Primary), + button("Next").on_press(Message::NextPressed).style( + theme::Button::Custom(Box::new(CustomButtonStyle::Primary)), + ), ); } @@ -716,3 +722,39 @@ pub enum Layout { Row, Column, } + +enum CustomButtonStyle { + Primary, + Secondary, +} + +impl widget::button::StyleSheet for CustomButtonStyle { + type Style = Theme; + + fn active(&self, _style: &Self::Style) -> widget::button::Appearance { + match self { + CustomButtonStyle::Primary => widget::button::Appearance { + background: Gradient::linear(Degrees(270.0)) + .add_stop(0.0, Palette::LIGHT.primary) + .add_stop(1.0, Color::from_rgb8(54, 80, 168)) + .build() + .into(), + text_color: Color::WHITE, + border_radius: 5.0, + ..Default::default() + }, + CustomButtonStyle::Secondary => widget::button::Appearance { + background: Gradient::linear(Radians( + 3.0 * std::f32::consts::PI / 2.0, + )) + .add_stop(0.0, Color::from_rgb8(194, 194, 194)) + .add_stop(1.0, Color::from_rgb8(126, 126, 126)) + .build() + .into(), + text_color: Color::WHITE, + border_radius: 5.0, + ..Default::default() + }, + } + } +} |