Skip to content
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

Text wrapping: how does it work? #7561

Open
db48x opened this issue May 5, 2024 · 1 comment
Open

Text wrapping: how does it work? #7561

db48x opened this issue May 5, 2024 · 1 comment

Comments

@db48x
Copy link

db48x commented May 5, 2024

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:

Screenshot from 2024-05-05 13-16-30

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();
@db48x
Copy link
Author

db48x commented May 5, 2024

I just found #2313, which asks much the same question. The code in #2313 (comment) seems to work, if I have adapted it correctly to a newer version of Dear ImGui.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants