imgui icon indicating copy to clipboard operation
imgui copied to clipboard

CalcWordWrapPosition does not deal with `...` correctly

Open aardappel opened this issue 1 month ago • 5 comments

Version/Branch of Dear ImGui:

docking branch 8f3f428 of 2025-10-03

Back-ends:

SDL2 + OpenGL3

Compiler, OS:

Win11 + MSVC 2022

Full config/build information:

No response

Details:

This is very tiny issue, feel free to delete if not worth addressing :)

CalcWordWrapPosition seems to treat . as end of sentence even when there's multiple dots, like for example... this! would get split up as for example. .. this!. Having it split as for example... this! would be nicer.

A related issue is that if you use this code to split and later re-concatenate you'll end up with a space between . and .. as you have no way of telling there wasn't one.

Looks like this code would need to get more complicated:

            // Allow wrapping after punctuation.
            inside_word = (c != '.' && c != ',' && c != ';' && c != '!' && c != '?' && c != '\"' && c != 0x3001 && c != 0x3002);

Frankly, simply requiring a space after punctuation would be both simpler and more predictable, I hope there is not a lot of people that write text like,this.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

aardappel avatar Nov 25 '25 18:11 aardappel

This is known by ocornut and is mentioned many times: https://github.com/ocornut/imgui/issues/9066#issuecomment-3527701341

Currently proposed fixes and tests are here: https://github.com/ocornut/imgui/issues/9066#issuecomment-3571146851

cyx2015s avatar Nov 26 '25 01:11 cyx2015s

Ah sorry, did not find those in my search. Feel free to close this one if formatting like ... is also captured in those (mostly see i18n concerns).

aardappel avatar Nov 26 '25 02:11 aardappel

Yes, it will break like for example... this! in this fix1, no weird break in consecutive punctuations or a weird space at the start of line.

Image 2

1: If his optimization did not change my wrapping behavior 2. Text boundary calculation changed and now take trailing space into consideration.

I don't have the right to close a issue but we'd like to see more people to test https://github.com/xuboying/imgui (no docking branch though). The new wrapping function is named CalcWordWrapPositionCJK and you need to manually replace it.

cyx2015s avatar Nov 26 '25 04:11 cyx2015s

Fixing a case like this is probably going to happen sooner or faster than doing wider fixes for international languages, so we can keep this open.

ocornut avatar Nov 26 '25 10:11 ocornut

@aardappel As a general answer to your (valid) inquiries about word-wrapping: as you are displaying user facing text and this is presumably a problem for you now, honestly my recommendation would be to rewrite the function however you like and rebase your patch when you update. When you get the hang of git features this should be trivial. Your changes will be isolated to that one function and for the amount of text you have you'll have very little difficulty tweaking the wrapping code.

ocornut avatar Dec 01 '25 12:12 ocornut

I should have fixed this with 22ffa3d + a5dffbe (It's been not trivial to preserve performances, it's actually now a little bit faster in non-optimized builds). See the current test cases at https://github.com/ocornut/imgui/issues/8990#issuecomment-3675947978.

ocornut avatar Dec 21 '25 17:12 ocornut