Round text galley sizes to nearest UI point size #4578
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, many labels had non-integer widths. This lead to rounding errors.
This was most notable for the new
Area
sizing code:We would run the initial sizing pass, to measure the size of e.g. a tooltip.
Say the tooltip contains text that was 100.123 ui points wide. With a 16pt border, that becomes 116.123, which is stored in the
Area
state as the width. The next frame, we use that stored size as the wrapping width. With perfect precision, we would then tell the label to wrap to 100.123 pts, which the text would just fit in. However, due to rounding errors we might end up asking it to wrap to 100.122 pts, meaning the last word would now wrap and end up on the next line.By rounding label sizes to perfect integers, we avoid such rounding errors, and most ui elements will now end up on perfect integer point coordinates (and
f32
can precisely express and do arithmetic on all integers < 2^24).Visually this has very little impact. Some labels move by a pixel here and there, mostly for the better.