Package imgui

Class ImGuiListClipper


public final class ImGuiListClipper extends ImGuiStructDestroyable
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.
  • Constructor Details

    • ImGuiListClipper

      public ImGuiListClipper()
    • ImGuiListClipper

      public ImGuiListClipper(long ptr)
  • Method Details

    • create

      protected long create()
      Specified by:
      create in class ImGuiStructDestroyable
    • getCtx

      public ImGuiContext getCtx()
      Parent UI context
    • setCtx

      public void setCtx(ImGuiContext value)
      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

      public static void forEach(Consumer<ImGuiListClipper> clipAction)
      Shortcut to use ImGuiListClipper instance.
      Parameters:
      clipAction - action to use inside the ImGuiListClipper instance
    • forEach

      public static void forEach(int itemsCount, ImListClipperCallback callback)
      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

      public static void forEach(int itemsCount, int itemsHeight, ImListClipperCallback callback)
      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