Commit f572ad9
Directional navigation now considers UiTransform rotation (#22399)
# Objective
Fixes #22234
The directional navigation system was ignoring `UiTransform` rotation
and scaling when calculating which node to navigate to. This caused
navigation to select incorrect nodes when they were rotated or scaled,
because the system used unrotated layout positions instead of the visual
positions seen by users.
## Solution
- Added `get_rotated_bounds()` helper function to calculate the
axis-aligned bounding box of a rotated rectangle
- Updated `get_navigable_nodes()` to apply both rotation and scale
transforms from `UiGlobalTransform` when creating `FocusableArea`
structs
- Updated `entity_to_camera_and_focusable_area()` to apply rotation and
scale transforms
- Used `bevy_math::ops` instead of `f32` methods for deterministic
trigonometry
The fix ensures that directional navigation uses the visual position of
nodes (after transforms) rather than just the layout position, so users
navigate to the button they actually see on screen.
## Testing
- Tested with `auto_directional_navigation` example - navigation works
correctly with scattered button layouts

---------
Co-authored-by: Carter Anderson <[email protected]>1 parent cd977df commit f572ad9
2 files changed
Lines changed: 32 additions & 7 deletions
File tree
- crates/bevy_ui/src
- examples/ui
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
188 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
192 | | - | |
| 193 | + | |
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
| |||
212 | 213 | | |
213 | 214 | | |
214 | 215 | | |
215 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
216 | 219 | | |
217 | 220 | | |
218 | 221 | | |
219 | 222 | | |
220 | 223 | | |
221 | | - | |
| 224 | + | |
222 | 225 | | |
223 | 226 | | |
224 | 227 | | |
| |||
228 | 231 | | |
229 | 232 | | |
230 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
213 | 222 | | |
214 | 223 | | |
215 | 224 | | |
| |||
225 | 234 | | |
226 | 235 | | |
227 | 236 | | |
| 237 | + | |
228 | 238 | | |
229 | 239 | | |
230 | 240 | | |
| |||
0 commit comments