imgui icon indicating copy to clipboard operation
imgui copied to clipboard

`TextWrapped` looks bad with decimal numbers due to hardcoded separators

Open vittorioromeo opened this issue 11 months ago • 2 comments

Version/Branch of Dear ImGui:

1.91.9b

Back-ends:

Custom VRSFML (SFML Fork) + OpenGL ES 3.x Backend

Compiler, OS:

Windows 11 + MSYS2/UCRT64

Full config/build information:

No response

Details:

When using ImGui::TextWrapped to render text containing decimal numbers, the . character used to separate the integral part from the decimal part is considered as a wrap point, causing the end result to look quite bad as the number can be split across multiple lines.

The same issue occurs with the , character. The only workaround I've found is using the ' character, which looks quite weird, but at least it makes the numbers legible.

A probably-reasonable "fix" would be for the wrapping function to avoid wrapping . and , if both the preceding and succeeding characters are digits.

Screenshots/Video:

Screenshots from my game BubbleByte:

With normal decimal separator

With workaround

Minimal, Complete and Verifiable Example code:

No response

vittorioromeo avatar Mar 20 '25 01:03 vittorioromeo

As an example, this addition to ImFont::CalcWordWrapPositionA solves my problem:

const auto isDigit = [](unsigned int c) { return c >= '0' && c <= '9'; };

if (c == '.' && s+1 < text_end && isDigit(*(s + 1)))
    inside_word = true;

vittorioromeo avatar Mar 20 '25 01:03 vittorioromeo

Linking to #8439 #8139 for text wrapping code.

My problem is that text size calculation is generally very hot path (admittedly wrapped text not as frequent).

I've got another version of the code for the new text function, I might be tempted to backport it, and then as those two new cases in Test Suite and come up with a fix.

ocornut avatar Mar 20 '25 14:03 ocornut