summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs22
-rw-r--r--src/winit.rs4
2 files changed, 17 insertions, 9 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 52b0ff8c..945af421 100644
--- a/src/lib.rs
+++ b/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> {
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>;