Package imgui
Class ImGuiListClipper
java.lang.Object
imgui.binding.ImGuiStruct
imgui.binding.ImGuiStructDestroyable
imgui.ImGuiListClipper
Helper: Manually clip large list of items.
If you have lots evenly spaced items and you have 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 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.
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 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.-
Field Summary
Fields inherited from class imgui.binding.ImGuiStruct
ptr -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbegin(int itemsCount) voidbegin(int itemsCount, float itemsHeight) protected longcreate()voidend()Automatically called on the last call of Step() that returns false.static voidforEach(int itemsCount, int itemsHeight, ImListClipperCallback callback) static voidforEach(int itemsCount, ImListClipperCallback callback) static voidforEach(Consumer<ImGuiListClipper> clipAction) Shortcut to useImGuiListClipperinstance.getCtx()Parent UI contextintintintfloatfloatvoidincludeItemByIndex(int itemIndex) Call IncludeItemByIndex() or IncludeItemsByIndex() *BEFORE* first call to Step() if you need a range of items to not be clipped, regardless of their visibility.voidincludeItemsByIndex(int itemBegin, int itemEnd) Call IncludeItemByIndex() or IncludeItemsByIndex() *BEFORE* first call to Step() if you need a range of items to not be clipped, regardless of their visibility.voidsetCtx(ImGuiContext value) Parent UI contextvoidsetDisplayEnd(int value) voidsetDisplayStart(int value) booleanstep()Call until it returns false.Methods inherited from class imgui.binding.ImGuiStructDestroyable
destroyMethods inherited from class imgui.binding.ImGuiStruct
isNotValidPtr, isValidPtr
-
Constructor Details
-
ImGuiListClipper
public ImGuiListClipper() -
ImGuiListClipper
public ImGuiListClipper(long ptr)
-
-
Method Details
-
create
protected long create()- Specified by:
createin classImGuiStructDestroyable
-
getCtx
Parent UI context -
setCtx
Parent UI context -
getDisplayStart
public int getDisplayStart() -
setDisplayStart
public void setDisplayStart(int value) -
getDisplayEnd
public int getDisplayEnd() -
setDisplayEnd
public void setDisplayEnd(int value) -
getItemsCount
public int getItemsCount() -
getItemsHeight
public float getItemsHeight() -
getStartPosY
public float getStartPosY() -
begin
public void begin(int itemsCount) -
begin
public void begin(int itemsCount, float itemsHeight) -
end
public void end()Automatically called on the last call of Step() that returns false. -
step
public boolean step()Call until it returns false. The DisplayStart/DisplayEnd fields will be set and you can process/draw those items. -
includeItemByIndex
public void includeItemByIndex(int itemIndex) Call IncludeItemByIndex() or IncludeItemsByIndex() *BEFORE* first call to Step() if you need a range of items to not be clipped, regardless of their visibility. (Due to alignment / padding of certain items it is possible that an extra item may be included on either end of the display range). -
includeItemsByIndex
public void includeItemsByIndex(int itemBegin, int itemEnd) Call IncludeItemByIndex() or IncludeItemsByIndex() *BEFORE* first call to Step() if you need a range of items to not be clipped, regardless of their visibility. (Due to alignment / padding of certain items it is possible that an extra item may be included on either end of the display range).- Parameters:
itemEnd- is exclusive e.g. use (42, 42+1) to make item 42 never clipped.
-
forEach
Shortcut to useImGuiListClipperinstance.- Parameters:
clipAction- action to use inside theImGuiListClipperinstance
-
forEach
- Parameters:
itemsCount- Use -1 to ignore (you can call Begin later). 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).callback- action to do in iterations
-
forEach
- Parameters:
itemsCount- Use -1 to ignore (you can call Begin later). 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).itemsHeight- Use -1.0f to be calculated automatically on first step. Otherwise, pass in the distance between your items, typically GetTextLineHeightWithSpacing() or GetFrameHeightWithSpacing().callback- action to do in iterations
-