mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 06:00:20 +00:00
05d90686fc
# Objective Taffy added layout rounding a while ago but it had a couple of bugs and caused some problems with the fussy `ab_glyph` text implementation. So I disabled Taffy's builtin rounding and added some hacks ad hoc that fixed (some) of those issues. Since then though Taffy's rounding algorithm has improved while we've changed layout a lot and migrated to `cosmic-text` so those hacks don't help any more and in some cases cause significant problems. Also our rounding implementation only rounds to the nearest logical pixel, whereas Taffy rounds to the nearest physical pixel meaning it's much more accurate with high dpi displays. fixes #15197 ## Some examples of layout rounding errors visible in the UI examples These errors are much more obvious at high scale factor, you might not see any problems at a scale factor of 1. `cargo run --example text_wrap_debug` <img width="1000" alt="text_debug_gaps" src="https://github.com/user-attachments/assets/5a584016-b8e2-487b-8842-f0f359077391"> The narrow horizontal and vertical lines are gaps in the layout caused by errors in the coordinate rounding. `cargo run --example text_debug` <img width="1000" alt="text_debug" src="https://github.com/user-attachments/assets/a4b37c02-a2fd-441c-a7bd-cd7a1a72e7dd"> The two text blocks here are aligned right to the same boundary but in this screen shot you can see that the lower block is one pixel off to the left. Because the size of this text node changes between frames with the reported framerate the rounding errors cause it to jump left and right. ## Solution Remove all our custom rounding hacks and reenable Taffy's layout rounding. The gaps in the `text_wrap_debug` example are gone: <img width="1000" alt="text_wrap_debug_fix" src="https://github.com/user-attachments/assets/92d2dd97-30c6-4ac8-99f1-6d65358995a7"> This doesn't fix some of the gaps that occur between borders and content but they seem appear to be a rendering problem as they disappear with `UiAntiAlias::Off` set. ## Testing Run the examples as described above in the `Objective` section. With this PR the problems mentioned shouldn't appear. Also added an example in a separate PR #16096 `layout_rounding_debug` for identifying these issues. ## Migration Guide `UiSurface::get_layout` now also returns the final sizes before rounding. Call `.0` on the `Ok` result to get the previously returned `taffy::Layout` value. --------- Co-authored-by: Rob Parrett <robparrett@gmail.com> |
||
---|---|---|
.. | ||
bevy_a11y | ||
bevy_animation | ||
bevy_app | ||
bevy_asset | ||
bevy_audio | ||
bevy_color | ||
bevy_core | ||
bevy_core_pipeline | ||
bevy_derive | ||
bevy_dev_tools | ||
bevy_diagnostic | ||
bevy_dylib | ||
bevy_ecs | ||
bevy_encase_derive | ||
bevy_gilrs | ||
bevy_gizmos | ||
bevy_gltf | ||
bevy_hierarchy | ||
bevy_image | ||
bevy_input | ||
bevy_internal | ||
bevy_log | ||
bevy_macro_utils | ||
bevy_math | ||
bevy_mesh | ||
bevy_mikktspace | ||
bevy_pbr | ||
bevy_picking | ||
bevy_ptr | ||
bevy_reflect | ||
bevy_remote | ||
bevy_render | ||
bevy_scene | ||
bevy_sprite | ||
bevy_state | ||
bevy_tasks | ||
bevy_text | ||
bevy_time | ||
bevy_transform | ||
bevy_ui | ||
bevy_utils | ||
bevy_window | ||
bevy_winit |