bevy/examples/ui
Alice Cecile b7d2cb8547
Provide access to the original target of entity-events in observers (#19663)
# Objective

Getting access to the original target of an entity-event is really
helpful when working with bubbled / propagated events.

`bevy_picking` special-cases this, but users have requested this for all
sorts of bubbled events.

The existing naming convention was also very confusing. Fixes
https://github.com/bevyengine/bevy/issues/17112, but also see #18982.

## Solution

1. Rename `ObserverTrigger::target` -> `current_target`.
1. Store `original_target: Option<Entity>` in `ObserverTrigger`.
1. Wire it up so this field gets set correctly.
1. Remove the `target` field on the `Pointer` events from
`bevy_picking`.

Closes https://github.com/bevyengine/bevy/pull/18710, which attempted
the same thing. Thanks @emfax!

## Testing

I've modified an existing test to check that the entities returned
during event bubbling / propagation are correct.

## Notes to reviewers

It's a little weird / sad that you can no longer access this infromation
via the buffered events for `Pointer`. That said, you already couldn't
access any bubbled target. We should probably remove the `BufferedEvent`
form of `Pointer` to reduce confusion and overhead, but I didn't want to
do so here.

Observer events can be trivially converted into buffered events (write
an observer with an EventWriter), and I suspect that that is the better
migration if you want the controllable timing or performance
characteristics of buffered events for your specific use case.

## Future work

It would be nice to not store this data at all (and not expose any
methods) if propagation was disabled. That involves more trait
shuffling, and I don't think we should do it here for reviewability.

---------

Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
2025-06-15 20:53:25 +00:00
..
borders.rs separate border colors (#18682) 2025-05-26 16:57:13 +00:00
box_shadow.rs Minor refactoring of box_shadow example (#19404) 2025-05-27 23:44:32 +00:00
button.rs separate border colors (#18682) 2025-05-26 16:57:13 +00:00
core_widgets_observers.rs Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
core_widgets.rs Core slider (#19584) 2025-06-15 00:53:31 +00:00
directional_navigation.rs Provide access to the original target of entity-events in observers (#19663) 2025-06-15 20:53:25 +00:00
display_and_visibility.rs Rename JustifyText to Justify (#19522) 2025-06-09 19:59:48 +00:00
flex_layout.rs
font_atlas_debug.rs
ghost_nodes.rs separate border colors (#18682) 2025-05-26 16:57:13 +00:00
gradients.rs Gradients example: Fit in initial window (#19520) 2025-06-08 17:26:02 +00:00
grid.rs
overflow_clip_margin.rs separate border colors (#18682) 2025-05-26 16:57:13 +00:00
overflow_debug.rs Specialized UI transform (#16615) 2025-06-09 19:05:49 +00:00
overflow.rs separate border colors (#18682) 2025-05-26 16:57:13 +00:00
relative_cursor_position.rs Specialized UI transform (#16615) 2025-06-09 19:05:49 +00:00
render_ui_to_texture.rs Rename TargetCamera to UiTargetCamera (#17403) 2025-01-19 19:56:57 +00:00
scroll.rs Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
size_constraints.rs Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
stacked_gradients.rs Rename Position to UiPosition in bevy_ui (#19422) 2025-05-29 14:52:44 +00:00
tab_navigation.rs Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
text_background_colors.rs Rename JustifyText to Justify (#19522) 2025-06-09 19:59:48 +00:00
text_debug.rs Rename JustifyText to Justify (#19522) 2025-06-09 19:59:48 +00:00
text_wrap_debug.rs Rename JustifyText to Justify (#19522) 2025-06-09 19:59:48 +00:00
text.rs Rename JustifyText to Justify (#19522) 2025-06-09 19:59:48 +00:00
transparency_ui.rs
ui_material.rs
ui_scaling.rs Rename Timer::finished and Timer::paused to is_finished and is_paused (#19386) 2025-05-27 22:24:18 +00:00
ui_texture_atlas_slice.rs
ui_texture_atlas.rs
ui_texture_slice_flip_and_tile.rs
ui_texture_slice.rs
ui_transform.rs Specialized UI transform (#16615) 2025-06-09 19:05:49 +00:00
viewport_debug.rs separate border colors (#18682) 2025-05-26 16:57:13 +00:00
viewport_node.rs Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
window_fallthrough.rs
z_index.rs