[olympic/modlib] Add ListBox to ImGui util
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user