Skip to content

Commit 148c904

Browse files
committed
Move observe helper to ecs observer module
1 parent 2e45788 commit 148c904

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

crates/bevy_ecs/src/observer/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
mod centralized_storage;
77
mod distributed_storage;
88
mod entity_cloning;
9+
mod observe;
910
mod runner;
1011
mod system_param;
1112

1213
pub use centralized_storage::*;
1314
pub use distributed_storage::*;
15+
pub use observe::*;
1416
pub use runner::*;
1517
pub use system_param::*;
1618

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// TODO: This probably doesn't belong in bevy_ui_widgets, but I am not sure where it should go.
2-
// It is certainly a useful thing to have.
1+
//! Helper utilities for adding observers as bundle effects.
2+
33
#![expect(unsafe_code, reason = "Unsafe code is used to improve performance.")]
44

55
use core::{marker::PhantomData, mem};
66

7-
use bevy_ecs::{
7+
use crate::{
88
bundle::{Bundle, DynamicBundle},
99
event::EntityEvent,
1010
system::IntoObserverSystem,
@@ -26,16 +26,16 @@ unsafe impl<
2626
{
2727
#[inline]
2828
fn component_ids(
29-
_components: &mut bevy_ecs::component::ComponentsRegistrator,
30-
) -> impl Iterator<Item = bevy_ecs::component::ComponentId> + use<E, B, M, I> {
29+
_components: &mut crate::component::ComponentsRegistrator,
30+
) -> impl Iterator<Item = crate::component::ComponentId> + use<E, B, M, I> {
3131
// SAFETY: Empty iterator
3232
core::iter::empty()
3333
}
3434

3535
#[inline]
3636
fn get_component_ids(
37-
_components: &bevy_ecs::component::Components,
38-
) -> impl Iterator<Item = Option<bevy_ecs::component::ComponentId>> {
37+
_components: &crate::component::Components,
38+
) -> impl Iterator<Item = Option<crate::component::ComponentId>> {
3939
// SAFETY: Empty iterator
4040
core::iter::empty()
4141
}
@@ -48,8 +48,8 @@ impl<E: EntityEvent, B: Bundle, M, I: IntoObserverSystem<E, B, M>> DynamicBundle
4848

4949
#[inline]
5050
unsafe fn get_components(
51-
ptr: bevy_ecs::ptr::MovingPtr<'_, Self>,
52-
_func: &mut impl FnMut(bevy_ecs::component::StorageType, bevy_ecs::ptr::OwningPtr<'_>),
51+
ptr: crate::ptr::MovingPtr<'_, Self>,
52+
_func: &mut impl FnMut(crate::component::StorageType, crate::ptr::OwningPtr<'_>),
5353
) {
5454
// SAFETY: We must not drop the pointer here, or it will be uninitialized in `apply_effect`
5555
// below.
@@ -58,8 +58,8 @@ impl<E: EntityEvent, B: Bundle, M, I: IntoObserverSystem<E, B, M>> DynamicBundle
5858

5959
#[inline]
6060
unsafe fn apply_effect(
61-
ptr: bevy_ecs::ptr::MovingPtr<'_, mem::MaybeUninit<Self>>,
62-
entity: &mut bevy_ecs::world::EntityWorldMut,
61+
ptr: crate::ptr::MovingPtr<'_, mem::MaybeUninit<Self>>,
62+
entity: &mut crate::world::EntityWorldMut,
6363
) {
6464
// SAFETY: The pointer was not dropped in `get_components`, so the allocation is still
6565
// initialized.

crates/bevy_feathers/src/controls/virtual_keyboard.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use bevy_ecs::observer::observe;
12
use bevy_ecs::prelude::*;
23
use bevy_input_focus::tab_navigation::TabGroup;
34
use bevy_ui::Node;
45
use bevy_ui::Val;
56
use bevy_ui::{widget::Text, FlexDirection};
6-
use bevy_ui_widgets::{observe, Activate};
7+
use bevy_ui_widgets::Activate;
78

89
use crate::controls::{button, ButtonProps};
910

crates/bevy_ui_widgets/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
mod button;
2222
mod checkbox;
2323
mod menu;
24-
mod observe;
2524
pub mod popover;
2625
mod radio;
2726
mod scrollbar;
@@ -30,7 +29,6 @@ mod slider;
3029
pub use button::*;
3130
pub use checkbox::*;
3231
pub use menu::*;
33-
pub use observe::*;
3432
pub use radio::*;
3533
pub use scrollbar::*;
3634
pub use slider::*;

examples/ui/standard_widgets_observers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
use bevy::{
88
color::palettes::basic::*,
9+
ecs::observer::observe,
910
input_focus::{
1011
tab_navigation::{TabGroup, TabIndex, TabNavigationPlugin},
1112
InputDispatchPlugin,
@@ -15,8 +16,8 @@ use bevy::{
1516
reflect::Is,
1617
ui::{Checked, InteractionDisabled, Pressed},
1718
ui_widgets::{
18-
checkbox_self_update, observe, Activate, Button, Checkbox, Slider, SliderRange,
19-
SliderThumb, SliderValue, UiWidgetsPlugins, ValueChange,
19+
checkbox_self_update, Activate, Button, Checkbox, Slider, SliderRange, SliderThumb,
20+
SliderValue, UiWidgetsPlugins, ValueChange,
2021
},
2122
};
2223

examples/ui/virtual_keyboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
33
use bevy::{
44
color::palettes::css::NAVY,
5+
ecs::observer::observe,
56
feathers::{
67
controls::{virtual_keyboard, VirtualKeyPressed},
78
dark_theme::create_dark_theme,
89
theme::UiTheme,
910
FeathersPlugins,
1011
},
1112
prelude::*,
12-
ui_widgets::observe,
1313
};
1414

1515
fn main() {

0 commit comments

Comments
 (0)