diff options
| author | 2019-11-17 07:09:46 +0100 | |
|---|---|---|
| committer | 2019-11-17 07:11:44 +0100 | |
| commit | 02c20e6202f1c8c28753f3233cc635790707937a (patch) | |
| tree | b13ec79b938a6000709d1241ac1344724386c77a /src | |
| parent | e640b875900a3833fd38efa195e99b40ec3f6820 (diff) | |
| download | iced-02c20e6202f1c8c28753f3233cc635790707937a.tar.gz iced-02c20e6202f1c8c28753f3233cc635790707937a.tar.bz2 iced-02c20e6202f1c8c28753f3233cc635790707937a.zip | |
Support async actions in `iced_winit`
Diffstat (limited to '')
| -rw-r--r-- | src/lib.rs | 22 | ||||
| -rw-r--r-- | src/winit.rs | 4 | 
2 files changed, 17 insertions, 9 deletions
| @@ -4,21 +4,23 @@ mod platform;  pub use platform::*; -pub trait Application { -    type Message: std::fmt::Debug; +pub trait Application: Sized { +    type Message: std::fmt::Debug + Send; + +    fn new() -> (Self, Command<Self::Message>);      fn title(&self) -> String; -    fn update(&mut self, message: Self::Message); +    fn update(&mut self, message: Self::Message) -> Command<Self::Message>;      fn view(&mut self) -> Element<Self::Message>; -    fn run(self) +    fn run()      where          Self: 'static + Sized,      {          #[cfg(not(target_arch = "wasm32"))] -        iced_winit::Application::run(Instance(self)); +        <Instance<Self> as iced_winit::Application>::run();          #[cfg(target_arch = "wasm32")]          iced_web::Application::run(Instance(self)); @@ -35,12 +37,18 @@ where      type Renderer = Renderer;      type Message = A::Message; +    fn new() -> (Self, Command<A::Message>) { +        let (app, command) = A::new(); + +        (Instance(app), command) +    } +      fn title(&self) -> String {          self.0.title()      } -    fn update(&mut self, message: Self::Message) { -        self.0.update(message); +    fn update(&mut self, message: Self::Message) -> Command<Self::Message> { +        self.0.update(message)      }      fn view(&mut self) -> Element<Self::Message> { diff --git a/src/winit.rs b/src/winit.rs index d35a339f..c869a269 100644 --- a/src/winit.rs +++ b/src/winit.rs @@ -2,8 +2,8 @@ pub use iced_wgpu::{Primitive, Renderer};  pub use iced_winit::{      button, scrollable, slider, text, text_input, winit, Align, Background, -    Checkbox, Color, Font, Image, Length, Radio, Scrollable, Slider, Text, -    TextInput, +    Checkbox, Color, Command, Font, Image, Length, Radio, Scrollable, Slider, +    Text, TextInput,  };  pub type Element<'a, Message> = iced_winit::Element<'a, Message, Renderer>; | 
