From 975b5a73104bd6833b42e12891ae9506a98067c4 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 21 Aug 2018 22:34:16 +0200 Subject: [PATCH] ImDrawList: Fixed clipping of leading lines above the clipping rectangle from counting in the worst case vertices reservation. (fix code added in #200!) --- CHANGELOG.txt | 1 + imgui_draw.cpp | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 05e49f5ef..368a9c11d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -73,6 +73,7 @@ Other Changes: - Fixed PushID() from keeping alive the new ID Stack top value (if a previously active widget shared the ID it would be erroneously kept alive). - Fixed horizontal mouse wheel not forwarding the request to the parent window if ImGuiWindowFlags_NoScrollWithMouse is set. (#1463, #1380, #1502) - Fixed a include build issue for Cygwin in non-POSIX (Win32) mode. (#1917, #1319, #276) + - ImDrawList: Fixed clipping of leading lines above the clipping rectangle from counting in the worst-case vertices reservation. (fix code added in #200!) - OS/Windows: Fixed missing ImmReleaseContext() call in the default Win32 IME handler. (#1932) [@vby] - Metrics: Changed io.MetricsActiveWindows to reflect the number of active windows (!= from visible windows), which is useful for lazy/idle render mechanisms as new windows are typically not visible for one frame. diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 073c1c8a8..75e7401c6 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2632,11 +2632,16 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col const bool word_wrap_enabled = (wrap_width > 0.0f); const char* word_wrap_eol = NULL; - // Skip non-visible lines + // Fast-forward to first visible line const char* s = text_begin; if (!word_wrap_enabled && y + line_height < clip_rect.y) - while (s < text_end && *s != '\n') // Fast-forward to next line - s++; + while (y + line_height < clip_rect.y) + { + while (s < text_end) + if (*s++ == '\n') + break; + y += line_height; + } // Reserve vertices for remaining worse case (over-reserving is useful and easily amortized) const int vtx_count_max = (int)(text_end - s) * 4; @@ -2695,12 +2700,8 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col { x = pos.x; y += line_height; - if (y > clip_rect.w) - break; - if (!word_wrap_enabled && y + line_height < clip_rect.y) - while (s < text_end && *s != '\n') // Fast-forward to next line - s++; + break; // break out of main loop continue; } if (c == '\r')