Clipper: enhanced ImGuiListClipper (#3841)

This commit is contained in:
GamingMinds-DanielC
2021-10-11 15:57:29 +02:00
committed by ocornut
parent b409df34db
commit cd1b5f7883
2 changed files with 128 additions and 35 deletions

10
imgui.h
View File

@ -2179,6 +2179,7 @@ struct ImGuiStorage
// Usage:
// ImGuiListClipper clipper;
// clipper.Begin(1000); // We have 1000 elements, evenly spaced.
// clipper.ForceDisplay(42); // Optional, force element with given index to be displayed (use f.e. if you need to update a tooltip for a drag&drop source)
// while (clipper.Step())
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
// ImGui::Text("line number %d", i);
@ -2195,6 +2196,12 @@ struct ImGuiListClipper
// [Internal]
int ItemsCount;
int RangeStart[4]; // 1 for the user, rest for internal use
int RangeEnd[4];
int RangeCount;
int YRangeMin[1];
int YRangeMax[1];
int YRangeCount;
int StepNo;
int ItemsFrozen;
float ItemsHeight;
@ -2207,6 +2214,9 @@ struct ImGuiListClipper
// items_height: Use -1.0f to be calculated automatically on first step. Otherwise pass in the distance between your items, typically GetTextLineHeightWithSpacing() or GetFrameHeightWithSpacing().
IMGUI_API void Begin(int items_count, float items_height = -1.0f); // Automatically called by constructor if you passed 'items_count' or by Step() in Step 1.
IMGUI_API void End(); // Automatically called on the last call of Step() that returns false.
IMGUI_API void ForceDisplayRange(int item_start, int item_end); // Optionally call before the first call to Step() if you need a range of items to be displayed regardless of visibility.
inline void ForceDisplay(int item_start, int item_count = 1) { ForceDisplayRange(item_start, item_start + item_count); } // Like ForceDisplayRange, but with a number instead of an end index.
IMGUI_API void ForceDisplayYRange(float y_min, float y_max); // Like ForceDisplayRange, but with y coordinates instead of item indices.
IMGUI_API bool Step(); // Call until it returns false. The DisplayStart/DisplayEnd fields will be set and you can process/draw those items.
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS