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 UserInterface { type Message; fn update( &mut self, message: Self::Message, ) -> Option>>; fn view(&mut self) -> Element; fn run(self) where Self: 'static + Sized, { let window = web_sys::window().unwrap(); let document = window.document().unwrap(); let body = document.body().unwrap(); let app = Application::new(self); let vdom = dodrio::Vdom::new(&body, app); vdom.forget(); } } struct Application { ui: RefCell>>, } impl Application { fn new(ui: impl UserInterface + '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 Application 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()) } }