ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.25k stars 10.32k forks source link

Draw dashed / dotted lines #4706

Open alanjfs opened 3 years ago

alanjfs commented 3 years ago

Version/Branch of Dear ImGui:

Version: 1.86 WIP Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl3.cpp + imgui_impl_custom.cpp Compiler: Unrelated Operating System: Unrelated

My Issue/Question:

Came across this question from the old forums, and am wondering whether anything has changed with regards to drawing dotted or dashed lines with ImGui?

Alternatively if anyone knows of a way to achieve this; I'd imagine a modified texture for what is used to draw antialised lines could do the trick?

Screenshots/Video

Example of dashed lines, although spacing should ideally be consistent.

image

Standalone, minimal, complete and verifiable example:

ImGui::Begin("Psuedocode example");
auto painter = ImGui::GetForegroundDrawList();
painter.AddLine(p1, p2, color, thickness, ImGuiLineStyle_Dashed);
ImGui::End();
ocornut commented 3 years ago

There's this #1118 but no particular update. You'd have to try to implement it on your own (you can use AddCustomRectRegular() to register space in the atlas texture and add your dashes in there. The solution in #1118 will work, just be rather heavy (probably fine for ~100 segments though).