From ae5e2c6c734894d71b2034a498a858b7997c5d3d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 21 May 2020 04:27:31 +0200 Subject: Introduce `Program` and `State` --- src/application.rs | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index 644a4824..b6f2227e 100644 --- a/src/application.rs +++ b/src/application.rs @@ -198,10 +198,11 @@ pub trait Application: Sized { ..iced_glow::Settings::default() }; - as iced_glutin::Application>::run( - settings.into(), - glow_settings, - ); + iced_glutin::application::run::< + Instance, + Self::Executor, + iced_glow::window::Compositor, + >(settings.into(), glow_settings); } #[cfg(target_arch = "wasm32")] @@ -211,15 +212,29 @@ pub trait Application: Sized { struct Instance(A); +#[cfg(not(target_arch = "wasm32"))] +impl iced_glutin::Program for Instance +where + A: Application, +{ + type Renderer = iced_glow::Renderer; + type Message = A::Message; + + fn update(&mut self, message: Self::Message) -> Command { + self.0.update(message) + } + + fn view(&mut self) -> Element<'_, Self::Message> { + self.0.view() + } +} + #[cfg(not(target_arch = "wasm32"))] impl iced_glutin::Application for Instance where A: Application, { - type Compositor = iced_glow::window::Compositor; - type Executor = A::Executor; type Flags = A::Flags; - type Message = A::Message; fn new(flags: Self::Flags) -> (Self, Command) { let (app, command) = A::new(flags); @@ -238,17 +253,9 @@ where } } - fn update(&mut self, message: Self::Message) -> Command { - self.0.update(message) - } - fn subscription(&self) -> Subscription { self.0.subscription() } - - fn view(&mut self) -> Element<'_, Self::Message> { - self.0.view() - } } #[cfg(target_arch = "wasm32")] -- cgit