diff options
Diffstat (limited to 'winit')
-rw-r--r-- | winit/src/application.rs | 41 | ||||
-rw-r--r-- | winit/src/application/state.rs | 13 |
2 files changed, 27 insertions, 27 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs index 90b03d56..c7905c60 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -7,8 +7,8 @@ use crate::clipboard::{self, Clipboard}; use crate::conversion; use crate::mouse; use crate::{ - Color, Command, Debug, Error, Executor, Mode, Proxy, Runtime, Settings, - Size, Subscription, + Command, Debug, Error, Executor, Mode, Proxy, Runtime, Settings, Size, + Subscription, }; use iced_futures::futures; @@ -18,6 +18,8 @@ use iced_graphics::window; use iced_native::program::Program; use iced_native::user_interface::{self, UserInterface}; +pub use iced_native::application::StyleSheet; + use std::mem::ManuallyDrop; /// An interactive, native cross-platform application. @@ -51,6 +53,9 @@ pub trait Application: Program { /// title of your application when necessary. fn title(&self) -> String; + /// Returns the current [`Theme`] of the [`Application`]. + fn theme(&self) -> <Self::Renderer as iced_native::Renderer>::Theme; + /// Returns the event `Subscription` for the current state of the /// application. /// @@ -74,13 +79,6 @@ pub trait Application: Program { 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 @@ -112,6 +110,7 @@ where A: Application + 'static, E: Executor + 'static, C: window::Compositor<Renderer = A::Renderer> + 'static, + <A::Renderer as iced_native::Renderer>::Theme: StyleSheet, { use futures::task; use futures::Future; @@ -247,6 +246,7 @@ async fn run_instance<A, E, C>( A: Application + 'static, E: Executor + 'static, C: window::Compositor<Renderer = A::Renderer> + 'static, + <A::Renderer as iced_native::Renderer>::Theme: StyleSheet, { use iced_futures::futures::stream::StreamExt; use winit::event; @@ -255,6 +255,7 @@ async fn run_instance<A, E, C>( let mut state = State::new(&application, &window); let mut viewport_version = state.viewport_version(); + let mut theme = application.theme(); let physical_size = state.physical_size(); @@ -327,6 +328,7 @@ async fn run_instance<A, E, C>( let should_exit = application.should_exit(); + theme = application.theme(); user_interface = ManuallyDrop::new(build_user_interface( &mut application, cache, @@ -341,8 +343,11 @@ async fn run_instance<A, E, C>( } debug.draw_started(); - let new_mouse_interaction = - user_interface.draw(&mut renderer, state.cursor_position()); + let new_mouse_interaction = user_interface.draw( + &mut renderer, + &theme, + state.cursor_position(), + ); debug.draw_finished(); if new_mouse_interaction != mouse_interaction { @@ -389,8 +394,11 @@ async fn run_instance<A, E, C>( debug.layout_finished(); debug.draw_started(); - let new_mouse_interaction = user_interface - .draw(&mut renderer, state.cursor_position()); + let new_mouse_interaction = user_interface.draw( + &mut renderer, + &theme, + state.cursor_position(), + ); if new_mouse_interaction != mouse_interaction { window.set_cursor_icon(conversion::mouse_interaction( @@ -414,7 +422,7 @@ async fn run_instance<A, E, C>( &mut renderer, &mut surface, state.viewport(), - state.background_color(), + theme.background_color(), &debug.overlay(), ) { Ok(()) => { @@ -497,7 +505,10 @@ pub fn build_user_interface<'a, A: Application>( renderer: &mut A::Renderer, size: Size, debug: &mut Debug, -) -> UserInterface<'a, A::Message, A::Renderer> { +) -> UserInterface<'a, A::Message, A::Renderer> +where + <A::Renderer as crate::Renderer>::Theme: StyleSheet, +{ debug.view_started(); let view = application.view(); debug.view_finished(); diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs index b54d3aed..34a9b10e 100644 --- a/winit/src/application/state.rs +++ b/winit/src/application/state.rs @@ -1,5 +1,5 @@ use crate::conversion; -use crate::{Application, Color, Debug, Mode, Point, Size, Viewport}; +use crate::{Application, Debug, Mode, Point, Size, Viewport}; use std::marker::PhantomData; use winit::event::{Touch, WindowEvent}; @@ -10,7 +10,6 @@ use winit::window::Window; pub struct State<A: Application> { title: String, mode: Mode, - background_color: Color, scale_factor: f64, viewport: Viewport, viewport_version: usize, @@ -24,7 +23,6 @@ impl<A: Application> State<A> { pub fn new(application: &A, window: &Window) -> Self { let title = application.title(); let mode = application.mode(); - let background_color = application.background_color(); let scale_factor = application.scale_factor(); let viewport = { @@ -39,7 +37,6 @@ impl<A: Application> State<A> { Self { title, mode, - background_color, scale_factor, viewport, viewport_version: 0, @@ -50,11 +47,6 @@ impl<A: Application> State<A> { } } - /// Returns the current background [`Color`] of the [`State`]. - pub fn background_color(&self) -> Color { - self.background_color - } - /// Returns the current [`Viewport`] of the [`State`]. pub fn viewport(&self) -> &Viewport { &self.viewport @@ -187,9 +179,6 @@ impl<A: Application> State<A> { self.mode = new_mode; } - // Update background color - self.background_color = application.background_color(); - // Update scale factor let new_scale_factor = application.scale_factor(); |