summaryrefslogtreecommitdiffstats
path: root/examples/gradient
diff options
context:
space:
mode:
Diffstat (limited to 'examples/gradient')
-rw-r--r--examples/gradient/src/main.rs41
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),