Cleanup
This commit is contained in:
parent
f4e9dc0c8e
commit
65f5a625ad
|
|
@ -15,35 +15,34 @@ pub fn tick_dioxus_ui(world: &mut World) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let world_cell = world.as_unsafe_world_cell();
|
let world_cell = world.as_unsafe_world_cell();
|
||||||
|
|
||||||
let apply_mutations = |mutations: Mutations, bevy_ui_root: Entity| {
|
let apply_mutations = |mutations: Mutations, root_entity: Entity| {
|
||||||
todo!("Modify bevy_ui entities based on mutations");
|
todo!("Modify bevy_ui entities based on mutations");
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut command_queue = CommandQueue::default();
|
let mut command_queue = CommandQueue::default();
|
||||||
|
let ecs_context = EcsContext {
|
||||||
|
world_read_only: transmute(world_cell.world()),
|
||||||
|
commands: Rc::new(RefCell::new(Commands::new(
|
||||||
|
transmute(&mut command_queue),
|
||||||
|
transmute(world_cell.world()),
|
||||||
|
))),
|
||||||
|
};
|
||||||
|
|
||||||
for mut dioxus_ui_root in world_cell
|
for (root_entity, mut dioxus_ui_root) in world_cell
|
||||||
.world_mut()
|
.world_mut()
|
||||||
.query::<&mut DioxusUiRoot>()
|
.query::<(Entity, &mut DioxusUiRoot)>()
|
||||||
.iter_mut(world_cell.world_mut())
|
.iter_mut(world_cell.world_mut())
|
||||||
{
|
{
|
||||||
dioxus_ui_root
|
dioxus_ui_root
|
||||||
.virtual_dom
|
.virtual_dom
|
||||||
.get()
|
.get()
|
||||||
.base_scope()
|
.base_scope()
|
||||||
.provide_context(EcsContext {
|
.provide_context(ecs_context.clone());
|
||||||
world_read_only: transmute(world_cell.world()),
|
|
||||||
commands: Rc::new(RefCell::new(Commands::new(
|
|
||||||
transmute(&mut command_queue),
|
|
||||||
transmute(world_cell.world()),
|
|
||||||
))),
|
|
||||||
});
|
|
||||||
|
|
||||||
let bevy_ui_root = dioxus_ui_root.root_entity.unwrap_or_else(|| {
|
if !dioxus_ui_root.initial_build {
|
||||||
// TODO: Spawn bevy_ui_root as a child of dioxus_ui_root
|
apply_mutations(dioxus_ui_root.virtual_dom.get().rebuild(), root_entity);
|
||||||
let bevy_ui_root = world_cell.world_mut().spawn(()).id();
|
dioxus_ui_root.initial_build = true;
|
||||||
apply_mutations(dioxus_ui_root.virtual_dom.get().rebuild(), bevy_ui_root);
|
}
|
||||||
bevy_ui_root
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: Handle events from winit
|
// TODO: Handle events from winit
|
||||||
// dioxus_ui_root
|
// dioxus_ui_root
|
||||||
|
|
@ -53,7 +52,7 @@ pub fn tick_dioxus_ui(world: &mut World) {
|
||||||
|
|
||||||
apply_mutations(
|
apply_mutations(
|
||||||
dioxus_ui_root.virtual_dom.get().render_immediate(),
|
dioxus_ui_root.virtual_dom.get().render_immediate(),
|
||||||
bevy_ui_root,
|
root_entity,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ mod implementation;
|
||||||
use self::implementation::{tick_dioxus_ui, VirtualDomUnsafe};
|
use self::implementation::{tick_dioxus_ui, VirtualDomUnsafe};
|
||||||
use bevy::{
|
use bevy::{
|
||||||
app::{App, Plugin, Update},
|
app::{App, Plugin, Update},
|
||||||
ecs::{component::Component, entity::Entity},
|
ecs::component::Component,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use self::implementation::{use_commands, use_res, use_world};
|
pub use self::implementation::{use_commands, use_res, use_world};
|
||||||
|
|
@ -20,14 +20,14 @@ impl Plugin for DioxusUiPlugin {
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct DioxusUiRoot {
|
pub struct DioxusUiRoot {
|
||||||
virtual_dom: VirtualDomUnsafe,
|
virtual_dom: VirtualDomUnsafe,
|
||||||
root_entity: Option<Entity>,
|
initial_build: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DioxusUiRoot {
|
impl DioxusUiRoot {
|
||||||
pub fn new(root_component: fn(Scope) -> Element) -> Self {
|
pub fn new(root_component: fn(Scope) -> Element) -> Self {
|
||||||
Self {
|
Self {
|
||||||
virtual_dom: VirtualDomUnsafe::new(root_component),
|
virtual_dom: VirtualDomUnsafe::new(root_component),
|
||||||
root_entity: None,
|
initial_build: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue