Merge branch 'main' into scrollbar_size

This commit is contained in:
ickshonpe 2025-07-15 18:16:08 +01:00 committed by GitHub
commit 829dac66f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 53 additions and 55 deletions

View File

@ -61,7 +61,7 @@ pub fn event_propagation(criterion: &mut Criterion) {
group.finish();
}
#[derive(Event, EntityEvent, Clone, Component)]
#[derive(EntityEvent, Clone, Component)]
#[entity_event(traversal = &'static ChildOf, auto_propagate)]
struct TestEvent<const N: usize> {}

View File

@ -1,7 +1,7 @@
use core::hint::black_box;
use bevy_ecs::{
event::{EntityEvent, Event},
event::EntityEvent,
observer::{On, TriggerTargets},
world::World,
};
@ -13,7 +13,7 @@ fn deterministic_rand() -> ChaCha8Rng {
ChaCha8Rng::seed_from_u64(42)
}
#[derive(Clone, Event, EntityEvent)]
#[derive(Clone, EntityEvent)]
struct EventBase;
pub fn observe_simple(criterion: &mut Criterion) {

View File

@ -1534,7 +1534,7 @@ mod tests {
use super::*;
#[derive(Event, EntityEvent, Reflect, Clone)]
#[derive(EntityEvent, Reflect, Clone)]
struct A;
#[track_caller]

View File

@ -1325,7 +1325,7 @@ impl App {
/// # friends_allowed: bool,
/// # };
/// #
/// # #[derive(Event, EntityEvent)]
/// # #[derive(EntityEvent)]
/// # struct Invite;
/// #
/// # #[derive(Component)]

View File

@ -1,7 +1,7 @@
use accesskit::Role;
use bevy_a11y::AccessibilityNode;
use bevy_app::{App, Plugin};
use bevy_ecs::event::{EntityEvent, Event};
use bevy_ecs::event::EntityEvent;
use bevy_ecs::query::{Has, Without};
use bevy_ecs::system::{In, ResMut};
use bevy_ecs::{
@ -97,7 +97,7 @@ fn checkbox_on_pointer_click(
/// commands.trigger_targets(SetChecked(true), checkbox);
/// }
/// ```
#[derive(Event, EntityEvent)]
#[derive(EntityEvent)]
pub struct SetChecked(pub bool);
/// Event which can be triggered on a checkbox to toggle the checked state. This can be used to
@ -119,7 +119,7 @@ pub struct SetChecked(pub bool);
/// commands.trigger_targets(ToggleChecked, checkbox);
/// }
/// ```
#[derive(Event, EntityEvent)]
#[derive(EntityEvent)]
pub struct ToggleChecked;
fn checkbox_on_set_checked(

View File

@ -3,7 +3,7 @@ use core::ops::RangeInclusive;
use accesskit::{Orientation, Role};
use bevy_a11y::AccessibilityNode;
use bevy_app::{App, Plugin};
use bevy_ecs::event::{EntityEvent, Event};
use bevy_ecs::event::EntityEvent;
use bevy_ecs::hierarchy::Children;
use bevy_ecs::lifecycle::Insert;
use bevy_ecs::query::Has;
@ -498,7 +498,7 @@ pub(crate) fn slider_on_insert_step(trigger: On<Insert, SliderStep>, mut world:
/// commands.trigger_targets(SetSliderValue::Relative(-0.25), slider);
/// }
/// ```
#[derive(Event, EntityEvent, Clone)]
#[derive(EntityEvent, Clone)]
pub enum SetSliderValue {
/// Set the slider value to a specific value.
Absolute(f32),

View File

@ -333,7 +333,7 @@ If the event is an `EntityEvent`, it can also be triggered to target specific en
```rust
use bevy_ecs::prelude::*;
#[derive(Event, EntityEvent)]
#[derive(EntityEvent)]
struct Explode;
let mut world = World::new();

View File

@ -73,6 +73,7 @@ pub fn derive_entity_event(input: TokenStream) -> TokenStream {
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
TokenStream::from(quote! {
impl #impl_generics #bevy_ecs_path::event::Event for #struct_name #type_generics #where_clause {}
impl #impl_generics #bevy_ecs_path::event::EntityEvent for #struct_name #type_generics #where_clause {
type Traversal = #traversal;
const AUTO_PROPAGATE: bool = #auto_propagate;

View File

@ -557,7 +557,7 @@ pub fn derive_event(input: TokenStream) -> TokenStream {
/// see full explanation on `EntityEvent` trait docs.
///
/// ```ignore
/// #[derive(Event, EntityEvent)]
/// #[derive(EntityEvent)]
/// /// Traversal component
/// #[entity_event(traversal = &'static ChildOf)]
/// /// Always propagate

View File

@ -150,7 +150,7 @@ pub trait Event: Send + Sync + 'static {
/// # use bevy_ecs::prelude::*;
/// #
/// // When the `Damage` event is triggered on an entity, bubble the event up to ancestors.
/// #[derive(Event, EntityEvent)]
/// #[derive(EntityEvent)]
/// #[entity_event(traversal = &'static ChildOf, auto_propagate)]
/// struct Damage {
/// amount: f32,
@ -162,7 +162,7 @@ pub trait Event: Send + Sync + 'static {
/// ```
/// # use bevy_ecs::prelude::*;
/// #
/// # #[derive(Event, EntityEvent)]
/// # #[derive(EntityEvent)]
/// # #[entity_event(traversal = &'static ChildOf, auto_propagate)]
/// # struct Damage {
/// # amount: f32,
@ -201,7 +201,7 @@ pub trait Event: Send + Sync + 'static {
/// ```
/// # use bevy_ecs::prelude::*;
/// #
/// # #[derive(Event, EntityEvent)]
/// # #[derive(EntityEvent)]
/// # #[entity_event(traversal = &'static ChildOf, auto_propagate)]
/// # struct Damage {
/// # amount: f32,
@ -242,7 +242,7 @@ pub trait Event: Send + Sync + 'static {
#[diagnostic::on_unimplemented(
message = "`{Self}` is not an `EntityEvent`",
label = "invalid `EntityEvent`",
note = "consider annotating `{Self}` with `#[derive(Event, EntityEvent)]`"
note = "consider annotating `{Self}` with `#[derive(EntityEvent)]`"
)]
pub trait EntityEvent: Event {
/// The component that describes which [`Entity`] to propagate this event to next, when [propagation] is enabled.

View File

@ -54,8 +54,8 @@ use crate::{
component::{Component, ComponentId, ComponentIdFor, Tick},
entity::Entity,
event::{
BufferedEvent, EntityEvent, Event, EventCursor, EventId, EventIterator,
EventIteratorWithId, EventKey, Events,
BufferedEvent, EntityEvent, EventCursor, EventId, EventIterator, EventIteratorWithId,
EventKey, Events,
},
query::FilteredAccessSet,
relationship::RelationshipHookMode,
@ -328,7 +328,7 @@ pub const DESPAWN: EventKey = EventKey(ComponentId::new(4));
/// Trigger emitted when a component is inserted onto an entity that does not already have that
/// component. Runs before `Insert`.
/// See [`crate::lifecycle::ComponentHooks::on_add`] for more information.
#[derive(Event, EntityEvent, Debug, Clone)]
#[derive(EntityEvent, Debug, Clone)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
#[cfg_attr(feature = "bevy_reflect", reflect(Debug))]
#[doc(alias = "OnAdd")]
@ -337,7 +337,7 @@ pub struct Add;
/// Trigger emitted when a component is inserted, regardless of whether or not the entity already
/// had that component. Runs after `Add`, if it ran.
/// See [`crate::lifecycle::ComponentHooks::on_insert`] for more information.
#[derive(Event, EntityEvent, Debug, Clone)]
#[derive(EntityEvent, Debug, Clone)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
#[cfg_attr(feature = "bevy_reflect", reflect(Debug))]
#[doc(alias = "OnInsert")]
@ -348,7 +348,7 @@ pub struct Insert;
///
/// Runs before the value is replaced, so you can still access the original component data.
/// See [`crate::lifecycle::ComponentHooks::on_replace`] for more information.
#[derive(Event, EntityEvent, Debug, Clone)]
#[derive(EntityEvent, Debug, Clone)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
#[cfg_attr(feature = "bevy_reflect", reflect(Debug))]
#[doc(alias = "OnReplace")]
@ -357,7 +357,7 @@ pub struct Replace;
/// Trigger emitted when a component is removed from an entity, and runs before the component is
/// removed, so you can still access the component data.
/// See [`crate::lifecycle::ComponentHooks::on_remove`] for more information.
#[derive(Event, EntityEvent, Debug, Clone)]
#[derive(EntityEvent, Debug, Clone)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
#[cfg_attr(feature = "bevy_reflect", reflect(Debug))]
#[doc(alias = "OnRemove")]
@ -365,7 +365,7 @@ pub struct Remove;
/// Trigger emitted for each component on an entity when it is despawned.
/// See [`crate::lifecycle::ComponentHooks::on_despawn`] for more information.
#[derive(Event, EntityEvent, Debug, Clone)]
#[derive(EntityEvent, Debug, Clone)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
#[cfg_attr(feature = "bevy_reflect", reflect(Debug))]
#[doc(alias = "OnDespawn")]

View File

@ -131,7 +131,7 @@ use crate::prelude::ReflectComponent;
/// # use bevy_ecs::prelude::*;
/// # let mut world = World::default();
/// # let entity = world.spawn_empty().id();
/// #[derive(Event, EntityEvent)]
/// #[derive(EntityEvent)]
/// struct Explode;
///
/// world.add_observer(|trigger: On<Explode>, mut commands: Commands| {
@ -151,7 +151,7 @@ use crate::prelude::ReflectComponent;
/// # let mut world = World::default();
/// # let e1 = world.spawn_empty().id();
/// # let e2 = world.spawn_empty().id();
/// # #[derive(Event, EntityEvent)]
/// # #[derive(EntityEvent)]
/// # struct Explode;
/// world.trigger_targets(Explode, [e1, e2]);
/// ```
@ -165,7 +165,7 @@ use crate::prelude::ReflectComponent;
/// # let mut world = World::default();
/// # let e1 = world.spawn_empty().id();
/// # let e2 = world.spawn_empty().id();
/// # #[derive(Event, EntityEvent)]
/// # #[derive(EntityEvent)]
/// # struct Explode;
/// world.entity_mut(e1).observe(|trigger: On<Explode>, mut commands: Commands| {
/// println!("Boom!");
@ -187,7 +187,7 @@ use crate::prelude::ReflectComponent;
/// # use bevy_ecs::prelude::*;
/// # let mut world = World::default();
/// # let entity = world.spawn_empty().id();
/// # #[derive(Event, EntityEvent)]
/// # #[derive(EntityEvent)]
/// # struct Explode;
/// let mut observer = Observer::new(|trigger: On<Explode>| {});
/// observer.watch_entity(entity);

View File

@ -72,18 +72,14 @@ fn component_clone_observed_by(_source: &SourceComponent, ctx: &mut ComponentClo
#[cfg(test)]
mod tests {
use crate::{
entity::EntityCloner,
event::{EntityEvent, Event},
observer::On,
resource::Resource,
system::ResMut,
entity::EntityCloner, event::EntityEvent, observer::On, resource::Resource, system::ResMut,
world::World,
};
#[derive(Resource, Default)]
struct Num(usize);
#[derive(Event, EntityEvent)]
#[derive(EntityEvent)]
struct E;
#[test]

View File

@ -521,10 +521,10 @@ mod tests {
#[component(storage = "SparseSet")]
struct S;
#[derive(Event, EntityEvent)]
#[derive(EntityEvent)]
struct EventA;
#[derive(Event, EntityEvent)]
#[derive(EntityEvent)]
struct EventWithData {
counter: usize,
}
@ -548,7 +548,7 @@ mod tests {
}
}
#[derive(Component, Event, EntityEvent)]
#[derive(Component, EntityEvent)]
#[entity_event(traversal = &'static ChildOf, auto_propagate)]
struct EventPropagating;

View File

@ -83,7 +83,7 @@ impl<'w, E, B: Bundle> On<'w, E, B> {
/// ```rust
/// # use bevy_ecs::prelude::*;
///
/// #[derive(Event, EntityEvent)]
/// #[derive(EntityEvent)]
/// struct AssertEvent;
///
/// fn assert_observer(trigger: On<AssertEvent>) {

View File

@ -5861,7 +5861,7 @@ mod tests {
assert_eq!((&mut X(8), &mut Y(9)), (x_component, y_component));
}
#[derive(Event, EntityEvent)]
#[derive(EntityEvent)]
struct TestEvent;
#[test]

View File

@ -137,7 +137,7 @@ pub struct InputFocusVisible(pub bool);
///
/// To set up your own bubbling input event, add the [`dispatch_focused_input::<MyEvent>`](dispatch_focused_input) system to your app,
/// in the [`InputFocusSystems::Dispatch`] system set during [`PreUpdate`].
#[derive(Event, EntityEvent, Clone, Debug, Component)]
#[derive(EntityEvent, Clone, Debug, Component)]
#[entity_event(traversal = WindowTraversal, auto_propagate)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Component, Clone))]
pub struct FocusedInput<E: BufferedEvent + Clone> {
@ -149,7 +149,7 @@ pub struct FocusedInput<E: BufferedEvent + Clone> {
/// An event which is used to set input focus. Trigger this on an entity, and it will bubble
/// until it finds a focusable entity, and then set focus to it.
#[derive(Clone, Event, EntityEvent)]
#[derive(Clone, EntityEvent)]
#[entity_event(traversal = WindowTraversal, auto_propagate)]
pub struct AcquireFocus {
/// The primary window entity.

View File

@ -59,7 +59,7 @@ use crate::{
///
/// The documentation for the [`pointer_events`] explains the events this module exposes and
/// the order in which they fire.
#[derive(Event, BufferedEvent, EntityEvent, Clone, PartialEq, Debug, Reflect, Component)]
#[derive(BufferedEvent, EntityEvent, Clone, PartialEq, Debug, Reflect, Component)]
#[entity_event(traversal = PointerTraversal, auto_propagate)]
#[reflect(Component, Debug, Clone)]
pub struct Pointer<E: Debug + Clone + Reflect> {

View File

@ -15,6 +15,7 @@ use async_channel::{Receiver, Sender};
use bevy_app::{App, Plugin};
use bevy_asset::Handle;
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::schedule::IntoScheduleConfigs;
use bevy_ecs::{
change_detection::ResMut,
entity::Entity,
@ -22,7 +23,6 @@ use bevy_ecs::{
prelude::{Component, Resource, World},
system::{Query, Res},
};
use bevy_ecs::{event::Event, schedule::IntoScheduleConfigs};
use bevy_image::{Image, TextureFormatPixelInfo};
use bevy_platform::collections::HashMap;
use bevy_reflect::Reflect;
@ -111,7 +111,7 @@ impl Readback {
///
/// The event contains the data as a `Vec<u8>`, which can be interpreted as the raw bytes of the
/// requested buffer or texture.
#[derive(Event, EntityEvent, Deref, DerefMut, Reflect, Debug)]
#[derive(EntityEvent, Deref, DerefMut, Reflect, Debug)]
#[reflect(Debug)]
pub struct ReadbackComplete(pub Vec<u8>);

View File

@ -40,7 +40,7 @@ use std::{
use tracing::{error, info, warn};
use wgpu::{CommandEncoder, Extent3d, TextureFormat};
#[derive(Event, EntityEvent, Deref, DerefMut, Reflect, Debug)]
#[derive(EntityEvent, Deref, DerefMut, Reflect, Debug)]
#[reflect(Debug)]
pub struct ScreenshotCaptured(pub Image);

View File

@ -2,7 +2,7 @@ use crate::{DynamicScene, Scene};
use bevy_asset::{AssetEvent, AssetId, Assets, Handle};
use bevy_ecs::{
entity::{Entity, EntityHashMap},
event::{EntityEvent, Event, EventCursor, Events},
event::{EntityEvent, EventCursor, Events},
hierarchy::ChildOf,
reflect::AppTypeRegistry,
resource::Resource,
@ -21,12 +21,13 @@ use bevy_ecs::{
prelude::{Changed, Component, Without},
system::{Commands, Query},
};
/// Triggered on a scene's parent entity when [`crate::SceneInstance`] becomes ready to use.
///
/// See also [`On`], [`SceneSpawner::instance_is_ready`].
///
/// [`On`]: bevy_ecs::observer::On
#[derive(Clone, Copy, Debug, Eq, PartialEq, Event, EntityEvent, Reflect)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, EntityEvent, Reflect)]
#[reflect(Debug, PartialEq, Clone)]
pub struct SceneInstanceReady {
/// Instance which has been spawned.

View File

@ -37,7 +37,7 @@ struct Animations {
graph_handle: Handle<AnimationGraph>,
}
#[derive(Event, EntityEvent, Reflect, Clone)]
#[derive(EntityEvent, Reflect, Clone)]
struct OnStep;
fn observe_on_step(

View File

@ -18,7 +18,7 @@ fn main() {
#[derive(Component)]
struct MessageText;
#[derive(Event, EntityEvent, Clone)]
#[derive(EntityEvent, Clone)]
struct MessageEvent {
value: String,
color: Color,

View File

@ -53,7 +53,7 @@ fn setup(mut commands: Commands) {
// - **auto_propagate:**
// We can also choose whether or not this event will propagate by default when triggered. If this is
// false, it will only propagate following a call to `On::propagate(true)`.
#[derive(Clone, Component, Event, EntityEvent)]
#[derive(Clone, Component, EntityEvent)]
#[entity_event(traversal = &'static ChildOf, auto_propagate)]
struct Attack {
damage: u16,

View File

@ -60,13 +60,13 @@ impl Mine {
}
}
#[derive(Event, EntityEvent)]
#[derive(Event)]
struct ExplodeMines {
pos: Vec2,
radius: f32,
}
#[derive(Event, EntityEvent)]
#[derive(EntityEvent)]
struct Explode;
fn setup(mut commands: Commands) {

View File

@ -106,7 +106,7 @@ struct DelayedComponentTimer(Timer);
#[component(immutable)]
struct DelayedComponent<B: Bundle>(B);
#[derive(Event, EntityEvent)]
#[derive(EntityEvent)]
struct Unwrap;
fn tick_timers(

View File

@ -50,7 +50,7 @@ fn send_scroll_events(
}
/// UI scrolling event.
#[derive(Event, EntityEvent, Debug)]
#[derive(EntityEvent, Debug)]
#[entity_event(auto_propagate, traversal = &'static ChildOf)]
struct Scroll {
/// Scroll delta in logical coordinates.

View File

@ -57,12 +57,12 @@ commands.trigger(Speak {
});
```
To allow an event to be targeted at entities and even propagated further, you can also derive `EntityEvent`.
To allow an event to be targeted at entities and even propagated further, you can instead derive `EntityEvent`.
It supports optionally specifying some options for propagation using the `event` attribute:
```rust
// When the `Damage` event is triggered on an entity, bubble the event up to ancestors.
#[derive(Event, EntityEvent)]
#[derive(EntityEvent)]
#[entity_event(traversal = &'static ChildOf, auto_propagate)]
struct Damage {
amount: f32,