[olympic/modlib] Add ListBox to ImGui util
This commit is contained in:
parent
0d106bde21
commit
ef9cb8bea4
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
#include <turbine/context.hpp>
|
#include <turbine/context.hpp>
|
||||||
@ -59,6 +61,12 @@ bool FileComboBox(
|
|||||||
ox::StringView fileExt,
|
ox::StringView fileExt,
|
||||||
size_t &selectedIdx) noexcept;
|
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
|
* @param name
|
||||||
|
@ -113,24 +113,34 @@ bool FileComboBox(
|
|||||||
return out;
|
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;
|
auto out = false;
|
||||||
if (ImGui::BeginListBox(name.c_str())) {
|
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));
|
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) {
|
if (i != selIdx) {
|
||||||
selIdx = i;
|
selIdx = i;
|
||||||
out = true;
|
out = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
ImGui::EndListBox();
|
ImGui::EndListBox();
|
||||||
}
|
}
|
||||||
return out;
|
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(
|
FilePicker::FilePicker(
|
||||||
studio::StudioContext &sctx,
|
studio::StudioContext &sctx,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user