[studio] Add combobox that will take string views
All checks were successful
Build / build (push) Successful in 3m47s

This commit is contained in:
Gary Talent 2025-02-02 20:46:08 -06:00
parent 105a1e5559
commit 4728699585
2 changed files with 31 additions and 0 deletions

View File

@ -225,6 +225,18 @@ PopupResponse PopupControlsOkCancel(
[[nodiscard]]
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz = {285, 0});
/**
*
* @param lbl
* @param list
* @param selectedIdx
* @return true if new value selected, false otherwise
*/
bool ComboBox(
ox::CStringView lbl,
ox::SpanView<ox::CStringView> list,
size_t &selectedIdx) noexcept;
/**
*
* @param lbl

View File

@ -90,6 +90,25 @@ bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show,
return ImGui::BeginPopupModal(popupName.c_str(), &show, modalFlags);
}
bool ComboBox(
ox::CStringView lbl,
ox::SpanView<ox::CStringView> list,
size_t &selectedIdx) noexcept {
bool out{};
auto const first = selectedIdx < list.size() ? list[selectedIdx].c_str() : "";
if (ImGui::BeginCombo(lbl.c_str(), first, 0)) {
for (auto i = 0u; i < list.size(); ++i) {
const auto selected = (selectedIdx == i);
if (ImGui::Selectable(list[i].c_str(), selected) && selectedIdx != i) {
selectedIdx = i;
out = true;
}
}
ImGui::EndCombo();
}
return out;
}
bool ComboBox(
ox::CStringView lbl,
ox::Span<const ox::String> list,