use dodrio::bumpalo; use futures::Future; use std::cell::RefCell; mod bus; mod element; pub mod widget; pub use bus::Bus; pub use element::Element; pub use iced_core::{Align, Color, Justify, Length}; pub use widget::*; pub trait Application { type Message; fn update( &mut self, message: Self::Message, ) -> Option>>; fn view(&mut self) -> Element; fn run(self) where Self: 'static + Sized, { let app = Instance::new(self); let window = web_sys::window().unwrap(); let document = window.document().unwrap(); let body = document.body().unwrap(); let vdom = dodrio::Vdom::new(&body, app); vdom.forget(); } } struct Instance { ui: RefCell>>, } impl Instance { fn new(ui: impl Application + 'static) -> Self { Self { ui: RefCell::new(Box::new(ui)), } } fn update(&mut self, message: Message) { let mut ui = self.ui.borrow_mut(); // TODO: Resolve futures and publish resulting messages let _ = ui.update(message); } } impl dodrio::Render for Instance where Message: 'static, { fn render<'a, 'bump>( &'a self, bump: &'bump bumpalo::Bump, ) -> dodrio::Node<'bump> where 'a: 'bump, { let mut ui = self.ui.borrow_mut(); let element = ui.view(); element.widget.node(bump, &Bus::new()) } }