Skip to content

Commit 47deb90

Browse files
committed
Fill in docs
1 parent 6af2321 commit 47deb90

File tree

36 files changed

+460
-382
lines changed

36 files changed

+460
-382
lines changed

crates/bevy_app/src/app.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,16 +1339,18 @@ impl App {
13391339
/// # };
13401340
/// #
13411341
/// # #[derive(EntityEvent)]
1342-
/// # struct Invite;
1342+
/// # struct Invite {
1343+
/// # entity: Entity,
1344+
/// # }
13431345
/// #
13441346
/// # #[derive(Component)]
13451347
/// # struct Friend;
13461348
/// #
13471349
///
13481350
/// app.add_observer(|event: On<Party>, friends: Query<Entity, With<Friend>>, mut commands: Commands| {
13491351
/// if event.friends_allowed {
1350-
/// for friend in friends.iter() {
1351-
/// commands.trigger_targets(Invite, friend);
1352+
/// for entity in friends.iter() {
1353+
/// commands.trigger(Invite { entity } );
13521354
/// }
13531355
/// }
13541356
/// });

crates/bevy_core_widgets/src/core_button.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use bevy_ecs::system::In;
66
use bevy_ecs::{
77
component::Component,
88
entity::Entity,
9-
event::EntityEvent,
109
observer::On,
1110
query::With,
1211
system::{Commands, Query},

crates/bevy_core_widgets/src/core_checkbox.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,19 @@ fn checkbox_on_pointer_click(
9090
///
9191
/// fn setup(mut commands: Commands) {
9292
/// // Create a checkbox
93-
/// let checkbox = commands.spawn((
93+
/// let entity = commands.spawn((
9494
/// CoreCheckbox::default(),
9595
/// )).id();
9696
///
9797
/// // Set to checked
98-
/// commands.trigger_targets(SetChecked(true), checkbox);
98+
/// commands.trigger(SetChecked { entity, checked: true});
9999
/// }
100100
/// ```
101101
#[derive(EntityEvent)]
102102
pub struct SetChecked {
103+
/// The [`CoreCheckbox`] entity to set the "checked" state on.
103104
pub entity: Entity,
105+
/// Sets the `checked` state to `true` or `false`.
104106
pub checked: bool,
105107
}
106108

@@ -115,12 +117,12 @@ pub struct SetChecked {
115117
///
116118
/// fn setup(mut commands: Commands) {
117119
/// // Create a checkbox
118-
/// let checkbox = commands.spawn((
120+
/// let entity = commands.spawn((
119121
/// CoreCheckbox::default(),
120122
/// )).id();
121123
///
122124
/// // Set to checked
123-
/// commands.trigger_targets(ToggleChecked, checkbox);
125+
/// commands.trigger(ToggleChecked { entity });
124126
/// }
125127
/// ```
126128
#[derive(EntityEvent)]

crates/bevy_core_widgets/src/core_radio.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ fn radio_group_on_button_click(
149149
) {
150150
if let Ok(CoreRadioGroup { on_change }) = q_group.get(ev.entity) {
151151
// Starting with the original target, search upward for a radio button.
152-
let radio_id = if q_radio.contains(ev.original_entity()) {
153-
ev.original_entity()
152+
let radio_id = if q_radio.contains(ev.original_event_target()) {
153+
ev.original_event_target()
154154
} else {
155155
// Search ancestors for the first radio button
156156
let mut found_radio = None;
157-
for ancestor in q_parents.iter_ancestors(ev.original_entity()) {
157+
for ancestor in q_parents.iter_ancestors(ev.original_event_target()) {
158158
if q_group.contains(ancestor) {
159159
// We reached a radio group before finding a radio button, bail out
160160
return;

crates/bevy_core_widgets/src/core_slider.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,27 +488,34 @@ pub(crate) fn slider_on_insert_step(insert: On<Insert, SliderStep>, mut world: D
488488
/// # Example:
489489
///
490490
/// ```
491-
/// use bevy_ecs::system::Commands;
492-
/// use bevy_core_widgets::{CoreSlider, SliderRange, SliderValue, SetSliderValue};
493-
///
491+
/// # use bevy_ecs::system::Commands;
492+
/// # use bevy_core_widgets::{CoreSlider, SliderRange, SliderValue, SetSliderValue, SliderValueChange};
494493
/// fn setup(mut commands: Commands) {
495494
/// // Create a slider
496-
/// let slider = commands.spawn((
495+
/// let entity = commands.spawn((
497496
/// CoreSlider::default(),
498497
/// SliderValue(0.5),
499498
/// SliderRange::new(0.0, 1.0),
500499
/// )).id();
501500
///
502501
/// // Set to an absolute value
503-
/// commands.trigger_targets(SetSliderValue::Absolute(0.75), slider);
502+
/// commands.trigger(SetSliderValue {
503+
/// entity,
504+
/// change: SliderValueChange::Absolute(0.75),
505+
/// });
504506
///
505507
/// // Adjust relatively
506-
/// commands.trigger_targets(SetSliderValue::Relative(-0.25), slider);
508+
/// commands.trigger(SetSliderValue {
509+
/// entity,
510+
/// change: SliderValueChange::Relative(-0.25),
511+
/// });
507512
/// }
508513
/// ```
509514
#[derive(EntityEvent, Clone)]
510515
pub struct SetSliderValue {
516+
/// The slider entity to change.
511517
pub entity: Entity,
518+
/// The change to apply to the slider entity.
512519
pub change: SliderValueChange,
513520
}
514521

crates/bevy_core_widgets/src/lib.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,15 @@ mod core_radio;
2121
mod core_scrollbar;
2222
mod core_slider;
2323

24-
use bevy_app::{PluginGroup, PluginGroupBuilder};
24+
pub use callback::*;
25+
pub use core_button::*;
26+
pub use core_checkbox::*;
27+
pub use core_radio::*;
28+
pub use core_scrollbar::*;
29+
pub use core_slider::*;
2530

31+
use bevy_app::{PluginGroup, PluginGroupBuilder};
2632
use bevy_ecs::entity::Entity;
27-
pub use callback::{Callback, Notify};
28-
pub use core_button::{CoreButton, CoreButtonPlugin};
29-
pub use core_checkbox::{CoreCheckbox, CoreCheckboxPlugin, SetChecked, ToggleChecked};
30-
pub use core_radio::{CoreRadio, CoreRadioGroup, CoreRadioGroupPlugin};
31-
pub use core_scrollbar::{
32-
ControlOrientation, CoreScrollbar, CoreScrollbarDragState, CoreScrollbarPlugin,
33-
CoreScrollbarThumb,
34-
};
35-
pub use core_slider::{
36-
CoreSlider, CoreSliderDragState, CoreSliderPlugin, CoreSliderThumb, SetSliderValue,
37-
SliderPrecision, SliderRange, SliderStep, SliderValue, TrackClick,
38-
};
3933

4034
/// A plugin group that registers the observers for all of the core widgets. If you don't want to
4135
/// use all of the widgets, you can import the individual widget plugins instead.

crates/bevy_ecs/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn reader(mut reader: EventReader<Message>) {
301301

302302
### Observers
303303

304-
Observers are systems that listen for a "trigger" of a specific `Event`:
304+
Observers are systems that watch for a "trigger" of a specific `Event`:
305305

306306
```rust
307307
use bevy_ecs::prelude::*;
@@ -317,8 +317,6 @@ world.add_observer(|event: On<Speak>| {
317317
println!("{}", event.message);
318318
});
319319

320-
world.flush();
321-
322320
world.trigger(Speak {
323321
message: "Hello!".to_string(),
324322
});
@@ -334,19 +332,19 @@ If the event is an `EntityEvent`, it can also be triggered to target specific en
334332
use bevy_ecs::prelude::*;
335333

336334
#[derive(EntityEvent)]
337-
struct Explode;
335+
struct Explode {
336+
entity: Entity,
337+
}
338338

339339
let mut world = World::new();
340340
let entity = world.spawn_empty().id();
341341

342-
world.add_observer(|event: On<Explode>, mut commands: Commands| {
343-
println!("Entity {} goes BOOM!", event.entity());
344-
commands.entity(event.entity()).despawn();
342+
world.add_observer(|explode: On<Explode>, mut commands: Commands| {
343+
println!("Entity {} goes BOOM!", explode.entity);
344+
commands.entity(explode.entity).despawn();
345345
});
346346

347-
world.flush();
348-
349-
world.trigger_targets(Explode, entity);
347+
world.trigger(Explode { entity });
350348
```
351349

352350
[bevy]: https://bevy.org/

crates/bevy_ecs/macros/src/component.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub fn derive_entity_event(input: TokenStream) -> TokenStream {
120120
.into();
121121
}
122122

123-
let entity_field = match get_entity_event_field(&ast) {
123+
let entity_field = match get_event_target_field(&ast) {
124124
Ok(value) => value,
125125
Err(err) => return err.into_compile_error().into(),
126126
};
@@ -143,21 +143,21 @@ pub fn derive_entity_event(input: TokenStream) -> TokenStream {
143143
}
144144

145145
impl #impl_generics #bevy_ecs_path::event::EntityEvent for #struct_name #type_generics #where_clause {
146-
fn entity(&self) -> #bevy_ecs_path::entity::Entity {
146+
fn event_target(&self) -> #bevy_ecs_path::entity::Entity {
147147
self.#entity_field
148148
}
149149

150-
fn entity_mut(&mut self) -> &mut #bevy_ecs_path::entity::Entity {
150+
fn event_target_mut(&mut self) -> &mut #bevy_ecs_path::entity::Entity {
151151
&mut self.#entity_field
152152
}
153153
}
154154

155155
})
156156
}
157157

158-
/// Returns the field with the `#[event_entity]` attribute, the only field if unnamed,
158+
/// Returns the field with the `#[event_target]` attribute, the only field if unnamed,
159159
/// or the field with the name "entity".
160-
fn get_entity_event_field(ast: &DeriveInput) -> Result<Member> {
160+
fn get_event_target_field(ast: &DeriveInput) -> Result<Member> {
161161
let Data::Struct(DataStruct { fields, .. }) = &ast.data else {
162162
return Err(syn::Error::new(
163163
ast.span(),
@@ -169,29 +169,29 @@ fn get_entity_event_field(ast: &DeriveInput) -> Result<Member> {
169169
if field.ident.as_ref().is_some_and(|i| i == "entity") || field
170170
.attrs
171171
.iter()
172-
.any(|attr| attr.path().is_ident(EVENT_ENTITY)) {
172+
.any(|attr| attr.path().is_ident(EVENT_TARGET)) {
173173
Some(Member::Named(field.ident.clone()?))
174174
} else {
175175
None
176176
}
177177
}).ok_or(syn::Error::new(
178178
fields.span(),
179-
"EntityEvent derive expected a field name 'entity' or a field annotated with #[event_entity]."
179+
"EntityEvent derive expected a field name 'entity' or a field annotated with #[event_target]."
180180
)),
181181
Fields::Unnamed(fields) if fields.unnamed.len() == 1 => Ok(Member::Unnamed(Index::from(0))),
182182
Fields::Unnamed(fields) => fields.unnamed.iter().enumerate().find_map(|(index, field)| {
183183
if field
184184
.attrs
185185
.iter()
186-
.any(|attr| attr.path().is_ident(EVENT_ENTITY)) {
186+
.any(|attr| attr.path().is_ident(EVENT_TARGET)) {
187187
Some(Member::Unnamed(Index::from(index)))
188188
} else {
189189
None
190190
}
191191
})
192192
.ok_or(syn::Error::new(
193193
fields.span(),
194-
"EntityEvent derive expected unnamed structs with one field or with a field annotated with #[event_entity].",
194+
"EntityEvent derive expected unnamed structs with one field or with a field annotated with #[event_target].",
195195
)),
196196
Fields::Unit => Err(syn::Error::new(
197197
fields.span(),
@@ -536,7 +536,7 @@ pub const STORAGE: &str = "storage";
536536
pub const REQUIRE: &str = "require";
537537
pub const RELATIONSHIP: &str = "relationship";
538538
pub const RELATIONSHIP_TARGET: &str = "relationship_target";
539-
pub const EVENT_ENTITY: &str = "event_entity";
539+
pub const EVENT_TARGET: &str = "event_target";
540540

541541
pub const ON_ADD: &str = "on_add";
542542
pub const ON_INSERT: &str = "on_insert";

crates/bevy_ecs/macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ pub fn derive_event(input: TokenStream) -> TokenStream {
566566
/// #[entity_event(auto_propagate)]
567567
/// struct MyEvent;
568568
/// ```
569-
#[proc_macro_derive(EntityEvent, attributes(entity_event, event_entity))]
569+
#[proc_macro_derive(EntityEvent, attributes(entity_event, event_target))]
570570
pub fn derive_entity_event(input: TokenStream) -> TokenStream {
571571
component::derive_entity_event(input)
572572
}

crates/bevy_ecs/src/component/tick.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Tick {
8686
}
8787
}
8888

89-
/// An observer [`Event`] that can be used to maintain [`Tick`]s in custom data structures, enabling to make
89+
/// An [`Event`] that can be used to maintain [`Tick`]s in custom data structures, enabling to make
9090
/// use of bevy's periodic checks that clamps ticks to a certain range, preventing overflows and thus
9191
/// keeping methods like [`Tick::is_newer_than`] reliably return `false` for ticks that got too old.
9292
///

0 commit comments

Comments
 (0)