use freya_engine::prelude::{
Canvas,
FontCollection,
};
use freya_native_core::NodeId;
use torin::torin::Torin;
use winit::window::Window;
use crate::dom::FreyaDOM;
#[derive(Default)]
pub struct PluginsManager {
plugins: Vec<Box<dyn FreyaPlugin>>,
}
impl PluginsManager {
pub fn add_plugin(&mut self, plugin: impl FreyaPlugin + 'static) {
self.plugins.push(Box::new(plugin))
}
pub fn send(&mut self, event: PluginEvent) {
for plugin in &mut self.plugins {
plugin.on_event(&event)
}
}
}
pub enum PluginEvent<'a> {
WindowCreated(&'a Window),
BeforeRender {
canvas: &'a Canvas,
font_collection: &'a FontCollection,
freya_dom: &'a FreyaDOM,
},
AfterRender {
canvas: &'a Canvas,
font_collection: &'a FontCollection,
freya_dom: &'a FreyaDOM,
},
StartedLayout(&'a Torin<NodeId>),
FinishedLayout(&'a Torin<NodeId>),
StartedUpdatingDOM,
FinishedUpdatingDOM,
}
pub trait FreyaPlugin {
fn on_event(&mut self, event: &PluginEvent);
}