diff --git a/imgui.cpp b/imgui.cpp index 8d4507c..90983bc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7531,8 +7531,10 @@ 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; @@ -7547,7 +7549,7 @@ } ImGui::PopID(); } - + clipper.End(); ImGui::ListBoxFooter(); return value_changed; }