From 98621aa344a7a0e1b23f320d21a4687af559998e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 12 Mar 2024 16:52:53 +0100 Subject: [PATCH] Remove `themer` use from `gradient` example :tada: --- examples/gradient/src/main.rs | 20 ++++++++++---------- widget/src/container.rs | 24 +++++++++++++++++++++--- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index 4a8b2fa54e..8ed4c830cc 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -1,6 +1,6 @@ use iced::application; use iced::widget::{ - checkbox, column, container, horizontal_space, row, slider, text, themer, + checkbox, column, container, horizontal_space, row, slider, text, }; use iced::{gradient, window}; use iced::{ @@ -70,16 +70,16 @@ impl Sandbox for Gradient { transparent, } = *self; - let gradient = gradient::Linear::new(angle) - .add_stop(0.0, start) - .add_stop(1.0, end); + let gradient_box = container(horizontal_space()) + .style(move |_theme, _status| { + let gradient = gradient::Linear::new(angle) + .add_stop(0.0, start) + .add_stop(1.0, end); - let gradient_box = themer( - gradient, - container(horizontal_space()) - .width(Length::Fill) - .height(Length::Fill), - ); + gradient.into() + }) + .width(Length::Fill) + .height(Length::Fill); let angle_picker = row![ text("Angle").width(64), diff --git a/widget/src/container.rs b/widget/src/container.rs index f51ff8789d..7c133588ed 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -539,6 +539,24 @@ impl Appearance { } } +impl From for Appearance { + fn from(color: Color) -> Self { + Self::default().with_background(color) + } +} + +impl From for Appearance { + fn from(gradient: Gradient) -> Self { + Self::default().with_background(gradient) + } +} + +impl From for Appearance { + fn from(gradient: gradient::Linear) -> Self { + Self::default().with_background(gradient) + } +} + /// The possible status of a [`Container`]. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Status { @@ -571,19 +589,19 @@ impl DefaultStyle for Appearance { impl DefaultStyle for Color { fn default_style(&self, _status: Status) -> Appearance { - Appearance::default().with_background(*self) + Appearance::from(*self) } } impl DefaultStyle for Gradient { fn default_style(&self, _status: Status) -> Appearance { - Appearance::default().with_background(*self) + Appearance::from(*self) } } impl DefaultStyle for gradient::Linear { fn default_style(&self, _status: Status) -> Appearance { - Appearance::default().with_background(*self) + Appearance::from(*self) } }