From cbf4f054197ed439c7010bec62dedeff3c96cc87 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 2 Oct 2026 13:04:33 +0200 Subject: [PATCH] DrawList: added io.ConfigDebugDrawListDefaultsToStrokeLegacy. (#9504) --- docs/CHANGELOG.txt | 12 ++++++++++++ imgui.cpp | 8 +++++++- imgui.h | 5 +++++ imgui_demo.cpp | 4 ++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8b7f2d6a7..63c7ed07b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -67,6 +67,12 @@ While the current version doesn't make lots of visible use of the new features a facilities, they are among the pillars that will make it easier to create prettier contents, both for custom rendering and future versions of the library. +Use `ImDrawFlags_StrokeLegacy` mode to emulate old rendering: +- Per-primitive: draw_list->AddLine(..., ..., ImDrawFlags_StrokeLegacy); +- For a given scope: draw_list->PushDrawFlag(ImDrawFlags_StrokeLegacy, true); draw_list->AddLine(...); draw_list->PopDrawFlag(); +- Globally: ImGui::Checkbox("DefaultsToStrokeLegacy", &io.ConfigDebugDrawListDefaultsToStrokeLegacy); // Map to a checkbox +- Globally: io.ConfigDebugDrawListDefaultsToStrokeLegacy = io.KeyShift; // Map on Shift + Main work courtesy of @memononen. Additional work/reviewing/guidance by @ocornut. With legacy bits from @thedmd, @potocpav. @@ -224,6 +230,12 @@ Other Changes: - All functions: new rendering code fixes some inconsistencies between graphics APIs (e.g. DirectX vs OpenGL) which are using different diamond exits rules. New code should work precisely the same regardless of graphics API. (#3116, #3258, #2441) [@memononen] + - Debug: added `io.ConfigDebugDrawListDefaultsToStrokeLegacy` to facilitate comparing old/new + behaviors. This is equivalent to calling `PushDrawFlag(ImDrawFlags_StrokeLegacy, true)` + on every drawlist. + Suggested uses, e.g. + - `io.ConfigDebugDrawListDefaultsToStrokeLegacy = io.KeyShift; // Map on holding Shift` + - `ImGui::Checkbox("DefaultsToStrokeLegacy", &io.ConfigDebugDrawListDefaultsToStrokeLegacy);` - Added `ImDrawFlags_AALineEnds` flag to enable anti-aliased line ends. - Most noticeable for thick lines. - Also helps fill minor gaps if combining multiple individual lines. For best looking diff --git a/imgui.cpp b/imgui.cpp index ddef7ec4d..5b7d0c068 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -401,7 +401,11 @@ IMPLEMENTING SUPPORT for ImGuiBackendFlags_RendererHasTextures: - ImDrawList 1.92.9 <> 1.93 Interactive Testbed: https://www.dearimgui.com/docs/drawlist_v193 (<-- you can download this locally) - ImDrawList Wiki Reference: https://github.com/ocornut/imgui/wiki/Draw-List - Discussion thread: https://github.com/ocornut/imgui/issues/9504 - - Use ImDrawFlags_StrokeLegacy mode to emulate old rendering per-primitive or per-scope. + - use ImDrawFlags_StrokeLegacy mode to emulate old rendering: + - Per-primitive: draw_list->AddLine(..., ..., ImDrawFlags_StrokeLegacy); + - For a given scope: draw_list->PushDrawFlag(ImDrawFlags_StrokeLegacy, true); draw_list->AddLine(...); draw_list->PopDrawFlag(); + - Globally: ImGui::Checkbox("DefaultsToStrokeLegacy", &io.ConfigDebugDrawListDefaultsToStrokeLegacy); // Map to a checkbox + - Globally: io.ConfigDebugDrawListDefaultsToStrokeLegacy = io.KeyShift; // Map on Shift - AddLine: removed the (+0.5f,+0.5f) offset that was sneakily added to input coordinates by this function, and led to lots of inconsistencies. - This fixes inconsistencies in the API and matches the PathXXX API. - By default, stroke thickness extends on both side of the given segment. e.g for a "pixel-perfect" looking line with thickness=1.0f, coords should be passed as center of each ends of the line. @@ -5663,6 +5667,8 @@ static void SetupDrawListSharedData() g.DrawListSharedData.InitialDrawFlags |= ImDrawFlags_AALines; if (g.Style.AntiAliasedLineEnds) g.DrawListSharedData.InitialDrawFlags |= ImDrawFlags_AALineEnds; + if (g.IO.ConfigDebugDrawListDefaultsToStrokeLegacy) + g.DrawListSharedData.InitialDrawFlags |= ImDrawFlags_StrokeLegacy; if (!(g.IO.Fonts->Flags & ImFontAtlasFlags_NoBakedRoundCorners)) g.DrawListSharedData.InitialDrawFlags |= ImDrawFlags_UseTexForRoundCorners | ImDrawFlags_AllowTexForRoundCorners_; if (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset) diff --git a/imgui.h b/imgui.h index 5c47d94e1..acce04d3f 100644 --- a/imgui.h +++ b/imgui.h @@ -2559,6 +2559,11 @@ struct ImGuiIO // - Backends may have other side-effects on focus loss, so this will reduce side-effects but not necessary remove all of them. bool ConfigDebugIgnoreFocusLoss; // = false // Ignore io.AddFocusEvent(false), consequently not calling io.ClearInputKeys()/io.ClearInputMouse() in input processing. + // Option to compare < 1.93.0 rendering details vs 1.93.0 rendering details. (#9504) + // - Equivalent to calling PushDrawFlag(ImDrawList_StrokeLegacy,true) on every draw list instances. + // - Suggested use, e.g. io.ConfigDebugDrawListDefaultsToStrokeLegacy = io.KeyShift; // Map to SHIFT modifier + bool ConfigDebugDrawListDefaultsToStrokeLegacy; // false // Default all ImDrawList to ImDrawList_StrokeLegacy mode, mimicking pre-1.93.0 rendering. + //------------------------------------------------------------------ // Platform Identifiers // (the imgui_impl_xxxx backend files are setting those up for you) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 5078c11d7..97038f1e0 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -576,6 +576,8 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::SameLine(); HelpMarker("Some calls to Begin()/BeginChild() will return false.\n\nWill cycle through window depths then repeat. Windows should be flickering while running."); ImGui::Checkbox("io.ConfigDebugIgnoreFocusLoss", &io.ConfigDebugIgnoreFocusLoss); ImGui::SameLine(); HelpMarker("Option to deactivate io.AddFocusEvent(false) handling. May facilitate interactions with a debugger when focus loss leads to clearing inputs data."); + ImGui::Checkbox("io.ConfigDebugDrawListDefaultsToStrokeLegacy", &io.ConfigDebugDrawListDefaultsToStrokeLegacy); + ImGui::SameLine(); HelpMarker("Option to default all ImDrawList to ImDrawFlags_StrokeLegacy mode, mimicking pre-1.93.0 rendering."); ImGui::Checkbox("io.ConfigDebugIniSettings", &io.ConfigDebugIniSettings); ImGui::SameLine(); HelpMarker("Option to save .ini data with extra comments (particularly helpful for Docking, but makes saving slower)."); @@ -8924,6 +8926,8 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) #endif Checkbox("Anti-aliased fill", &style.AntiAliasedFill); + Checkbox("Debug: DrawList Defaults to _StrokeLegacy", &ImGui::GetIO().ConfigDebugDrawListDefaultsToStrokeLegacy); + PushItemWidth(GetFontSize() * 8); DragFloat("Curve Tessellation Max Error", &style.CurveTessellationMaxError, 0.02f, 0.10f, 10.0f, "%.2f"); if (style.CurveTessellationMaxError < 0.10f)