This commit is contained in:
JMS55 2023-12-05 22:08:58 -08:00
parent 99344da4f4
commit f4e9dc0c8e
2 changed files with 9 additions and 4 deletions

View file

@ -8,7 +8,7 @@ use bevy::{
prelude::{Deref, DerefMut}, prelude::{Deref, DerefMut},
utils::synccell::SyncCell, utils::synccell::SyncCell,
}; };
use dioxus_core::{Mutations, ScopeState, VirtualDom}; use dioxus_core::{Element, Mutations, Scope, ScopeState, VirtualDom};
use std::{cell::RefCell, mem::transmute, rc::Rc}; use std::{cell::RefCell, mem::transmute, rc::Rc};
pub fn tick_dioxus_ui(world: &mut World) { pub fn tick_dioxus_ui(world: &mut World) {
@ -104,3 +104,9 @@ pub fn use_commands<'a>(cx: &'a ScopeState) -> Rc<RefCell<Commands<'a, 'a>>> {
#[derive(Deref, DerefMut)] #[derive(Deref, DerefMut)]
pub struct VirtualDomUnsafe(pub SyncCell<VirtualDom>); pub struct VirtualDomUnsafe(pub SyncCell<VirtualDom>);
unsafe impl Send for VirtualDomUnsafe {} unsafe impl Send for VirtualDomUnsafe {}
impl VirtualDomUnsafe {
pub fn new(root_component: fn(Scope) -> Element) -> Self {
Self(SyncCell::new(VirtualDom::new(root_component)))
}
}

View file

@ -4,11 +4,10 @@ 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, entity::Entity},
utils::synccell::SyncCell,
}; };
use dioxus_core::{Element, Scope, VirtualDom};
pub use self::implementation::{use_commands, use_res, use_world}; pub use self::implementation::{use_commands, use_res, use_world};
pub use dioxus_core::{Element, Scope};
pub struct DioxusUiPlugin; pub struct DioxusUiPlugin;
@ -27,7 +26,7 @@ pub struct DioxusUiRoot {
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(SyncCell::new(VirtualDom::new(root_component))), virtual_dom: VirtualDomUnsafe::new(root_component),
root_entity: None, root_entity: None,
} }
} }