mod apply_mutations; pub mod colors; mod deferred_system; mod events; pub mod hooks; mod tick; use self::{ apply_mutations::BevyTemplate, deferred_system::DeferredSystemRegistry, events::EventReaders, hooks::EcsSubscriptions, tick::tick_dioxus_ui, }; use bevy::{ app::{App, Plugin, Update}, ecs::{bundle::Bundle, component::Component, entity::Entity}, prelude::{Deref, DerefMut}, ui::node_bundles::NodeBundle, utils::{EntityHashMap, HashMap}, }; use dioxus::core::{Element, ElementId, Scope, VirtualDom}; pub use bevy_mod_picking; pub use dioxus; pub struct DioxusUiPlugin; impl Plugin for DioxusUiPlugin { fn build(&self, app: &mut App) { // TODO: I think UiRoots must be dropped only after EcsSubscriptions app.init_non_send_resource::() .init_resource::() .init_resource::() .init_resource::() .add_systems(Update, tick_dioxus_ui); } } #[derive(Bundle)] pub struct DioxusUiBundle { pub dioxus_ui_root: DioxusUiRoot, pub node_bundle: NodeBundle, } #[derive(Component, Deref, Hash, PartialEq, Eq, Clone, Copy)] pub struct DioxusUiRoot(pub fn(Scope) -> Element); #[derive(Deref, DerefMut, Default)] struct UiRoots(HashMap<(Entity, DioxusUiRoot), UiRoot>); struct UiRoot { virtual_dom: VirtualDom, element_id_to_bevy_ui_entity: HashMap, bevy_ui_entity_to_element_id: EntityHashMap, templates: HashMap, needs_rebuild: bool, } impl UiRoot { fn new(root_component: DioxusUiRoot) -> Self { Self { virtual_dom: VirtualDom::new(root_component.0), element_id_to_bevy_ui_entity: HashMap::new(), bevy_ui_entity_to_element_id: EntityHashMap::default(), templates: HashMap::new(), needs_rebuild: true, } } }