summaryrefslogtreecommitdiffstats
path: root/src/pure/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/pure/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/pure/application.rs')
-rw-r--r--src/pure/application.rs25
1 files changed, 19 insertions, 6 deletions
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<Self::Message>;
+ /// 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<Self::Message>) {
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)
}