bevy_dioxus/src/lib.rs

49 lines
1.1 KiB
Rust
Raw Normal View History

2023-12-07 02:46:50 +00:00
mod apply_mutations;
2023-12-07 19:17:42 +00:00
mod bsn;
2023-12-07 02:46:50 +00:00
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::{
2023-12-07 19:17:42 +00:00
bsn::Bsn,
2023-12-07 02:46:50 +00:00
deferred_system::DeferredSystemRunQueue,
tick::{tick_dioxus_ui, VirtualDomUnsafe},
};
2023-12-06 05:24:51 +00:00
use bevy::{
app::{App, Plugin, Update},
2023-12-07 19:17:42 +00:00
ecs::{component::Component, entity::Entity},
utils::HashMap,
2023-12-06 05:24:51 +00:00
};
2023-12-07 19:17:42 +00:00
use dioxus_core::ElementId;
2023-12-06 05:24:51 +00:00
2023-12-07 02:46:50 +00:00
pub use self::hooks::DioxusUiHooks;
2023-12-06 06:08:58 +00:00
pub use dioxus_core::{Element, Scope};
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 02:46:50 +00:00
app.init_resource::<DeferredSystemRunQueue>()
.add_systems(Update, tick_dioxus_ui);
2023-12-06 05:24:51 +00:00
}
}
#[derive(Component)]
pub struct DioxusUiRoot {
virtual_dom: VirtualDomUnsafe,
2023-12-07 19:17:42 +00:00
element_id_to_bevy_ui_entity: HashMap<ElementId, Entity>,
templates: HashMap<String, Bsn>,
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-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
}
}
}