diff --git a/crates/bevy_ecs/src/observer/mod.rs b/crates/bevy_ecs/src/observer/mod.rs index e10ec4c5e0ddd..43b4005776090 100644 --- a/crates/bevy_ecs/src/observer/mod.rs +++ b/crates/bevy_ecs/src/observer/mod.rs @@ -6,11 +6,13 @@ mod centralized_storage; mod distributed_storage; mod entity_cloning; +mod observe; mod runner; mod system_param; pub use centralized_storage::*; pub use distributed_storage::*; +pub use observe::*; pub use runner::*; pub use system_param::*; diff --git a/crates/bevy_ui_widgets/src/observe.rs b/crates/bevy_ecs/src/observer/observe.rs similarity index 71% rename from crates/bevy_ui_widgets/src/observe.rs rename to crates/bevy_ecs/src/observer/observe.rs index 9443cb5898711..c08fae6b53aaf 100644 --- a/crates/bevy_ui_widgets/src/observe.rs +++ b/crates/bevy_ecs/src/observer/observe.rs @@ -1,10 +1,10 @@ -// TODO: This probably doesn't belong in bevy_ui_widgets, but I am not sure where it should go. -// It is certainly a useful thing to have. +//! Helper utilities for adding observers as bundle effects. + #![expect(unsafe_code, reason = "Unsafe code is used to improve performance.")] use core::{marker::PhantomData, mem}; -use bevy_ecs::{ +use crate::{ bundle::{Bundle, DynamicBundle}, event::EntityEvent, system::IntoObserverSystem, @@ -26,16 +26,16 @@ unsafe impl< { #[inline] fn component_ids( - _components: &mut bevy_ecs::component::ComponentsRegistrator, - ) -> impl Iterator + use { + _components: &mut crate::component::ComponentsRegistrator, + ) -> impl Iterator + use { // SAFETY: Empty iterator core::iter::empty() } #[inline] fn get_component_ids( - _components: &bevy_ecs::component::Components, - ) -> impl Iterator> { + _components: &crate::component::Components, + ) -> impl Iterator> { // SAFETY: Empty iterator core::iter::empty() } @@ -48,8 +48,8 @@ impl> DynamicBundle #[inline] unsafe fn get_components( - ptr: bevy_ecs::ptr::MovingPtr<'_, Self>, - _func: &mut impl FnMut(bevy_ecs::component::StorageType, bevy_ecs::ptr::OwningPtr<'_>), + ptr: crate::ptr::MovingPtr<'_, Self>, + _func: &mut impl FnMut(crate::component::StorageType, crate::ptr::OwningPtr<'_>), ) { // SAFETY: We must not drop the pointer here, or it will be uninitialized in `apply_effect` // below. @@ -58,8 +58,8 @@ impl> DynamicBundle #[inline] unsafe fn apply_effect( - ptr: bevy_ecs::ptr::MovingPtr<'_, mem::MaybeUninit>, - entity: &mut bevy_ecs::world::EntityWorldMut, + ptr: crate::ptr::MovingPtr<'_, mem::MaybeUninit>, + entity: &mut crate::world::EntityWorldMut, ) { // SAFETY: The pointer was not dropped in `get_components`, so the allocation is still // initialized. diff --git a/crates/bevy_feathers/src/controls/virtual_keyboard.rs b/crates/bevy_feathers/src/controls/virtual_keyboard.rs index f59c1d1bcc5c9..9852d723593b1 100644 --- a/crates/bevy_feathers/src/controls/virtual_keyboard.rs +++ b/crates/bevy_feathers/src/controls/virtual_keyboard.rs @@ -1,9 +1,10 @@ +use bevy_ecs::observer::observe; use bevy_ecs::prelude::*; use bevy_input_focus::tab_navigation::TabGroup; use bevy_ui::Node; use bevy_ui::Val; use bevy_ui::{widget::Text, FlexDirection}; -use bevy_ui_widgets::{observe, Activate}; +use bevy_ui_widgets::Activate; use crate::controls::{button, ButtonProps}; diff --git a/crates/bevy_ui_widgets/src/lib.rs b/crates/bevy_ui_widgets/src/lib.rs index 8f30e2842701a..078d451b611bf 100644 --- a/crates/bevy_ui_widgets/src/lib.rs +++ b/crates/bevy_ui_widgets/src/lib.rs @@ -21,7 +21,6 @@ mod button; mod checkbox; mod menu; -mod observe; pub mod popover; mod radio; mod scrollbar; @@ -30,7 +29,6 @@ mod slider; pub use button::*; pub use checkbox::*; pub use menu::*; -pub use observe::*; pub use radio::*; pub use scrollbar::*; pub use slider::*; diff --git a/examples/ui/standard_widgets_observers.rs b/examples/ui/standard_widgets_observers.rs index 4bed7b5c5b257..6c8ce0cc752f0 100644 --- a/examples/ui/standard_widgets_observers.rs +++ b/examples/ui/standard_widgets_observers.rs @@ -6,6 +6,7 @@ use bevy::{ color::palettes::basic::*, + ecs::observer::observe, input_focus::{ tab_navigation::{TabGroup, TabIndex, TabNavigationPlugin}, InputDispatchPlugin, @@ -15,8 +16,8 @@ use bevy::{ reflect::Is, ui::{Checked, InteractionDisabled, Pressed}, ui_widgets::{ - checkbox_self_update, observe, Activate, Button, Checkbox, Slider, SliderRange, - SliderThumb, SliderValue, UiWidgetsPlugins, ValueChange, + checkbox_self_update, Activate, Button, Checkbox, Slider, SliderRange, SliderThumb, + SliderValue, UiWidgetsPlugins, ValueChange, }, }; diff --git a/examples/ui/virtual_keyboard.rs b/examples/ui/virtual_keyboard.rs index 918b1a1054fbb..aa8756d762f14 100644 --- a/examples/ui/virtual_keyboard.rs +++ b/examples/ui/virtual_keyboard.rs @@ -2,6 +2,7 @@ use bevy::{ color::palettes::css::NAVY, + ecs::observer::observe, feathers::{ controls::{virtual_keyboard, VirtualKeyPressed}, dark_theme::create_dark_theme, @@ -9,7 +10,6 @@ use bevy::{ FeathersPlugins, }, prelude::*, - ui_widgets::observe, }; fn main() {