Old API, prefer using BeginCombo() nowadays if you can.
| 2124 | |
| 2125 | // Old API, prefer using BeginCombo() nowadays if you can. |
| 2126 | bool ImGui::Combo(const char* label, int* current_item, const char* (*getter)(void* user_data, int idx), void* user_data, int items_count, int popup_max_height_in_items) |
| 2127 | { |
| 2128 | ImGuiContext& g = *GImGui; |
| 2129 | |
| 2130 | // Call the getter to obtain the preview string which is a parameter to BeginCombo() |
| 2131 | const char* preview_value = NULL; |
| 2132 | if (*current_item >= 0 && *current_item < items_count) |
| 2133 | preview_value = getter(user_data, *current_item); |
| 2134 | |
| 2135 | // The old Combo() API exposed "popup_max_height_in_items". The new more general BeginCombo() API doesn't have/need it, but we emulate it here. |
| 2136 | if (popup_max_height_in_items != -1 && !(g.NextWindowData.HasFlags & ImGuiNextWindowDataFlags_HasSizeConstraint)) |
| 2137 | SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, CalcMaxPopupHeightFromItemCount(popup_max_height_in_items))); |
| 2138 | |
| 2139 | if (!BeginCombo(label, preview_value, ImGuiComboFlags_None)) |
| 2140 | return false; |
| 2141 | |
| 2142 | // Display items |
| 2143 | bool value_changed = false; |
| 2144 | ImGuiListClipper clipper; |
| 2145 | clipper.Begin(items_count); |
| 2146 | clipper.IncludeItemByIndex(*current_item); |
| 2147 | while (clipper.Step()) |
| 2148 | for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) |
| 2149 | { |
| 2150 | const char* item_text = getter(user_data, i); |
| 2151 | if (item_text == NULL) |
| 2152 | item_text = "*Unknown item*"; |
| 2153 | |
| 2154 | PushID(i); |
| 2155 | const bool item_selected = (i == *current_item); |
| 2156 | if (Selectable(item_text, item_selected) && *current_item != i) |
| 2157 | { |
| 2158 | value_changed = true; |
| 2159 | *current_item = i; |
| 2160 | } |
| 2161 | if (item_selected) |
| 2162 | SetItemDefaultFocus(); |
| 2163 | PopID(); |
| 2164 | } |
| 2165 | |
| 2166 | EndCombo(); |
| 2167 | if (value_changed) |
| 2168 | MarkItemEdited(g.LastItemData.ID); |
| 2169 | |
| 2170 | return value_changed; |
| 2171 | } |
| 2172 | |
| 2173 | // Combo box helper allowing to pass an array of strings. |
| 2174 | bool ImGui::Combo(const char* label, int* current_item, const char* const items[], int items_count, int height_in_items) |
nothing calls this directly
no test coverage detected