MCPcopy Create free account
hub / github.com/cinder/Cinder / Combo

Method Combo

src/imgui/imgui_widgets.cpp:2126–2171  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2124
2125// Old API, prefer using BeginCombo() nowadays if you can.
2126bool 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.
2174bool 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