Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/bevy_ecs/src/observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -26,16 +26,16 @@ unsafe impl<
{
#[inline]
fn component_ids(
_components: &mut bevy_ecs::component::ComponentsRegistrator,
) -> impl Iterator<Item = bevy_ecs::component::ComponentId> + use<E, B, M, I> {
_components: &mut crate::component::ComponentsRegistrator,
) -> impl Iterator<Item = crate::component::ComponentId> + use<E, B, M, I> {
// SAFETY: Empty iterator
core::iter::empty()
}

#[inline]
fn get_component_ids(
_components: &bevy_ecs::component::Components,
) -> impl Iterator<Item = Option<bevy_ecs::component::ComponentId>> {
_components: &crate::component::Components,
) -> impl Iterator<Item = Option<crate::component::ComponentId>> {
// SAFETY: Empty iterator
core::iter::empty()
}
Expand All @@ -48,8 +48,8 @@ impl<E: EntityEvent, B: Bundle, M, I: IntoObserverSystem<E, B, M>> 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.
Expand All @@ -58,8 +58,8 @@ impl<E: EntityEvent, B: Bundle, M, I: IntoObserverSystem<E, B, M>> DynamicBundle

#[inline]
unsafe fn apply_effect(
ptr: bevy_ecs::ptr::MovingPtr<'_, mem::MaybeUninit<Self>>,
entity: &mut bevy_ecs::world::EntityWorldMut,
ptr: crate::ptr::MovingPtr<'_, mem::MaybeUninit<Self>>,
entity: &mut crate::world::EntityWorldMut,
) {
// SAFETY: The pointer was not dropped in `get_components`, so the allocation is still
// initialized.
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_feathers/src/controls/virtual_keyboard.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_ui_widgets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
mod button;
mod checkbox;
mod menu;
mod observe;
pub mod popover;
mod radio;
mod scrollbar;
Expand All @@ -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::*;
Expand Down
5 changes: 3 additions & 2 deletions examples/ui/standard_widgets_observers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use bevy::{
color::palettes::basic::*,
ecs::observer::observe,
input_focus::{
tab_navigation::{TabGroup, TabIndex, TabNavigationPlugin},
InputDispatchPlugin,
Expand All @@ -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,
},
};

Expand Down
2 changes: 1 addition & 1 deletion examples/ui/virtual_keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

use bevy::{
color::palettes::css::NAVY,
ecs::observer::observe,
feathers::{
controls::{virtual_keyboard, VirtualKeyPressed},
dark_theme::create_dark_theme,
theme::UiTheme,
FeathersPlugins,
},
prelude::*,
ui_widgets::observe,
};

fn main() {
Expand Down
Loading