diff options
author | 2024-03-19 22:09:36 +0900 | |
---|---|---|
committer | 2024-03-19 22:09:36 +0900 | |
commit | f3a1c785b2743e9c48c3d28df0c6772ce579d7c8 (patch) | |
tree | 1b39799f45878d89b4f9e2f9bea8fa8a7ed07150 /examples/gradient/src | |
parent | c9453cd55d84f0dd2ad0050208863d036c98843f (diff) | |
parent | 8ce16aba6204cb5c02a709cdf79c309f7b7e0196 (diff) | |
download | iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.tar.gz iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.tar.bz2 iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.zip |
Merge branch 'iced-rs:master' into viewer_content_fit
Diffstat (limited to 'examples/gradient/src')
-rw-r--r-- | examples/gradient/src/main.rs | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index 8ed4c830..22c21cdd 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -1,22 +1,17 @@ -use iced::application; +use iced::gradient; +use iced::program; use iced::widget::{ checkbox, column, container, horizontal_space, row, slider, text, }; -use iced::{gradient, window}; -use iced::{ - Alignment, Color, Element, Length, Radians, Sandbox, Settings, Theme, -}; +use iced::{Alignment, Color, Element, Length, Radians, Theme}; pub fn main() -> iced::Result { tracing_subscriber::fmt::init(); - Gradient::run(Settings { - window: window::Settings { - transparent: true, - ..Default::default() - }, - ..Default::default() - }) + iced::program("Gradient - Iced", Gradient::update, Gradient::view) + .style(Gradient::style) + .transparent(true) + .run() } #[derive(Debug, Clone, Copy)] @@ -35,9 +30,7 @@ enum Message { TransparentToggled(bool), } -impl Sandbox for Gradient { - type Message = Message; - +impl Gradient { fn new() -> Self { Self { start: Color::WHITE, @@ -47,10 +40,6 @@ impl Sandbox for Gradient { } } - fn title(&self) -> String { - String::from("Gradient") - } - fn update(&mut self, message: Message) { match message { Message::StartChanged(color) => self.start = color, @@ -106,18 +95,26 @@ impl Sandbox for Gradient { .into() } - fn style(&self, theme: &Theme) -> application::Appearance { + fn style(&self, theme: &Theme) -> program::Appearance { + use program::DefaultStyle; + if self.transparent { - application::Appearance { + program::Appearance { background_color: Color::TRANSPARENT, text_color: theme.palette().text, } } else { - application::default(theme) + Theme::default_style(theme) } } } +impl Default for Gradient { + fn default() -> Self { + Self::new() + } +} + fn color_picker(label: &str, color: Color) -> Element<'_, Color> { row![ text(label).width(64), |