dear-imgui-2.3.0: Haskell bindings for Dear ImGui.
Safe HaskellSafe-Inferred
LanguageHaskell2010

DearImGui.Raw.ListClipper

Description

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.

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 clips 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.

Usage:

clipper <- ListClipper.new
ListClipper.begin clipper 1000 -- We have 1000 elements, evenly spaced.
whileTrue (ListClipper.step clipper) $
  start <- ListClipper.displayStart clipper
  end <- ListClipper.displayEnd clipper
  for_ [start .. end] ix ->
    ImGui.text $ "line number " <> show ix

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.
  • 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.
Synopsis

Documentation

type ListClipper = Ptr ImGuiListClipper Source #

ImGuiListClipper object handle.

new :: MonadIO m => m ListClipper Source #

Create a new ListClipper instance.

delete :: MonadIO m => ListClipper -> m () Source #

Destroy ListClipper instance.

begin :: MonadIO m => ListClipper -> CInt -> CFloat -> m () Source #

ListClipper setup

items_count: Use maxBound 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.

Wraps ListClipper::Begin().

displayStart :: ListClipper -> CInt Source #

An accessor for ListClipper::Begin

displayEnd :: ListClipper -> CInt Source #

An accessor for ListClipper::DisplayStart

step :: MonadIO m => ListClipper -> m Bool Source #

Call until it returns False.

The displayStartdisplayEnd fields will be set and you can processdraw those items.

Wraps ListClipper::Step().