forked from h33p/m0dular-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidgets.h
94 lines (73 loc) · 1.65 KB
/
widgets.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef WIDGETS_H
#define WIDGETS_H
#include "templated_data_types.h"
struct TabPad
{
const int pad;
TabPad(const int& p = 10)
: pad(p)
{
ImGui::Dummy(ImVec2(0.0f, pad));
ImGui::Indent(pad);
}
~TabPad()
{
ImGui::Unindent(pad);
}
};
struct IdPush
{
IdPush(const void* ptr)
{
ImGui::PushID(ptr);
}
~IdPush()
{
ImGui::PopID();
}
};
template<typename T>
struct Slider
{
static constexpr ImGuiDataType dataType = GetImGuiDataType<T>::value;
template<typename F>
static void Run(F& V, T min = 0, T max = 1, const char* label = "", const char* tooltip = "", const char* format = "%.3f", float power = 1.f)
{
T tv = V;//, ov = tv;
ImGui::SliderScalar(label, dataType, &tv, &min, &max, format, power);
if (tooltip && ImGui::IsItemHovered())
ImGui::SetTooltip("%s", tooltip);
V = tv;
}
};
template<typename T, size_t N>
struct SliderVec
{
static constexpr ImGuiDataType dataType = GetImGuiDataType<T>::value;
template<typename F>
static void Run(F& V, T min = 0, T max = 1, const char* label = "", const char* tooltip = "", const char* format = "%.3f", float power = 1.f)
{
T tv[N], ov[N];
for (size_t i = 0; i < N; i++)
tv[i] = ov[i] = V[i];
ImGui::SliderScalarN(label, dataType, tv, N, &min, &max, format, power);
if (tooltip && ImGui::IsItemHovered())
ImGui::SetTooltip("%s", tooltip);
for (size_t i = 0; i < N; i++)
V[i] = tv[i];
}
};
struct CheckBox
{
template<typename T>
static void Run(T& V, const char* label, const char* tooltip = "")
{
bool tv = V;
ImGui::Checkbox(label, &tv);
if (tooltip && ImGui::IsItemHovered())
ImGui::SetTooltip("%s", tooltip);
if (tv != !!V)
V = tv;
}
};
#endif