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/application.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/application.rs') diff --git a/src/application.rs b/src/application.rs index 11735b93..f05d2c4b 100644 --- a/src/application.rs +++ b/src/application.rs @@ -57,7 +57,7 @@ use crate::{Color, Command, Element, Executor, Settings, Subscription}; /// says "Hello, world!": /// /// ```no_run -/// use iced::{executor, Application, Command, Element, Settings, Text}; +/// use iced::{executor, Application, Command, Element, Settings, Text, Theme}; /// /// pub fn main() -> iced::Result { /// Hello::run(Settings::default()) @@ -67,8 +67,9 @@ use crate::{Color, Command, Element, Executor, Settings, Subscription}; /// /// impl Application for Hello { /// type Executor = executor::Default; -/// type Message = (); /// type Flags = (); +/// type Message = (); +/// type Theme = Theme; /// /// fn new(_flags: ()) -> (Hello, Command) { /// (Hello, Command::none()) @@ -99,6 +100,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; @@ -129,6 +133,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(&mut self) -> 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. /// @@ -141,11 +155,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(&mut self) -> Element<'_, Self::Message>; - /// Returns the current [`Application`] mode. /// /// The runtime will automatically transition your application if a new mode @@ -213,7 +222,7 @@ pub trait Application: Sized { Ok(crate::runtime::application::run::< Instance, Self::Executor, - crate::renderer::window::Compositor, + crate::renderer::window::Compositor, >(settings.into(), renderer_settings)?) } } @@ -224,14 +233,14 @@ impl iced_winit::Program for Instance where A: Application, { - type Renderer = crate::renderer::Renderer; + type Renderer = crate::renderer::Renderer; type Message = A::Message; fn update(&mut self, message: Self::Message) -> Command { self.0.update(message) } - fn view(&mut self) -> Element<'_, Self::Message> { + fn view(&mut self) -> Element<'_, Self::Message, A::Theme> { self.0.view() } } @@ -252,6 +261,10 @@ where self.0.title() } + fn theme(&self) -> A::Theme { + self.0.theme() + } + fn mode(&self) -> iced_winit::Mode { match self.0.mode() { window::Mode::Windowed => iced_winit::Mode::Windowed, -- 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/application.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/application.rs') diff --git a/src/application.rs b/src/application.rs index f05d2c4b..01571b56 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,5 +1,6 @@ +use crate::theme; use crate::window; -use crate::{Color, Command, Element, Executor, Settings, Subscription}; +use crate::{Command, Element, Executor, Settings, Subscription}; /// An interactive cross-platform application. /// @@ -101,7 +102,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; @@ -167,13 +168,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 @@ -277,10 +271,6 @@ where self.0.subscription() } - fn background_color(&self) -> Color { - self.0.background_color() - } - fn scale_factor(&self) -> f64 { self.0.scale_factor() } -- 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/application.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/application.rs') diff --git a/src/application.rs b/src/application.rs index 01571b56..b7c8cf9f 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,7 +1,8 @@ -use crate::theme; use crate::window; use crate::{Command, Element, Executor, Settings, Subscription}; +pub use iced_native::application::StyleSheet; + /// An interactive cross-platform application. /// /// This trait is the main entrypoint of Iced. Once implemented, you can run @@ -102,7 +103,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 bb07d017e8c8e43ac74f66bf649643bebdc5f71d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Jul 2022 20:07:33 +0200 Subject: Add `Style` variant support to `application::StyleSheet` --- src/application.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/application.rs') diff --git a/src/application.rs b/src/application.rs index b7c8cf9f..d4297eea 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,7 +1,7 @@ use crate::window; use crate::{Command, Element, Executor, Settings, Subscription}; -pub use iced_native::application::StyleSheet; +pub use iced_native::application::{Appearance, StyleSheet}; /// An interactive cross-platform application. /// @@ -141,10 +141,20 @@ pub trait Application: Sized { fn view(&mut self) -> Element<'_, Self::Message, Self::Theme>; /// Returns the current [`Theme`] of the [`Application`]. + /// + /// [`Theme`]: Self::Theme fn theme(&self) -> Self::Theme { Self::Theme::default() } + /// Returns the current [`Style`] of the [`Theme`]. + /// + /// [`Style`]: ::Style + /// [`Theme`]: Self::Theme + fn style(&self) -> ::Style { + ::Style::default() + } + /// Returns the event [`Subscription`] for the current state of the /// application. /// @@ -260,6 +270,10 @@ where self.0.theme() } + fn style(&self) -> ::Style { + self.0.style() + } + fn mode(&self) -> iced_winit::Mode { match self.0.mode() { window::Mode::Windowed => iced_winit::Mode::Windowed, -- 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/application.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/application.rs') diff --git a/src/application.rs b/src/application.rs index d4297eea..4edfb063 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,3 +1,4 @@ +//! Build interactive cross-platform applications. use crate::window; use crate::{Command, Element, 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/application.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/application.rs') diff --git a/src/application.rs b/src/application.rs index 4edfb063..e8d8e982 100644 --- a/src/application.rs +++ b/src/application.rs @@ -139,7 +139,9 @@ pub trait Application: Sized { /// Returns the widgets to display in the [`Application`]. /// /// These widgets can produce __messages__ based on user interaction. - fn view(&mut self) -> Element<'_, Self::Message, Self::Theme>; + fn view( + &mut self, + ) -> Element<'_, Self::Message, crate::Renderer>; /// Returns the current [`Theme`] of the [`Application`]. /// @@ -239,14 +241,14 @@ impl iced_winit::Program for Instance where A: Application, { - type Renderer = crate::renderer::Renderer; + type Renderer = crate::Renderer; type Message = A::Message; fn update(&mut self, message: Self::Message) -> Command { self.0.update(message) } - fn view(&mut self) -> Element<'_, Self::Message, A::Theme> { + fn view(&mut self) -> Element<'_, Self::Message, Self::Renderer> { self.0.view() } } -- cgit