bevy/crates
ickshonpe 00943f4f08
Growing UI nodes Fix (#8931)
# Objective

fixes #8911, #7712

## Solution

Rounding was added to Taffy which fixed issue #7712.
The implementation uses the f32 `round` method which rounds ties
(fractional part is a half) away from zero. Issue #8911 occurs when a
node's min and max bounds on either axis are "ties" and zero is between
them. Then the bounds are rounded away from each other, and the node
grows by a pixel. This alone shouldn't cause the node to expand
continuously, but I think there is some interaction with the way Taffy
recomputes a layout from its cached data that I didn't identify.

This PR fixes #8911 by first disabling Taffy's internal rounding and
using an alternative rounding function that rounds ties up.
Then, instead of rounding the values of the internal layout tree as
Taffy's built-in rounding does, we leave those values unmodified and
only the values stored in the components are rounded. This requires
walking the tree for the UI node geometry update rather than iterating
through a query.

Because the component values are regenerated each update, that should
mean that UI updates are idempotent (ish) now and make the growing node
behaviour seen in issue #8911 impossible.

I expected a performance regression, but it's an improvement on main:

```
cargo run --profile stress-test --features trace_tracy --example many_buttons
```

<img width="461" alt="ui-rounding-fix-compare"
src="https://github.com/bevyengine/bevy/assets/27962798/914bfd50-e18a-4642-b262-fafa69005432">

I guess it makes sense to do the rounding together with the node size
and position updates.

---

## Changelog

`bevy_ui::layout`:
* Taffy's built-in rounding is disabled and rounding is now performed by
`ui_layout_system`.

* Instead of rounding the values of the internal layout tree as Taffy's
built-in rounding does, we leave those values unmodified and only the
values stored in the components are rounded. This requires walking the
tree for the UI node geometry update rather than iterating through a
query. Because the component values are regenerated each update, that
should mean that UI updates are idempotent now and make the growing node
behaviour seen in issue #8911 impossible.

* Added two helper functions `round_ties_up` and
`round_layout_coordinates`.

---------

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2023-07-09 07:33:22 +00:00
..
bevy_a11y Bump accesskit and accesskit_winit. (#8655) 2023-07-07 22:49:53 +00:00
bevy_animation Register bevy_animation::PlayingAnimation (#9023) 2023-07-04 21:49:53 +00:00
bevy_app Fix not calling App::finish and App::cleanup in ScheduleRunnerPlugin (#9054) 2023-07-09 04:25:12 +00:00
bevy_asset bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
bevy_audio bevy_audio: ECS-based API redesign (#8424) 2023-07-07 23:01:17 +00:00
bevy_core bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
bevy_core_pipeline Fix CAS shader with explicit FullscreenVertexOutput import (#8993) 2023-06-29 19:56:57 +00:00
bevy_derive bevy_derive: Add #[deref] attribute (#8552) 2023-05-16 18:29:09 +00:00
bevy_diagnostic Allow tuples and single plugins in add_plugins, deprecate add_plugin (#8097) 2023-06-21 20:51:03 +00:00
bevy_dylib Suppress the clippy::type_complexity lint (#8313) 2023-04-06 21:27:36 +00:00
bevy_dynamic_plugin Remove stray boilerplate line in bevy_dynamic_plugin/Cargo.toml (#8830) 2023-06-12 19:10:48 +00:00
bevy_ecs Add optional single-threaded feature to bevy_ecs/bevy_tasks (#6690) 2023-07-09 04:22:15 +00:00
bevy_ecs_compile_fail_tests Resolve clippy issues for rust 1.70.0 (#8738) 2023-06-01 21:05:05 +00:00
bevy_encase_derive update syn, encase, glam and hexasphere (#8573) 2023-05-16 01:24:17 +00:00
bevy_gilrs Add gamepad rumble support to bevy_input (#8398) 2023-04-24 15:28:53 +00:00
bevy_gizmos Remove unused shader define (#8981) 2023-07-04 21:38:35 +00:00
bevy_gltf bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
bevy_hierarchy bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
bevy_input bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
bevy_internal Add optional single-threaded feature to bevy_ecs/bevy_tasks (#6690) 2023-07-09 04:22:15 +00:00
bevy_log log to stderr instead of stdout (#8886) 2023-06-19 23:36:02 +00:00
bevy_macro_utils update syn, encase, glam and hexasphere (#8573) 2023-05-16 01:24:17 +00:00
bevy_macros_compile_fail_tests bevy_derive: Add #[deref] attribute (#8552) 2023-05-16 18:29:09 +00:00
bevy_math Add integer equivalents for Rect (#7984) 2023-06-12 19:10:48 +00:00
bevy_mikktspace update syn, encase, glam and hexasphere (#8573) 2023-05-16 01:24:17 +00:00
bevy_pbr Run update_previous_view_projections in PreUpdate schedule (#9024) 2023-07-05 15:51:19 +00:00
bevy_ptr Fixed several missing links in docs. (#8117) 2023-04-23 17:28:36 +00:00
bevy_reflect bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
bevy_reflect_compile_fail_tests bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
bevy_render Remove unused dependency on once_cell in bevy_render (#9039) 2023-07-04 21:30:58 +00:00
bevy_scene bevy_scene: Add SceneFilter (#6793) 2023-07-06 21:04:26 +00:00
bevy_sprite bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
bevy_tasks Add optional single-threaded feature to bevy_ecs/bevy_tasks (#6690) 2023-07-09 04:22:15 +00:00
bevy_text bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
bevy_time bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
bevy_transform bevy_reflect: FromReflect Ergonomics Implementation (#6056) 2023-06-29 01:31:34 +00:00
bevy_ui Growing UI nodes Fix (#8931) 2023-07-09 07:33:22 +00:00
bevy_utils Bump hashbrown to 0.14 (#8904) 2023-06-21 13:04:44 +00:00
bevy_window Expose WindowDestroyed events (#9016) 2023-07-04 21:50:53 +00:00
bevy_winit make accesskit_unix optional again (#9074) 2023-07-08 22:31:30 +00:00