Skip to content

Text wrapping: the current wrapping is not ideal for punctuations in some cases #8139

Open
@achabense

Description

Version/Branch of Dear ImGui:

Version 1.91.2

Back-ends:

imgui_impl_sdl2.cpp + imgui_impl_sdlrenderer2.cpp

Compiler, OS:

Windows 10 + MSVC 2022

Full config/build information:

No response

Details:

As the screenshot shows, sometimes wrapped-text will split the punctuation to the beginning of next line, even if if can fit well into the first line.

(The problem will not show up if there is no " before the period .. )

Screenshots/Video:

image

(If it's s = "This is called qux.")
image

Minimal, Complete and Verifiable Example code:

static void issue() {
    if (ImGui::Begin("Issue", 0, ImGuiWindowFlags_NoSavedSettings)) {
        std::string s = "This is called \"qux\".";
        ImGui::PushTextWrapPos(ImGui::CalcTextSize(s.c_str()).x + 8);
        ImGui::TextUnformatted(s.c_str());
        ImGui::Spacing();
        s += " That"; // "qux". That
        ImGui::TextUnformatted(s.c_str()); // Though the '.' can fit in the first line, it's now at the second line.
        ImGui::PopTextWrapPos();
    }
    ImGui::End();
}

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions