MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / Combo

Method Combo

imgui_tiny_app/imgui/imgui_widgets.cpp:2169–2214  ·  view source on GitHub ↗

Old API, prefer using BeginCombo() nowadays if you can.

Source from the content-addressed store, hash-verified

2167
2168// Old API, prefer using BeginCombo() nowadays if you can.
2169bool 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)
2170{
2171 ImGuiContext& g = *GImGui;
2172
2173 // Call the getter to obtain the preview string which is a parameter to BeginCombo()
2174 const char* preview_value = NULL;
2175 if (*current_item >= 0 && *current_item < items_count)
2176 preview_value = getter(user_data, *current_item);
2177
2178 // 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.
2179 if (popup_max_height_in_items != -1 && !(g.NextWindowData.HasFlags & ImGuiNextWindowDataFlags_HasSizeConstraint))
2180 SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, CalcMaxPopupHeightFromItemCount(popup_max_height_in_items)));
2181
2182 if (!BeginCombo(label, preview_value, ImGuiComboFlags_None))
2183 return false;
2184
2185 // Display items
2186 bool value_changed = false;
2187 ImGuiListClipper clipper;
2188 clipper.Begin(items_count);
2189 clipper.IncludeItemByIndex(*current_item);
2190 while (clipper.Step())
2191 for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
2192 {
2193 const char* item_text = getter(user_data, i);
2194 if (item_text == NULL)
2195 item_text = "*Unknown item*";
2196
2197 PushID(i);
2198 const bool item_selected = (i == *current_item);
2199 if (Selectable(item_text, item_selected) && *current_item != i)
2200 {
2201 value_changed = true;
2202 *current_item = i;
2203 }
2204 if (item_selected)
2205 SetItemDefaultFocus();
2206 PopID();
2207 }
2208
2209 EndCombo();
2210 if (value_changed)
2211 MarkItemEdited(g.LastItemData.ID);
2212
2213 return value_changed;
2214}
2215
2216// Combo box helper allowing to pass an array of strings.
2217bool ImGui::Combo(const char* label, int* current_item, const char* const items[], int items_count, int height_in_items)

Callers

nothing calls this directly

Calls 6

ImVec2Function · 0.85
ComboFunction · 0.85
BeginMethod · 0.80
IncludeItemByIndexMethod · 0.80
StepMethod · 0.45

Tested by

no test coverage detected