diff --git a/src/olympic/studio/modlib/include/studio/imguiutil.hpp b/src/olympic/studio/modlib/include/studio/imguiutil.hpp index 46881268..bab5e7d8 100644 --- a/src/olympic/studio/modlib/include/studio/imguiutil.hpp +++ b/src/olympic/studio/modlib/include/studio/imguiutil.hpp @@ -148,6 +148,19 @@ bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, Im */ bool ComboBox(ox::CStringView lbl, ox::SpanView list, size_t &selectedIdx) noexcept; +/** + * + * @param lbl + * @param callback + * @param selectedIdx + * @return true if new value selected, false otherwise + */ +bool ComboBox( + ox::CStringView lbl, + std::function const&f, + size_t strCnt, + size_t &selectedIdx) noexcept; + bool FileComboBox( ox::CStringView lbl, studio::StudioContext &sctx, diff --git a/src/olympic/studio/modlib/src/imguiutil.cpp b/src/olympic/studio/modlib/src/imguiutil.cpp index a90f7c2e..0af15b97 100644 --- a/src/olympic/studio/modlib/src/imguiutil.cpp +++ b/src/olympic/studio/modlib/src/imguiutil.cpp @@ -100,6 +100,26 @@ bool ComboBox( return out; } +bool ComboBox( + ox::CStringView lbl, + std::function const&f, + size_t strCnt, + size_t &selectedIdx) noexcept { + bool out{}; + auto const first = selectedIdx < strCnt ? f(selectedIdx).c_str() : ""; + if (ImGui::BeginCombo(lbl.c_str(), first, 0)) { + for (auto i = 0u; i < strCnt; ++i) { + const auto selected = (selectedIdx == i); + if (ImGui::Selectable(f(i).c_str(), selected) && selectedIdx != i) { + selectedIdx = i; + out = true; + } + } + ImGui::EndCombo(); + } + return out; +} + bool FileComboBox( ox::CStringView lbl, studio::StudioContext &sctx,