From 926addbfe2e9fc7b78cfb50d8bd90a93537dc6fe Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 6 Dec 2021 17:03:47 +0100 Subject: [PATCH] Clipper: fixed invalid state when number of frozen table row is smaller than ItemCount. + Bonus rather unorthodox coding style. --- docs/CHANGELOG.txt | 1 + imgui.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 869d1d17..a3de7b03 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -74,6 +74,7 @@ Other Changes: (an additional ItemSpacing.y was declared, affecting scrollbar range). - Clipper: various and incomplete changes to tame down scrolling and precision issues on very large ranges. Passing an explicit height to the clipper now allows larger ranges. (#3609, #3962). +- Clipper: fixed invalid state when number of frozen table row is smaller than ItemCount. - Drag and Drop: BeginDragDropSource() with ImGuiDragDropFlags_SourceAllowNullID doesn't lose tooltip when scrolling. (#143) - Metrics: Added a node showing windows in submission order and showing the Begin() stack. diff --git a/imgui.cpp b/imgui.cpp index d5cf247e..c3be5b98 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2435,10 +2435,7 @@ bool ImGuiListClipper::Step() // No items if (ItemsCount == 0 || GetSkipItemForListClipping()) - { - End(); - return false; - } + return (void)End(), false; // While we are in frozen row state, keep displaying items one by one, unclipped // FIXME: Could be stored as a table-agnostic state. @@ -2446,6 +2443,8 @@ bool ImGuiListClipper::Step() { DisplayStart = data->ItemsFrozen; DisplayEnd = data->ItemsFrozen + 1; + if (DisplayStart >= ItemsCount) + return (void)End(), false; data->ItemsFrozen++; return true; } @@ -2461,6 +2460,8 @@ bool ImGuiListClipper::Step() data->Ranges.push_front(ImGuiListClipperRange::FromIndices(data->ItemsFrozen, data->ItemsFrozen + 1)); DisplayStart = ImMax(data->Ranges[0].Min, data->ItemsFrozen); DisplayEnd = ImMin(data->Ranges[0].Max, ItemsCount); + if (DisplayStart == DisplayEnd) + return (void)End(), false; data->StepNo = 1; return true; }