Draft first-class Theme support

RFC: https://github.com/iced-rs/rfcs/pull/6
This commit is contained in:
Héctor Ramón Jiménez 2022-05-14 01:47:55 +02:00
parent 5de337f214
commit 664251f3f5
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
113 changed files with 767 additions and 878 deletions

View file

@ -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)
}