-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add feature to disable text-to-pixel snapping during layout #5057
base: master
Are you sure you want to change the base?
Conversation
## The side effect of such rounding is that text layout will likely be inconsistent across | ||
## different values of `pixel_per_point`. Disabling such "snapping" will make the text fuzzy, | ||
## but the layout will remain constant across `pixels_per_point`. | ||
disable_text_snapping = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a runtime setting instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Let me revise it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, it makes the most sense to add this as a field of LayoutJob
which would default to true
for snapping. That would allow a user like myself to have, e.g., the UI elements all snap while retaining more granular control over a particular layout job. I'm not sure if adding a Struct field is considered a breaking change, so I'd welcome your thoughts on that. Thanks for a great library @emilk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding it to LayoutJob
is the right thing yes
Note that we already have a setting for this, though maybe it is not by the actual text layout engine: https://docs.rs/epaint/latest/epaint/tessellator/struct.TessellationOptions.html#structfield.round_text_to_pixels |
My concerns are primarily around the layout of the text, so I haven't had a chance to investigate the interaction with tesselation, but I will. I'll come back to you. |
Recognizing that a switch to Cosmic Text is on the way per #56 , I also wanted to implement a temporary feature which disables what I call "text snapping"--i.e., where we round to the nearest pixel on the x and y axis when rendering text. This results in text being laid out in different ways across
pixel_per_point
values. Such snapping improves font rendering in the absence of other anti-aliasing approaches which will be provided by Cosmic Text. For some contexts, however, maintaining the layout is more important acrosspixel_per_point
values. This feature allows for that until Cosmic Text saves the day.