8#ifndef IGL_OPENGL_GLFW_IMGUI_IMGUIHELPERS_H
9#define IGL_OPENGL_GLFW_IMGUI_IMGUIHELPERS_H
28static auto vector_getter = [](
void* vec,
int idx,
const char** out_text)
30 auto& vector = *
static_cast<std::vector<std::string>*
>(vec);
31 if (idx < 0 || idx >=
static_cast<int>(vector.size())) {
return false; }
32 *out_text = vector.at(idx).c_str();
36inline bool Combo(
const char* label,
int* idx, std::vector<std::string>& values)
38 if (values.empty()) {
return false; }
39 return Combo(label, idx, vector_getter,
40 static_cast<void*
>(&values), values.size());
43inline bool Combo(
const char* label,
int* idx, std::function<
const char *(
int)> getter,
int items_count)
45 auto func = [](
void* data,
int i,
const char** out_text) {
46 auto &getter = *
reinterpret_cast<std::function<
const char *(
int)
> *>(data);
47 const char *s = getter(i);
48 if (s) { *out_text = s;
return true; }
49 else {
return false; }
51 return Combo(label, idx, func,
reinterpret_cast<void *
>(&getter), items_count);
54inline bool ListBox(
const char* label,
int* idx, std::vector<std::string>& values)
56 if (values.empty()) {
return false; }
57 return ListBox(label, idx, vector_getter,
58 static_cast<void*
>(&values), values.size());
61inline bool InputText(
const char* label, std::string &str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL,
void* user_data = NULL)
64 std::fill_n(buf, 1024, 0);
65 std::copy_n(str.begin(), std::min(1024, (
int) str.size()), buf);
68 str = std::string(buf);
95inline bool SliderScalar(
const char *label, T* value, T min = 0, T max = 0,
const char* format =
"")
97 const char *fmt = format;
98 if (format ==
nullptr) {
104template<
typename Getter,
typename Setter>
105inline bool Checkbox(
const char* label, Getter get, Setter set)
Definition ImGuiTraits.h:20
Definition ImGuiHelpers.h:26
bool Combo(const char *label, int *idx, std::vector< std::string > &values)
Definition ImGuiHelpers.h:36
bool Checkbox(const char *label, Getter get, Setter set)
Definition ImGuiHelpers.h:105
bool SliderScalar(const char *label, T *value, T min=0, T max=0, const char *format="")
Definition ImGuiHelpers.h:95
bool InputText(const char *label, std::string &str, ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=NULL, void *user_data=NULL)
Definition ImGuiHelpers.h:61
bool ListBox(const char *label, int *idx, std::vector< std::string > &values)
Definition ImGuiHelpers.h:54