summaryrefslogtreecommitdiffstats
path: root/examples/gradient
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-05 03:48:08 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-05 03:48:08 +0100
commit29326215ccf13e1d1e25bf3bf5ada007856bff69 (patch)
tree9a286433affc511da2d8926d0f6862b664184b56 /examples/gradient
parent1f0a0c235a7729cf2d5716efeecb9c4dc972fdfa (diff)
downloadiced-29326215ccf13e1d1e25bf3bf5ada007856bff69.tar.gz
iced-29326215ccf13e1d1e25bf3bf5ada007856bff69.tar.bz2
iced-29326215ccf13e1d1e25bf3bf5ada007856bff69.zip
Simplify theming for `Container` widget
Diffstat (limited to 'examples/gradient')
-rw-r--r--examples/gradient/src/main.rs34
1 files changed, 19 insertions, 15 deletions
diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs
index a021c164..1a264063 100644
--- a/examples/gradient/src/main.rs
+++ b/examples/gradient/src/main.rs
@@ -1,7 +1,7 @@
use iced::application;
use iced::theme::{self, Theme};
use iced::widget::{
- checkbox, column, container, horizontal_space, row, slider, text,
+ checkbox, column, container, horizontal_space, row, slider, text, themer,
};
use iced::{gradient, window};
use iced::{
@@ -71,20 +71,24 @@ impl Sandbox for Gradient {
transparent,
} = *self;
- let gradient_box = container(horizontal_space())
- .width(Length::Fill)
- .height(Length::Fill)
- .style(move |_: &_| {
- let gradient = gradient::Linear::new(angle)
- .add_stop(0.0, start)
- .add_stop(1.0, end)
- .into();
-
- container::Appearance {
- background: Some(Background::Gradient(gradient)),
- ..Default::default()
- }
- });
+ let appearance = {
+ let gradient = gradient::Linear::new(angle)
+ .add_stop(0.0, start)
+ .add_stop(1.0, end)
+ .into();
+
+ container::Appearance {
+ background: Some(Background::Gradient(gradient)),
+ ..Default::default()
+ }
+ };
+
+ let gradient_box = themer(
+ move |_| appearance,
+ container(horizontal_space())
+ .width(Length::Fill)
+ .height(Length::Fill),
+ );
let angle_picker = row![
text("Angle").width(64),