iced/web/src/bus.rs
Héctor Ramón Jiménez a92a0b73ed Move winit logic from iced to iced_winit
- Added new `renderer::Windowed` trait. This shoud allow users to easily
  try different renderers by simply changing one line.
- Renamed `UserInterface` traits to `Application`, as the `run` method
  takes total control of the current thread.
- Moved `MouseCursor` back to `iced_native`. The new
  `renderer::Windowed` trait returns one on `draw`.
- Split `iced_native` renderer in multiple modules, for consistency.
2019-10-09 05:36:49 +02:00

40 lines
885 B
Rust

use crate::Instance;
use std::rc::Rc;
#[derive(Clone)]
pub struct Bus<Message> {
publish: Rc<Box<dyn Fn(Message, &mut dyn dodrio::RootRender)>>,
}
impl<Message> Bus<Message>
where
Message: 'static,
{
pub fn new() -> Self {
Self {
publish: Rc::new(Box::new(|message, root| {
let app = root.unwrap_mut::<Instance<Message>>();
app.update(message)
})),
}
}
pub fn publish(&self, message: Message, root: &mut dyn dodrio::RootRender) {
(self.publish)(message, root);
}
pub fn map<B>(&self, mapper: Rc<Box<dyn Fn(B) -> Message>>) -> Bus<B>
where
B: 'static,
{
let publish = self.publish.clone();
Bus {
publish: Rc::new(Box::new(move |message, root| {
publish(mapper(message), root)
})),
}
}
}