[studio/modlib] Add variant of ComboBox that takes callback
This commit is contained in:
parent
e62426b085
commit
f9a14433d1
@ -148,6 +148,19 @@ bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, Im
|
||||
*/
|
||||
bool ComboBox(ox::CStringView lbl, ox::SpanView<ox::String> 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<ox::CStringView(size_t)> const&f,
|
||||
size_t strCnt,
|
||||
size_t &selectedIdx) noexcept;
|
||||
|
||||
bool FileComboBox(
|
||||
ox::CStringView lbl,
|
||||
studio::StudioContext &sctx,
|
||||
|
@ -100,6 +100,26 @@ bool ComboBox(
|
||||
return out;
|
||||
}
|
||||
|
||||
bool ComboBox(
|
||||
ox::CStringView lbl,
|
||||
std::function<ox::CStringView(size_t)> 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,
|
||||
|
Loading…
Reference in New Issue
Block a user