- Focused/NavId now always included in display range.
- Any number of steps (while preserving zero-alloc policy).
- Non contiguous ranges for nav processing
- Moved new fields internally (+ moved StepNo away from sight so it doesn't get missused).
- Generally tweaks/refactors.
// Set cursor position and a few other things so that SetScrollHereY() and Columns() can work when seeking cursor.
// FIXME: It is problematic that we have to do that here, because custom/equivalent end-user code would stumble on the same issue.
// The clipper should probably have a 4th step to display the last item in a regular manner.
// The clipper should probably have a final step to display the last item in a regular manner, maybe with an opt-out flag for data sets which may have costly seek?
// In theory here we should assert that ImGui::GetCursorPosY() == StartPosY + DisplayEnd * ItemsHeight, but it feels saner to just seek at the end and not assert/crash the user.
// In theory here we should assert that we are already at the right position, but it seems saner to just seek at the end and not assert/crash the user.
// - Very important: when a starting position is after our maximum item, we set Min to (ItemsCount - 1). This allows us to handle most forms of wrapping.
// - Due to how Selectable extra padding they tend to be "unaligned" with exact unit in the item list,
// which with the flooring/ceiling tend to lead to 2 items instead of one being submitted.
IM_ASSERT(!scoring_rect.IsInverted());// Ensure if we have a finite, non-inverted bounding box here will allows us to remove extraneous ImFabs() calls in NavScoreItem().
// If you are submitting lots of evenly spaced items and you have a random access to the list, you can perform coarse
// clipping based on visibility to save yourself from processing those items at all.
// If you have lots evenly spaced items and you have a random access to the list, you can perform coarse
// clipping based on visibility to only submit items that are in view.
// The clipper calculates the range of visible items and advance the cursor to compensate for the non-visible items we have skipped.
// (Dear ImGui already clip items based on their bounds but it needs to measure text size to do so, whereas manual coarse clipping before submission makes this cost and your own data fetching/submission cost almost null)
// (Dear ImGui already clip items based on their bounds but: it needs to first layout the item to do so, and generally
// fetching/submitting your own data incurs additional cost. Coarse clipping using ImGuiListClipper allows you to easily
// scale using lists with tens of thousands of items without a problem)
// 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);
// Generally what happens is:
// - Clipper lets you process the first element (DisplayStart = 0, DisplayEnd = 1) regardless of it being visible or not.
// - User code submit one element.
// - User code submit that one element.
// - Clipper can measure the height of the first element
// - Clipper calculate the actual range of elements to display based on the current clipping rectangle, position the cursor before the first visible element.
// - User code submit visible elements.
// - The clipper also handles various subtleties related to keyboard/gamepad navigation, wrapping etc.
structImGuiListClipper
{
intDisplayStart;
intDisplayEnd;
// [Internal]
intItemsCount;
intRangeStart[4];// 1 for the user, rest for internal use
intRangeEnd[4];
intRangeCount;
intYRangeMin[1];
intYRangeMax[1];
intYRangeCount;
intStepNo;
intItemsFrozen;
floatItemsHeight;
floatStartPosY;
IMGUI_APIImGuiListClipper();
IMGUI_API~ImGuiListClipper();
intDisplayStart;// First item to display, updated by each call to Step()
intDisplayEnd;// End of items to display (exclusive)
intItemsCount;// [Internal] Number of items
floatItemsHeight;// [Internal] Height of item after a first step and item submission can calculate it
floatStartPosY;// [Internal] Cursor position at the time of Begin() or after table frozen rows are all processed
void*TempData;// [Internal] Internal data
// 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)
// 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_APIvoidBegin(intitems_count,floatitems_height=-1.0f);// Automatically called by constructor if you passed 'items_count' or by Step() in Step 1.
IMGUI_APIvoidEnd();// Automatically called on the last call of Step() that returns false.
IMGUI_APIvoidForceDisplayRange(intitem_start,intitem_end);// Optionally call before the first call to Step() if you need a range of items to be displayed regardless of visibility.
inlinevoidForceDisplay(intitem_start,intitem_count=1){ForceDisplayRange(item_start,item_start+item_count);}// Like ForceDisplayRange, but with a number instead of an end index.
IMGUI_APIvoidForceDisplayYRange(floaty_min,floaty_max);// Like ForceDisplayRange, but with y coordinates instead of item indices.
IMGUI_APIboolStep();// Call until it returns false. The DisplayStart/DisplayEnd fields will be set and you can process/draw those items.
// Call ForceDisplayRangeXXX functions before first call to Step() if you need a range of items to be displayed regardless of visibility.
IMGUI_APIvoidForceDisplayRangeByIndices(intitem_min,intitem_max);// item_max is exclusive e.g. use (42, 42+1) to make item 42 always visible BUT due to alignment/padding of certain items it is likely that an extra item may be included on either end of the display range.
inlineImGuiListClipper(intitems_count,floatitems_height=-1.0f){memset(this,0,sizeof(*this));ItemsCount=-1;Begin(items_count,items_height);}// [removed in 1.79]