#9579

Adding overbars/overlines to text, for indicating i.e. inverted signal names.

Opendatenwolfopened 1mo ago

Version/Branch of Dear ImGui:

Version 1.92, Branch: docking

Back-ends:

imgui_impl_opengl3.cpp + imgui_impl_vulkan.cpp

Compiler, OS:

Windows, Linux / GCC, Clang

Details:

I'd like to implement rendering KiCAD style signal labels, indicating inversed polarity by overlining the signal name. In KiCAD the markup used for this is ~{…}. I can think of several ways to implement this:

  • creating a dedicated ImGui::OverlinedText function
  • adding support for this kind of markup (or something similar) and render the line in the display list
  • using Unicode combining diacritics and addition support for those

Before I charge ahead I'd like collect suggestions and comments on the idea. Any specifics you can think of that might throw me curveballs there?

Activity

1
ocornut1mo ago

creating a dedicated ImGui::OverlinedText function

This is going to be the easiest route.

See what ImGui::TextLink() is doing:

    float line_y = bb.Max.y + ImFloor(g.FontBaked->Descent * g.FontBakedScale * 0.20f);
    window->DrawList->AddLineH(bb.Min.x, bb.Max.x, line_y, GetColorU32(line_colf), 1.0f * (float)(int)g.Style._MainScale); // FIXME-TEXT: Underline mode // FIXME-DPI

    PushStyleColor(ImGuiCol_Text, GetColorU32(text_colf));
    RenderText(bb.Min, label, label_end, false);
    PopStyleColor();

If they are single line labels you can call ImGui::Text() then read GetItemRectMin()/GetItemRectMax() and apply. I recommend updating to latest git hash on docking as this code changed recently.

Note what we are currently fixing various small issues with font metrics and it is possible what your offset calculating might change slightly to be correct in future versions, but it's going to be an easy change.

adding support for this kind of markup (or something similar) and render the line in the display list

This is going to be sit over the above code anyhow. This is only going to be useful if you want to submit a large blob of rich/markup text at once. If your labels are submitted by code that derived them from data them a simple helper just to draw the line is enough.

using Unicode combining diacritics and addition support for those

Those are not supported by our text rendering functions.