-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
imgui_toggle.cpp
115 lines (94 loc) · 3.95 KB
/
imgui_toggle.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif // IMGUI_DEFINE_MATH_OPERATORS
#include "imgui_toggle.h"
#include "imgui.h"
#include "imgui_toggle_math.h"
#include "imgui_toggle_palette.h"
#include "imgui_toggle_renderer.h"
using namespace ImGuiToggleConstants;
using namespace ImGuiToggleMath;
namespace
{
bool ToggleInternal(const char* label, bool* value, const ImGuiToggleConfig& config);
// sets the given config structure's values to the
// default ones used by the `Toggle()` overloads.
inline void SetToAliasDefaults(ImGuiToggleConfig& config)
{
config.Flags = ImGuiToggleFlags_Default;
config.AnimationDuration = AnimationDurationDisabled;
config.FrameRounding = FrameRoundingDefault;
config.KnobRounding = KnobRoundingDefault;
}
// thread-local data for the `Toggle()` functions to easily call `ToggleInternal()`.
static thread_local ImGuiToggleConfig _internalConfig;
} // namespace
bool ImGui::Toggle(const char* label, bool* v, const ImVec2& size /*= ImVec2()*/)
{
::SetToAliasDefaults(::_internalConfig);
return ::ToggleInternal(label, v, ::_internalConfig);
}
bool ImGui::Toggle(const char* label, bool* v, ImGuiToggleFlags flags, const ImVec2& size /*= ImVec2()*/)
{
::SetToAliasDefaults(::_internalConfig);
::_internalConfig.Flags = flags;
::_internalConfig.Size = size;
// if the user is using any animation flags,
// set the default animation duration.
if ((flags & ImGuiToggleFlags_Animated) != 0)
{
_internalConfig.AnimationDuration = AnimationDurationDefault;
}
return ::ToggleInternal(label, v, ::_internalConfig);
}
bool ImGui::Toggle(const char* label, bool* v, ImGuiToggleFlags flags, float animation_duration, const ImVec2& size /*= ImVec2()*/)
{
// this overload implies the toggle should be animated.
if (animation_duration > 0 && (flags & ImGuiToggleFlags_Animated) != 0)
{
// if the user didn't specify ImGuiToggleFlags_Animated, enable it.
flags = flags | (ImGuiToggleFlags_Animated);
}
::SetToAliasDefaults(::_internalConfig);
::_internalConfig.Flags = flags;
::_internalConfig.AnimationDuration = animation_duration;
::_internalConfig.Size = size;
return ::ToggleInternal(label, v, ::_internalConfig);
}
bool ImGui::Toggle(const char* label, bool* v, ImGuiToggleFlags flags, float frame_rounding, float knob_rounding, const ImVec2& size /*= ImVec2()*/)
{
::SetToAliasDefaults(::_internalConfig);
::_internalConfig.Flags = flags;
::_internalConfig.FrameRounding = frame_rounding;
::_internalConfig.KnobRounding = knob_rounding;
::_internalConfig.Size = size;
return ::ToggleInternal(label, v, ::_internalConfig);
}
bool ImGui::Toggle(const char* label, bool* v, ImGuiToggleFlags flags, float animation_duration, float frame_rounding, float knob_rounding, const ImVec2& size /*= ImVec2()*/)
{
// this overload implies the toggle should be animated.
if (animation_duration > 0 && (flags & ImGuiToggleFlags_Animated) != 0)
{
// if the user didn't specify ImGuiToggleFlags_Animated, enable it.
flags = flags | (ImGuiToggleFlags_Animated);
}
::_internalConfig.Flags = flags;
::_internalConfig.AnimationDuration = animation_duration;
::_internalConfig.FrameRounding = frame_rounding;
::_internalConfig.KnobRounding = knob_rounding;
::_internalConfig.Size = size;
return ::ToggleInternal(label, v, ::_internalConfig);
}
bool ImGui::Toggle(const char* label, bool* v, const ImGuiToggleConfig& config)
{
return ::ToggleInternal(label, v, config);
}
namespace
{
bool ToggleInternal(const char* label, bool* v, const ImGuiToggleConfig& config)
{
static thread_local ImGuiToggleRenderer renderer;
renderer.SetConfig(label, v, config);
return renderer.Render();
}
}