ListBox() uses ImGuiListClipper helper, faster for large lists, assume evenly sized items.

This commit is contained in:
ocornut 2015-05-31 12:35:21 +01:00
parent eb4ffd5dbd
commit bda0269133

View File

@ -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)) if (!ImGui::ListBoxHeader(label, items_count, height_in_items))
return false; 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; 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 bool item_selected = (i == *current_item);
const char* item_text; const char* item_text;
@ -7547,7 +7549,7 @@ bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(v
} }
ImGui::PopID(); ImGui::PopID();
} }
clipper.End();
ImGui::ListBoxFooter(); ImGui::ListBoxFooter();
return value_changed; return value_changed;
} }