diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 60b1806b8..c82bfd768 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -120,6 +120,8 @@ Other Changes: - Clear `DisplayStart`/`DisplayEnd` fields when `Step()` returns false. - Added `UserIndex` helper storage. This is solely a convenience for cases where you may want to carry an index around. + - Always pulls current context on `ImGuiListClipper::Begin()`, consistent with public + API design, and avoids issues with clipper instances outliving contexts. (#9324, #5856) - Scrollbar: - Implemented a custom tweak to extend hit-testing bounding box when window is sitting at the edge of a viewport (e.g. fullscreen or docked window), so that e.g. mouse the diff --git a/imgui.cpp b/imgui.cpp index 353eda54b..54214a8a5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3270,8 +3270,7 @@ ImGuiListClipper::~ImGuiListClipper() void ImGuiListClipper::Begin(int items_count, float items_height) { - if (Ctx == NULL) - Ctx = ImGui::GetCurrentContext(); + Ctx = ImGui::GetCurrentContext(); ImGuiContext& g = *Ctx; ImGuiWindow* window = g.CurrentWindow; diff --git a/imgui.h b/imgui.h index 7aec62952..babfcfd22 100644 --- a/imgui.h +++ b/imgui.h @@ -2856,16 +2856,16 @@ enum ImGuiListClipperFlags_ // - The clipper also handles various subtleties related to keyboard/gamepad navigation, wrapping etc. struct ImGuiListClipper { - ImGuiContext* Ctx; // Parent UI context int DisplayStart; // First item to display, updated by each call to Step() int DisplayEnd; // End of items to display (exclusive) int UserIndex; // Helper storage for user convenience/code. Optional, and otherwise unused if you don't use it. int ItemsCount; // [Internal] Number of items float ItemsHeight; // [Internal] Height of item after a first step and item submission can calculate it + ImGuiListClipperFlags Flags; // [Internal] Flags, currently not yet well exposed. double StartPosY; // [Internal] Cursor position at the time of Begin() or after table frozen rows are all processed double StartSeekOffsetY; // [Internal] Account for frozen rows in a table and initial loss of precision in very large windows. + ImGuiContext* Ctx; // [Internal] Parent UI context void* TempData; // [Internal] Internal data - ImGuiListClipperFlags Flags; // [Internal] Flags, currently not yet well exposed. // items_count: Use INT_MAX if you don't know how many items you have (in which case the cursor won't be advanced in the final step, and you can call SeekCursorForItem() manually if you need) // items_height: Use -1.0f to be calculated automatically on first step. Otherwise pass in the distance between your items, typically GetTextLineHeightWithSpacing() or GetFrameHeightWithSpacing().