From 664251f3f5c7b76f69a97683af1468094bba887f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 May 2022 01:47:55 +0200 Subject: Draft first-class `Theme` support RFC: https://github.com/iced-rs/rfcs/pull/6 --- src/pure/sandbox.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/pure/sandbox.rs') diff --git a/src/pure/sandbox.rs b/src/pure/sandbox.rs index fbd1d7a8..207a32bd 100644 --- a/src/pure/sandbox.rs +++ b/src/pure/sandbox.rs @@ -1,5 +1,5 @@ use crate::pure; -use crate::{Color, Command, Error, Settings, Subscription}; +use crate::{Color, Command, Error, Settings, Subscription, Theme}; /// A pure version of [`Sandbox`]. /// @@ -34,6 +34,16 @@ pub trait Sandbox { /// These widgets can produce __messages__ based on user interaction. fn view(&self) -> pure::Element<'_, Self::Message>; + /// Returns the current [`Theme`] of the [`Sandbox`]. + /// + /// If you want to use your own custom theme type, you will have to use an + /// [`Application`]. + /// + /// By default, it returns [`Theme::default`]. + fn theme(&self) -> Theme { + Theme::default() + } + /// Returns the background color of the [`Sandbox`]. /// /// By default, it returns [`Color::WHITE`]. @@ -82,6 +92,7 @@ where type Executor = iced_futures::backend::null::Executor; type Flags = (); type Message = T::Message; + type Theme = Theme; fn new(_flags: ()) -> (Self, Command) { (T::new(), Command::none()) @@ -97,14 +108,18 @@ where Command::none() } - fn subscription(&self) -> Subscription { - Subscription::none() - } - fn view(&self) -> pure::Element<'_, T::Message> { T::view(self) } + fn theme(&self) -> Self::Theme { + T::theme(self) + } + + fn subscription(&self) -> Subscription { + Subscription::none() + } + fn background_color(&self) -> Color { T::background_color(self) } -- cgit From 03eda9b162012c503ead649e5ccb95b7ef1d10ed Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 25 May 2022 05:01:18 +0200 Subject: Let a `Theme` control the background color of an application ... and remove `Application::background_color` --- src/pure/sandbox.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'src/pure/sandbox.rs') diff --git a/src/pure/sandbox.rs b/src/pure/sandbox.rs index 207a32bd..a58cace7 100644 --- a/src/pure/sandbox.rs +++ b/src/pure/sandbox.rs @@ -1,5 +1,5 @@ use crate::pure; -use crate::{Color, Command, Error, Settings, Subscription, Theme}; +use crate::{Command, Error, Settings, Subscription, Theme}; /// A pure version of [`Sandbox`]. /// @@ -44,13 +44,6 @@ pub trait Sandbox { Theme::default() } - /// Returns the background color of the [`Sandbox`]. - /// - /// By default, it returns [`Color::WHITE`]. - fn background_color(&self) -> Color { - Color::WHITE - } - /// Returns the scale factor of the [`Sandbox`]. /// /// It can be used to dynamically control the size of the UI at runtime @@ -120,10 +113,6 @@ where Subscription::none() } - fn background_color(&self) -> Color { - T::background_color(self) - } - fn scale_factor(&self) -> f64 { T::scale_factor(self) } -- cgit