From 29326215ccf13e1d1e25bf3bf5ada007856bff69 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 5 Mar 2024 03:48:08 +0100 Subject: Simplify theming for `Container` widget --- examples/gradient/src/main.rs | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'examples/gradient/src') 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), -- cgit From 34e7c6593a9e0f56cee5db18b7258717cf6bc11b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 6 Mar 2024 20:30:58 +0100 Subject: Use `Style` struct pattern instead of trait for all widgets --- examples/gradient/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/gradient/src') diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index 1a264063..3334bde9 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -84,7 +84,7 @@ impl Sandbox for Gradient { }; let gradient_box = themer( - move |_| appearance, + appearance, container(horizontal_space()) .width(Length::Fill) .height(Length::Fill), -- cgit From 7c4bf70023a8092faad9630c2c87fbf41bd6ab76 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 6 Mar 2024 21:27:03 +0100 Subject: Simplify theming for `Application` --- examples/gradient/src/main.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'examples/gradient/src') diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index 3334bde9..6d3ff125 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -1,11 +1,11 @@ use iced::application; -use iced::theme::{self, Theme}; use iced::widget::{ checkbox, column, container, horizontal_space, row, slider, text, themer, }; use iced::{gradient, window}; use iced::{ Alignment, Background, Color, Element, Length, Radians, Sandbox, Settings, + Theme, }; pub fn main() -> iced::Result { @@ -115,16 +115,14 @@ impl Sandbox for Gradient { .into() } - fn style(&self) -> theme::Application { + fn style(&self, theme: &Theme) -> application::Appearance { if self.transparent { - theme::Application::custom(|theme: &Theme| { - application::Appearance { - background_color: Color::TRANSPARENT, - text_color: theme.palette().text, - } - }) + application::Appearance { + background_color: Color::TRANSPARENT, + text_color: theme.palette().text, + } } else { - theme::Application::Default + application::default(theme) } } } -- cgit From 7ece5eea509f3595432babfc7729701f2e063b21 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 7 Mar 2024 21:02:17 +0100 Subject: Implement additional helpers for `Border` and `container::Appearance` --- examples/gradient/src/main.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'examples/gradient/src') diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index 6d3ff125..4a8b2fa5 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -4,8 +4,7 @@ use iced::widget::{ }; use iced::{gradient, window}; use iced::{ - Alignment, Background, Color, Element, Length, Radians, Sandbox, Settings, - Theme, + Alignment, Color, Element, Length, Radians, Sandbox, Settings, Theme, }; pub fn main() -> iced::Result { @@ -71,20 +70,12 @@ impl Sandbox for Gradient { transparent, } = *self; - 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 = gradient::Linear::new(angle) + .add_stop(0.0, start) + .add_stop(1.0, end); let gradient_box = themer( - appearance, + gradient, container(horizontal_space()) .width(Length::Fill) .height(Length::Fill), -- cgit