Fix text alignment for unbounded text#17270
Conversation
ickshonpe
left a comment
There was a problem hiding this comment.
Adding a check in update_buffer is exactly what I was thinking of. It's a very simple change and shouldn't affect UI text at all since UI text is always bounded by the size of its UI node.
I don't think we can be fussy about the performance regression, it's only during recomputation and users can manually add TextBounds themselves for anything performance critical.
My other suggestion to do a post-layout relayout and recalculate interaction coords would be a lot more involved and much more complicated and fragile. It isn't worth it, we'd be better off contributing the time to finding an upstream solution in cosmic-text.
Wouldn't expect to see any problems but I checked out all the text examples to be safe and didn't see anything wrong.
# Objective Fixes bevyengine#16783 ## Solution Works around a `cosmic-text` bug or limitation by triggering a re-layout with the calculated width from the first layout run. See linked issue. Credit to @ickshonpe for the clever solution. ## Performance This has a significant performance impact only on unbounded text that are not `JustifyText::Left`, which is still a bit of a bummer because text2d performance in 0.15.1 is already not great. But this seems better than alignment not working. ||many_text2d nfc re|many_text2d nfc re center| |-|-|-| |unbounded-layout-no-fix|3.06|3.10| |unbounded-layout-fix|3.05 ⬜ -0.2%|2.71 🟥 -12.5%| ## Testing I added a centered text to the `text2d` example. `cargo run --example text2d` We should look at other text examples and stress tests. I haven't tested as thoroughly as I would like, so help testing that this doesn't break something in UI would be appreciated.
Fixes #16783 Works around a `cosmic-text` bug or limitation by triggering a re-layout with the calculated width from the first layout run. See linked issue. Credit to @ickshonpe for the clever solution. This has a significant performance impact only on unbounded text that are not `JustifyText::Left`, which is still a bit of a bummer because text2d performance in 0.15.1 is already not great. But this seems better than alignment not working. ||many_text2d nfc re|many_text2d nfc re center| |-|-|-| |unbounded-layout-no-fix|3.06|3.10| |unbounded-layout-fix|3.05 ⬜ -0.2%|2.71 🟥 -12.5%| I added a centered text to the `text2d` example. `cargo run --example text2d` We should look at other text examples and stress tests. I haven't tested as thoroughly as I would like, so help testing that this doesn't break something in UI would be appreciated.
Objective
Fixes #16783
Solution
Works around a
cosmic-textbug or limitation by triggering a re-layout with the calculated width from the first layout run. See linked issue.Credit to @ickshonpe for the clever solution.
Performance
This has a significant performance impact only on unbounded text that are not
JustifyText::Left, which is still a bit of a bummer because text2d performance in 0.15.1 is already not great. But this seems better than alignment not working.Testing
I added a centered text to the
text2dexample.cargo run --example text2dWe should look at other text examples and stress tests. I haven't tested as thoroughly as I would like, so help testing that this doesn't break something in UI would be appreciated.