MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / Combo

Method Combo

TheForceEngine/TFE_Ui/imGUI/imgui_widgets.cpp:2011–2056  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2009
2010// Old API, prefer using BeginCombo() nowadays if you can.
2011bool 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)
2012{
2013 ImGuiContext& g = *GImGui;
2014
2015 // Call the getter to obtain the preview string which is a parameter to BeginCombo()
2016 const char* preview_value = NULL;
2017 if (*current_item >= 0 && *current_item < items_count)
2018 preview_value = getter(user_data, *current_item);
2019
2020 // 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.
2021 if (popup_max_height_in_items != -1 && !(g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSizeConstraint))
2022 SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, CalcMaxPopupHeightFromItemCount(popup_max_height_in_items)));
2023
2024 if (!BeginCombo(label, preview_value, ImGuiComboFlags_None))
2025 return false;
2026
2027 // Display items
2028 bool value_changed = false;
2029 ImGuiListClipper clipper;
2030 clipper.Begin(items_count);
2031 clipper.IncludeItemByIndex(*current_item);
2032 while (clipper.Step())
2033 for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
2034 {
2035 const char* item_text = getter(user_data, i);
2036 if (item_text == NULL)
2037 item_text = "*Unknown item*";
2038
2039 PushID(i);
2040 const bool item_selected = (i == *current_item);
2041 if (Selectable(item_text, item_selected) && *current_item != i)
2042 {
2043 value_changed = true;
2044 *current_item = i;
2045 }
2046 if (item_selected)
2047 SetItemDefaultFocus();
2048 PopID();
2049 }
2050
2051 EndCombo();
2052 if (value_changed)
2053 MarkItemEdited(g.LastItemData.ID);
2054
2055 return value_changed;
2056}
2057
2058// Combo box helper allowing to pass an array of strings.
2059bool 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 5

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

Tested by

no test coverage detected