Round icon position and size in buttons to make them look sharper #63957
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.
I'm not sure if this is a good fix, but it's a naïve one that seems to work for now. For the longest time in 4.0 I've noticed that at an editor scale >100% buttons have blurry icons. It affected all the buttons, but it didn't affect the same icons used in
TextureRect
s, for example. Even though both would render the button at the same size.I'd tried to spot if there is any difference between the approach to submitting a texture to render in
Button
and inTextureRect
, but I could find nothing. I'd checked, and the blurred texture was still the same size as it was supposed to be, just a bit offset. So I assumed that it may be something related to floating point imprecision. I don't see any code that rounds position and scale inTextureRect
, but maybe it just happens by accident because the source values it uses for positioining are already rounded. Not sure.However, when I'd tried to round position and size of icons in buttons, it did help. It can create an uneven offset, because we're dealing with small pixel sizes at this point, but it works as a naïve approach, as I've already mentioned. Maybe there is a way to force pixel snapping for icons in GUI that would work better? I guess this issue would return if your UI element is anchored to some non-integer position, so this is definitely not a cure. But it makes the editor look way better.
So up to reviewers to decide, I guess!
Comparison screenshots (the extra pair of icons on the toolbar are for testing/demo, not a part of the actual UI nor of this PR; but notice how one is blurry and another is sharp in the "before" — the sharp one is TextureRect).
Not sure why button used the
*_region
method there, since it copied the entire size of the original texture anyway. I can revert that part if there is a reason for that.