bevy_dioxus/src/lib.rs

60 lines
1.4 KiB
Rust
Raw Normal View History

2023-12-07 02:46:50 +00:00
mod apply_mutations;
mod deferred_system;
mod hooks;
mod tick;
2023-12-06 05:24:51 +00:00
2023-12-07 02:46:50 +00:00
use self::{
apply_mutations::BevyTemplate,
2023-12-07 20:25:02 +00:00
deferred_system::DeferredSystemRegistry,
2023-12-07 02:46:50 +00:00
tick::{tick_dioxus_ui, VirtualDomUnsafe},
};
2023-12-06 05:24:51 +00:00
use bevy::{
app::{App, Plugin, Update},
ecs::{bundle::Bundle, component::Component, entity::Entity},
ui::node_bundles::NodeBundle,
2023-12-07 19:17:42 +00:00
utils::HashMap,
2023-12-06 05:24:51 +00:00
};
use dioxus::core::{Element, ElementId, Scope};
2023-12-06 05:24:51 +00:00
2023-12-07 21:51:55 +00:00
pub use self::{
deferred_system::DeferredSystem,
hooks::{DioxusUiHooks, DioxusUiQuery},
};
pub use dioxus;
2023-12-06 05:58:45 +00:00
2023-12-06 05:24:51 +00:00
pub struct DioxusUiPlugin;
impl Plugin for DioxusUiPlugin {
fn build(&self, app: &mut App) {
2023-12-07 20:25:02 +00:00
app.init_resource::<DeferredSystemRegistry>()
2023-12-07 02:46:50 +00:00
.add_systems(Update, tick_dioxus_ui);
2023-12-06 05:24:51 +00:00
}
}
#[derive(Bundle)]
pub struct DioxusUiBundle {
pub dioxus_ui_root: DioxusUiRoot,
pub node_bundle: NodeBundle,
}
2023-12-06 05:24:51 +00:00
#[derive(Component)]
pub struct DioxusUiRoot {
virtual_dom: VirtualDomUnsafe,
2023-12-10 21:50:10 +00:00
hierarchy: HashMap<(Entity, u8), Entity>,
2023-12-07 19:17:42 +00:00
element_id_to_bevy_ui_entity: HashMap<ElementId, Entity>,
templates: HashMap<String, BevyTemplate>,
2023-12-07 02:46:50 +00:00
needs_rebuild: bool,
2023-12-06 05:24:51 +00:00
}
impl DioxusUiRoot {
pub fn new(root_component: fn(Scope) -> Element) -> Self {
Self {
2023-12-06 06:08:58 +00:00
virtual_dom: VirtualDomUnsafe::new(root_component),
2023-12-10 21:50:10 +00:00
hierarchy: HashMap::new(),
2023-12-07 19:17:42 +00:00
element_id_to_bevy_ui_entity: HashMap::new(),
templates: HashMap::new(),
2023-12-07 02:46:50 +00:00
needs_rebuild: true,
2023-12-06 05:24:51 +00:00
}
}
}