diff options
Diffstat (limited to 'src/application.rs')
-rw-r--r-- | src/application.rs | 65 |
1 files changed, 43 insertions, 22 deletions
diff --git a/src/application.rs b/src/application.rs index 11735b93..e8d8e982 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,5 +1,8 @@ +//! Build interactive cross-platform applications. use crate::window; -use crate::{Color, Command, Element, Executor, Settings, Subscription}; +use crate::{Command, Element, Executor, Settings, Subscription}; + +pub use iced_native::application::{Appearance, StyleSheet}; /// An interactive cross-platform application. /// @@ -57,7 +60,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 +70,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 +103,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 + StyleSheet; + /// The data needed to initialize your [`Application`]. type Flags; @@ -129,6 +136,28 @@ 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, crate::Renderer<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`]: <Self::Theme as StyleSheet>::Style + /// [`Theme`]: Self::Theme + fn style(&self) -> <Self::Theme as StyleSheet>::Style { + <Self::Theme as StyleSheet>::Style::default() + } + /// Returns the event [`Subscription`] for the current state of the /// application. /// @@ -141,11 +170,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 @@ -158,13 +182,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 @@ -213,7 +230,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 +241,14 @@ impl<A> iced_winit::Program for Instance<A> where A: Application, { - type Renderer = crate::renderer::Renderer; + type Renderer = crate::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, Self::Renderer> { self.0.view() } } @@ -252,6 +269,14 @@ where self.0.title() } + fn theme(&self) -> A::Theme { + self.0.theme() + } + + fn style(&self) -> <A::Theme as StyleSheet>::Style { + self.0.style() + } + fn mode(&self) -> iced_winit::Mode { match self.0.mode() { window::Mode::Windowed => iced_winit::Mode::Windowed, @@ -264,10 +289,6 @@ where self.0.subscription() } - fn background_color(&self) -> Color { - self.0.background_color() - } - fn scale_factor(&self) -> f64 { self.0.scale_factor() } |