[olympic/modlib] Add ListBox to ImGui util

This commit is contained in:
Gary Talent 2024-01-30 21:46:38 -06:00
parent 0d106bde21
commit ef9cb8bea4
2 changed files with 22 additions and 4 deletions

View File

@ -4,6 +4,8 @@
#pragma once
#include <functional>
#include <imgui.h>
#include <turbine/context.hpp>
@ -59,6 +61,12 @@ bool FileComboBox(
ox::StringView fileExt,
size_t &selectedIdx) noexcept;
bool ListBox(
ox::CStringView name,
std::function<ox::CStringView(size_t)> const&f,
size_t strCnt,
size_t &selIdx) noexcept;
/**
*
* @param name

View File

@ -113,24 +113,34 @@ bool FileComboBox(
return out;
}
bool ListBox(ox::CStringView name, ox::SpanView<ox::String> const&list, size_t &selIdx) noexcept {
bool ListBox(
ox::CStringView name,
std::function<ox::CStringView(size_t)> const&f,
size_t strCnt,
size_t &selIdx) noexcept {
auto out = false;
if (ImGui::BeginListBox(name.c_str())) {
for (auto i = 0u; auto const&obj : list) {
for (auto i = 0u; i < strCnt; ++i) {
auto str = f(i);
ig::IDStackItem const idStackItem2(static_cast<int>(i));
if (ImGui::Selectable(obj.c_str(), selIdx == i)) {
if (ImGui::Selectable(str.c_str(), selIdx == i)) {
if (i != selIdx) {
selIdx = i;
out = true;
}
}
++i;
}
ImGui::EndListBox();
}
return out;
}
bool ListBox(ox::CStringView name, ox::SpanView<ox::String> const&list, size_t &selIdx) noexcept {
return ig::ListBox(name, [list](size_t i) -> ox::CStringView {
return list[i];
}, list.size(), selIdx);
}
FilePicker::FilePicker(
studio::StudioContext &sctx,