summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-21 18:00:27 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-21 18:00:27 +0100
commitba56a561b254c9a5f3d23cb54d23dc311759ab4c (patch)
tree3d262b1e892d83f7493a99737a267204a191e317 /src/lib.rs
parent428509c84a142a653be3ec4bbff0c23c466c44fa (diff)
downloadiced-ba56a561b254c9a5f3d23cb54d23dc311759ab4c.tar.gz
iced-ba56a561b254c9a5f3d23cb54d23dc311759ab4c.tar.bz2
iced-ba56a561b254c9a5f3d23cb54d23dc311759ab4c.zip
Implement `iced::Sandbox` trait for simple apps
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs72
1 files changed, 4 insertions, 68 deletions
diff --git a/src/lib.rs b/src/lib.rs
index e64767c2..8462cd3c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,73 +1,9 @@
+mod application;
#[cfg_attr(target_arch = "wasm32", path = "web.rs")]
#[cfg_attr(not(target_arch = "wasm32"), path = "native.rs")]
mod platform;
+mod sandbox;
+pub use application::Application;
pub use platform::*;
-
-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) -> Command<Self::Message>;
-
- fn view(&mut self) -> Element<Self::Message>;
-
- fn run()
- where
- Self: 'static + Sized,
- {
- #[cfg(not(target_arch = "wasm32"))]
- <Instance<Self> as iced_winit::Application>::run();
-
- #[cfg(target_arch = "wasm32")]
- iced_web::Application::run(Instance(self));
- }
-}
-
-struct Instance<A: Application>(A);
-
-#[cfg(not(target_arch = "wasm32"))]
-impl<A> iced_winit::Application for Instance<A>
-where
- A: Application,
-{
- type Renderer = iced_wgpu::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) -> Command<Self::Message> {
- self.0.update(message)
- }
-
- fn view(&mut self) -> Element<Self::Message> {
- self.0.view()
- }
-}
-
-#[cfg(target_arch = "wasm32")]
-impl<A> iced_web::Application for Instance<A>
-where
- A: Application,
-{
- type Message = A::Message;
-
- fn update(&mut self, message: Self::Message) {
- self.0.update(message);
- }
-
- fn view(&mut self) -> Element<Self::Message> {
- self.0.view()
- }
-}
+pub use sandbox::Sandbox;