2023-12-07 20:30:33 +00:00
|
|
|
use crate::{
|
|
|
|
deferred_system::{new_deferred_system, DeferredSystem},
|
|
|
|
tick::EcsContext,
|
|
|
|
};
|
2023-12-07 02:46:50 +00:00
|
|
|
use bevy::ecs::{
|
|
|
|
system::{IntoSystem, Resource},
|
|
|
|
world::World,
|
|
|
|
};
|
|
|
|
use dioxus_core::ScopeState;
|
|
|
|
|
|
|
|
pub trait DioxusUiHooks {
|
|
|
|
fn use_world<'a>(&'a self) -> &'a World;
|
|
|
|
fn use_resource<'a, T: Resource>(&'a self) -> &'a T;
|
|
|
|
fn use_system<S>(&self, system: S) -> DeferredSystem
|
|
|
|
where
|
|
|
|
S: IntoSystem<(), (), ()> + 'static;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DioxusUiHooks for ScopeState {
|
|
|
|
fn use_world<'a>(&'a self) -> &'a World {
|
|
|
|
EcsContext::get_world(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn use_resource<'a, T: Resource>(&'a self) -> &'a T {
|
|
|
|
EcsContext::get_world(self).resource()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn use_system<S>(&self, system: S) -> DeferredSystem
|
|
|
|
where
|
|
|
|
S: IntoSystem<(), (), ()> + 'static,
|
|
|
|
{
|
2023-12-07 20:30:33 +00:00
|
|
|
self.use_hook(|| new_deferred_system(system, EcsContext::get_world(self)))
|
2023-12-07 20:25:02 +00:00
|
|
|
.0
|
2023-12-07 02:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// pub fn use_query<'a, Q, F>(cx: &'a ScopeState) -> QueryIter<'a, '_, Q, F>
|
|
|
|
// where
|
|
|
|
// Q: ReadOnlyWorldQuery,
|
|
|
|
// F: ReadOnlyWorldQuery,
|
|
|
|
// {
|
|
|
|
// let world = EcsContext::get_world(cx);
|
|
|
|
// world.query_filtered::<Q, F>().iter(&world)
|
|
|
|
// }
|