Add use_event_reader()
This commit is contained in:
parent
01eed81bf1
commit
85709a3a92
|
@ -2,6 +2,7 @@ use crate::UiContext;
|
||||||
use bevy::{
|
use bevy::{
|
||||||
ecs::{
|
ecs::{
|
||||||
component::ComponentId,
|
component::ComponentId,
|
||||||
|
event::{Event, EventIterator, Events, ManualEventReader},
|
||||||
query::{QueryState, ReadOnlyWorldQuery},
|
query::{QueryState, ReadOnlyWorldQuery},
|
||||||
system::{Query, Resource},
|
system::{Query, Resource},
|
||||||
world::{unsafe_world_cell::UnsafeWorldCell, World},
|
world::{unsafe_world_cell::UnsafeWorldCell, World},
|
||||||
|
@ -115,6 +116,16 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn use_event_reader<'a, E: Event>(cx: &'a ScopeState) -> EventIterator<'a, E> {
|
||||||
|
let event_reader = cx.use_hook(|| ManualEventReader::default());
|
||||||
|
let events = EcsContext::get_world(cx).resource::<Events<E>>();
|
||||||
|
let new_events = event_reader.read(events);
|
||||||
|
if new_events.len() != 0 {
|
||||||
|
(cx.schedule_update())();
|
||||||
|
}
|
||||||
|
new_events
|
||||||
|
}
|
||||||
|
|
||||||
pub struct UseQuery<'a, Q: ReadOnlyWorldQuery, F: ReadOnlyWorldQuery> {
|
pub struct UseQuery<'a, Q: ReadOnlyWorldQuery, F: ReadOnlyWorldQuery> {
|
||||||
query_state: QueryState<Q, F>,
|
query_state: QueryState<Q, F>,
|
||||||
world_cell: UnsafeWorldCell<'a>,
|
world_cell: UnsafeWorldCell<'a>,
|
||||||
|
|
|
@ -29,7 +29,9 @@ use dioxus::core::{Element, ElementId, Scope, VirtualDom};
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use super::deferred_system::use_system_scheduler;
|
pub use super::deferred_system::use_system_scheduler;
|
||||||
pub use super::ecs_hooks::{use_query, use_query_filtered, use_resource, use_world};
|
pub use super::ecs_hooks::{
|
||||||
|
use_event_reader, use_query, use_query_filtered, use_resource, use_world,
|
||||||
|
};
|
||||||
pub use super::elements::*;
|
pub use super::elements::*;
|
||||||
pub use super::use_state_send::*;
|
pub use super::use_state_send::*;
|
||||||
pub use super::{DioxusUiBundle, DioxusUiPlugin, DioxusUiRoot};
|
pub use super::{DioxusUiBundle, DioxusUiPlugin, DioxusUiRoot};
|
||||||
|
|
Loading…
Reference in a new issue