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/sandbox.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/sandbox.rs') diff --git a/src/sandbox.rs b/src/sandbox.rs index e7e97920..16819569 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -1,5 +1,5 @@ use crate::{ - Application, Color, Command, Element, Error, Settings, Subscription, + Application, Color, Command, Element, Error, Settings, Subscription, Theme, }; /// A sandboxed [`Application`]. @@ -111,6 +111,16 @@ pub trait Sandbox { /// These widgets can produce __messages__ based on user interaction. fn view(&mut self) -> 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`]. @@ -159,6 +169,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()) @@ -174,14 +185,18 @@ where Command::none() } - fn subscription(&self) -> Subscription { - Subscription::none() - } - fn view(&mut self) -> 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/sandbox.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'src/sandbox.rs') diff --git a/src/sandbox.rs b/src/sandbox.rs index 16819569..f03562fb 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -1,5 +1,5 @@ use crate::{ - Application, Color, Command, Element, Error, Settings, Subscription, Theme, + Application, Command, Element, Error, Settings, Subscription, Theme, }; /// A sandboxed [`Application`]. @@ -121,13 +121,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 @@ -197,10 +190,6 @@ where Subscription::none() } - fn background_color(&self) -> Color { - T::background_color(self) - } - fn scale_factor(&self) -> f64 { T::scale_factor(self) } -- cgit From 3514bd1535bc8421c746d981ca488883486de97f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Jul 2022 20:13:14 +0200 Subject: Add `theme::Application` styling support to `Sandbox` --- src/sandbox.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/sandbox.rs') diff --git a/src/sandbox.rs b/src/sandbox.rs index f03562fb..3ca3fe8f 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -1,6 +1,5 @@ -use crate::{ - Application, Command, Element, Error, Settings, Subscription, Theme, -}; +use crate::theme::{self, Theme}; +use crate::{Application, Command, Element, Error, Settings, Subscription}; /// A sandboxed [`Application`]. /// @@ -121,6 +120,13 @@ pub trait Sandbox { Theme::default() } + /// Returns the current style variant of [`theme::Application`]. + /// + /// By default, it returns [`theme::Application::default`]. + fn style(&self) -> theme::Application { + theme::Application::default() + } + /// Returns the scale factor of the [`Sandbox`]. /// /// It can be used to dynamically control the size of the UI at runtime @@ -186,6 +192,10 @@ where T::theme(self) } + fn style(&self) -> theme::Application { + T::style(self) + } + fn subscription(&self) -> Subscription { Subscription::none() } -- cgit