summaryrefslogtreecommitdiffstats
path: root/src/application.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-05-14 01:47:55 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-05-14 01:56:32 +0200
commit664251f3f5c7b76f69a97683af1468094bba887f (patch)
treef43a495036ed117ce5dbb479c62652d872a6d273 /src/application.rs
parent5de337f214530faab1d5fe47784afd7006c3f7f0 (diff)
downloadiced-664251f3f5c7b76f69a97683af1468094bba887f.tar.gz
iced-664251f3f5c7b76f69a97683af1468094bba887f.tar.bz2
iced-664251f3f5c7b76f69a97683af1468094bba887f.zip
Draft first-class `Theme` support
RFC: https://github.com/iced-rs/rfcs/pull/6
Diffstat (limited to 'src/application.rs')
-rw-r--r--src/application.rs33
1 files changed, 23 insertions, 10 deletions
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<Self::Message>) {
/// (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<Self::Message>;
+ /// 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>,
Self::Executor,
- crate::renderer::window::Compositor,
+ crate::renderer::window::Compositor<Self::Theme>,
>(settings.into(), renderer_settings)?)
}
}
@@ -224,14 +233,14 @@ impl<A> iced_winit::Program for Instance<A>
where
A: Application,
{
- type Renderer = crate::renderer::Renderer;
+ type Renderer = crate::renderer::Renderer<A::Theme>;
type Message = A::Message;
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
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,