imgui
imgui copied to clipboard
Text wrapping: how does it work?
Version/Branch of Dear ImGui:
Version 1.89.6, Branch: master
Back-ends:
imgui_impl_sdl2.cpp
Compiler, OS:
gcc (GCC) 11.3.0, Linux
Full config/build information:
Dear ImGui 1.89.6 (18960)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201703
define: __linux__
define: __GNUC__=11
--------------------------------
io.BackendPlatformName: imgui_impl_sdl2
io.BackendRendererName: imgui_impl_sdlrenderer2
io.ConfigFlags: 0x00000003
NavEnableKeyboard
NavEnableGamepad
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000000E
HasMouseCursors
HasSetMousePos
RendererHasVtxOffset
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,256
io.DisplaySize: 1920.00,1080.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00
Details:
I am trying to wrap a paragraph of text in the usual manner, except that the paragraph has some color in the middle. The result is that each of the segments of text are wrapped separately, rather than as a whole paragraph.
Am I misunderstanding the API? Is there documentation that explains how wrapping actually works?
Screenshots/Video:
Minimal, Complete and Verifiable Example code:
ImGui::SetNextWindowSize( { 500, 300 }, ImGuiCond_Once );
if( ImGui::Begin( "test" ) ) {
// three sentences in a nicely–wrapped paragraph
ImGui::TextWrapped( "%s", "Some long text that will wrap around nicely. Some red text in the middle. Some long text that will wrap around nicely." );
ImGui::NewLine();
// same three sentences, but the color breaks the wrapping
ImGui::PushTextWrapPos( 0 );
ImGui::TextUnformatted( "Some long text that will wrap around nicely." );
ImGui::SameLine();
ImGui::TextColored( c_red, "%s", "Some red text in the middle." );
ImGui::SameLine();
ImGui::TextUnformatted( "Some long text that will wrap around nicely." );
ImGui::PopTextWrapPos();
}
ImGui::End();
I just found #2313, which asks much the same question. The code in https://github.com/ocornut/imgui/issues/2313#issuecomment-458084296 seems to work, if I have adapted it correctly to a newer version of Dear ImGui.