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/application.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/pure/application.rs') diff --git a/src/pure/application.rs b/src/pure/application.rs index 5f400bea..77f68c9e 100644 --- a/src/pure/application.rs +++ b/src/pure/application.rs @@ -21,6 +21,9 @@ pub trait Application: Sized { /// The type of __messages__ your [`Application`] will produce. type Message: std::fmt::Debug + Send; + /// The theme of your [`Application`]. + type Theme: Default; + /// The data needed to initialize your [`Application`]. type Flags; @@ -51,6 +54,16 @@ pub trait Application: Sized { /// Any [`Command`] returned will be executed immediately in the background. fn update(&mut self, message: Self::Message) -> Command; + /// Returns the widgets to display in the [`Application`]. + /// + /// These widgets can produce __messages__ based on user interaction. + fn view(&self) -> pure::Element<'_, Self::Message, Self::Theme>; + + /// Returns the current [`Theme`] of the [`Application`]. + fn theme(&self) -> Self::Theme { + Self::Theme::default() + } + /// Returns the event [`Subscription`] for the current state of the /// application. /// @@ -63,11 +76,6 @@ pub trait Application: Sized { Subscription::none() } - /// Returns the widgets to display in the [`Application`]. - /// - /// These widgets can produce __messages__ based on user interaction. - fn view(&self) -> pure::Element<'_, Self::Message>; - /// Returns the current [`Application`] mode. /// /// The runtime will automatically transition your application if a new mode @@ -137,6 +145,7 @@ where type Executor = A::Executor; type Message = A::Message; type Flags = A::Flags; + type Theme = A::Theme; fn new(flags: Self::Flags) -> (Self, Command) { let (application, command) = A::new(flags); @@ -162,12 +171,16 @@ where A::subscription(&self.application) } - fn view(&mut self) -> crate::Element<'_, Self::Message> { + fn view(&mut self) -> crate::Element<'_, Self::Message, Self::Theme> { let content = A::view(&self.application); Pure::new(&mut self.state, content).into() } + fn theme(&self) -> Self::Theme { + A::theme(&self.application) + } + fn mode(&self) -> window::Mode { A::mode(&self.application) } -- 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/application.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/pure/application.rs') diff --git a/src/pure/application.rs b/src/pure/application.rs index 77f68c9e..1306ab6c 100644 --- a/src/pure/application.rs +++ b/src/pure/application.rs @@ -1,6 +1,7 @@ use crate::pure::{self, Pure}; +use crate::theme; use crate::window; -use crate::{Color, Command, Executor, Settings, Subscription}; +use crate::{Command, Executor, Settings, Subscription}; /// A pure version of [`Application`]. /// @@ -22,7 +23,7 @@ pub trait Application: Sized { type Message: std::fmt::Debug + Send; /// The theme of your [`Application`]. - type Theme: Default; + type Theme: Default + theme::Definition; /// The data needed to initialize your [`Application`]. type Flags; @@ -88,13 +89,6 @@ pub trait Application: Sized { window::Mode::Windowed } - /// Returns the background color of the [`Application`]. - /// - /// By default, it returns [`Color::WHITE`]. - fn background_color(&self) -> Color { - Color::WHITE - } - /// Returns the scale factor of the [`Application`]. /// /// It can be used to dynamically control the size of the UI at runtime @@ -185,10 +179,6 @@ where A::mode(&self.application) } - fn background_color(&self) -> Color { - A::background_color(&self.application) - } - fn scale_factor(&self) -> f64 { A::scale_factor(&self.application) } -- cgit From 7f3b7075db68a215f4331b4bfba1c8ddd1c4d7f3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 26 May 2022 19:02:15 +0200 Subject: Rename `theme::Definition` to `application::StyleSheet` --- src/pure/application.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/pure/application.rs') diff --git a/src/pure/application.rs b/src/pure/application.rs index 1306ab6c..4a7df13e 100644 --- a/src/pure/application.rs +++ b/src/pure/application.rs @@ -1,8 +1,9 @@ use crate::pure::{self, Pure}; -use crate::theme; use crate::window; use crate::{Command, Executor, Settings, Subscription}; +pub use iced_native::application::StyleSheet; + /// A pure version of [`Application`]. /// /// Unlike the impure version, the `view` method of this trait takes an @@ -23,7 +24,7 @@ pub trait Application: Sized { type Message: std::fmt::Debug + Send; /// The theme of your [`Application`]. - type Theme: Default + theme::Definition; + type Theme: Default + StyleSheet; /// The data needed to initialize your [`Application`]. type Flags; -- cgit From 48bc505cb6fe85b6568715de4c8b4067603f8fb0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Jul 2022 23:20:25 +0200 Subject: Fix missing docs in `iced` crate --- src/pure/application.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/pure/application.rs') diff --git a/src/pure/application.rs b/src/pure/application.rs index 4a7df13e..af9b078b 100644 --- a/src/pure/application.rs +++ b/src/pure/application.rs @@ -1,3 +1,4 @@ +//! Build interactive cross-platform applications. use crate::pure::{self, Pure}; use crate::window; use crate::{Command, Executor, Settings, Subscription}; -- cgit From 4407385fbe629eb079b0166649492da5f689ea95 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Jul 2022 23:38:34 +0200 Subject: Make `Element` aliases in `iced` compatible with `iced_native` and `iced_pure` --- src/pure/application.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/pure/application.rs') diff --git a/src/pure/application.rs b/src/pure/application.rs index af9b078b..396854ad 100644 --- a/src/pure/application.rs +++ b/src/pure/application.rs @@ -60,7 +60,9 @@ pub trait Application: Sized { /// Returns the widgets to display in the [`Application`]. /// /// These widgets can produce __messages__ based on user interaction. - fn view(&self) -> pure::Element<'_, Self::Message, Self::Theme>; + fn view( + &self, + ) -> pure::Element<'_, Self::Message, crate::Renderer>; /// Returns the current [`Theme`] of the [`Application`]. fn theme(&self) -> Self::Theme { @@ -167,7 +169,9 @@ where A::subscription(&self.application) } - fn view(&mut self) -> crate::Element<'_, Self::Message, Self::Theme> { + fn view( + &mut self, + ) -> crate::Element<'_, Self::Message, crate::Renderer> { let content = A::view(&self.application); Pure::new(&mut self.state, content).into() -- cgit