-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fractional font width cannot be aligned with itself #791
Comments
…ceil. (#3776) his is in order for text wrapping to have enough space when provided width precisely calculated with CalcTextSize().x. Amend 7b0bf23. Note that the rounding of either positions and widths are technically undesirable (e.g. #3437, #791) but variety of code is currently on it so we are first fixing current behavior before we'll eventually change it.
I think I'm hitting this issue too. Calling GetCharacterAdvance slightly undershoots a monospace font's width, calling CalcTextSize slightly overshoots it. The font I'm running into issues with specifically is Fantasque Sans Mono https://github.com/belluzj/fantasque-sans. But I just wanted to flag this in case it helps nailing down the issue in the future! |
I've bumped into a similar issue. If text is pretty long,
The issue was caused by the following line within // FIXME: This has been here since Dec 2015 (7b0bf230) but down the line we want this out.
// FIXME: Investigate using ceilf or e.g.
// - https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
// - https://embarkstudios.github.io/rust-gpu/api/src/libm/math/ceilf.rs.html
text_size.x = IM_FLOOR(text_size.x + 0.99999f); Apparently for text_size.x==280.0f, the addition of 0.99999f resulted in a number above 281.0f, which doesn't look like proper rounding :). I've fixed it in my copy of ImGui by replacing that cumbersome rounding with a call to Neither is #define IM_FLOOR(_VAL) ((float)(int)(_VAL)) // ImFloor() is not inlined in MSVC debug builds Does ImGui avoid those standard functions for performance reasons? This thread on StackOverflow hints that floor() implementation may be suboptimal: https://stackoverflow.com/questions/824118/why-is-floor-so-slow One of the answers there also gives a better implementation of int c(double x)
{
return (int) x + (x > (int) x);
} Is it time to finally fix this issue? |
When working with monospace font it is common to align different parts using spaces. For example, when one wants to align text "abcd" and "efg", he would usually add a separate space before "efg" like this:
Which will lead to the next output:
However, dear imgui rounds up calculated text width to the pixel border so after rendering space cursor will be at rounded position and "efg" will not be aligned with "bcd". This makes using monospace font pretty awkward.
Originally issue started at emoon/ProDBG#304.
The text was updated successfully, but these errors were encountered: