Support async actions in iced_winit
This commit is contained in:
parent
e640b87590
commit
02c20e6202
7 changed files with 110 additions and 47 deletions
22
src/lib.rs
22
src/lib.rs
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue