Skip to content

Commit

Permalink
ListBox() uses ImGuiListClipper helper, faster for large lists, assum…
Browse files Browse the repository at this point in the history
…e evenly sized items.
  • Loading branch information
ocornut committed May 31, 2015
1 parent eb4ffd5 commit bda0269
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7531,8 +7531,10 @@ bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(v
if (!ImGui::ListBoxHeader(label, items_count, height_in_items))
return false;

// Assume all items have even height (= 1 line of text). If you need items of different or variable sizes you can create a custom version of ListBox() in your code without using the clipper.
bool value_changed = false;
for (int i = 0; i < items_count; i++)
ImGuiListClipper clipper(items_count, ImGui::GetTextLineHeightWithSpacing());
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
{
const bool item_selected = (i == *current_item);
const char* item_text;
Expand All @@ -7547,7 +7549,7 @@ bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(v
}
ImGui::PopID();
}

clipper.End();
ImGui::ListBoxFooter();
return value_changed;
}
Expand Down

0 comments on commit bda0269

Please sign in to comment.