forked from ocornut/imgui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgui_scoped.h
331 lines (233 loc) · 10.5 KB
/
imgui_scoped.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#pragma once
#include "imgui.h"
namespace ImScoped
{
#define IMGUI_DELETE_MOVE_COPY(Base) \
Base(Base&&) = delete; /* Move not allowed */ \
Base &operator=(Base&&) = delete; /* "" */ \
Base(const Base&) = delete; /* Copy not allowed */ \
Base& operator=(const Base&) = delete /* "" */
struct Window
{
bool IsContentVisible;
Window(const char* name, bool* p_open = NULL, ImGuiWindowFlags flags = 0) { IsContentVisible = ImGui::Begin(name, p_open, flags); }
~Window() { ImGui::End(); }
explicit operator bool() const { return IsContentVisible; }
IMGUI_DELETE_MOVE_COPY(Window);
};
struct Child
{
bool IsContentVisible;
Child(const char* str_id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags flags = 0) { IsContentVisible = ImGui::BeginChild(str_id, size, border, flags); }
Child(ImGuiID id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags flags = 0) { IsContentVisible = ImGui::BeginChild(id, size, border, flags); }
~Child() { ImGui::EndChild(); }
explicit operator bool() const { return IsContentVisible; }
IMGUI_DELETE_MOVE_COPY(Child);
};
struct Font
{
Font(ImFont* font) { ImGui::PushFont(font); }
~Font() { ImGui::PopFont(); }
IMGUI_DELETE_MOVE_COPY(Font);
};
struct StyleColor
{
StyleColor(ImGuiCol idx, ImU32 col) { ImGui::PushStyleColor(idx, col); }
StyleColor(ImGuiCol idx, const ImVec4& col) { ImGui::PushStyleColor(idx, col); }
~StyleColor() { ImGui::PopStyleColor(); }
IMGUI_DELETE_MOVE_COPY(StyleColor);
};
struct StyleVar
{
StyleVar(ImGuiStyleVar idx, float val) { ImGui::PushStyleVar(idx, val); }
StyleVar(ImGuiStyleVar idx, const ImVec2& val) { ImGui::PushStyleVar(idx, val); }
~StyleVar() { ImGui::PopStyleVar(); }
IMGUI_DELETE_MOVE_COPY(StyleVar);
};
struct ItemWidth
{
ItemWidth(float item_width) { ImGui::PushItemWidth(item_width); }
~ItemWidth() { ImGui::PopItemWidth(); }
IMGUI_DELETE_MOVE_COPY(ItemWidth);
};
struct TextWrapPos
{
TextWrapPos(float wrap_pos_x = 0.0f) { ImGui::PushTextWrapPos(wrap_pos_x); }
~TextWrapPos() { ImGui::PopTextWrapPos(); }
IMGUI_DELETE_MOVE_COPY(TextWrapPos);
};
struct AllowKeyboardFocus
{
AllowKeyboardFocus(bool allow_keyboard_focus) { ImGui::PushAllowKeyboardFocus(allow_keyboard_focus); }
~AllowKeyboardFocus() { ImGui::PopAllowKeyboardFocus(); }
IMGUI_DELETE_MOVE_COPY(AllowKeyboardFocus);
};
struct ButtonRepeat
{
ButtonRepeat(bool repeat) { ImGui::PushButtonRepeat(repeat); }
~ButtonRepeat() { ImGui::PopButtonRepeat(); }
IMGUI_DELETE_MOVE_COPY(ButtonRepeat);
};
struct Group
{
Group() { ImGui::BeginGroup(); }
~Group() { ImGui::EndGroup(); }
IMGUI_DELETE_MOVE_COPY(Group);
};
struct ID
{
ID(const char* str_id) { ImGui::PushID(str_id); }
ID(const char* str_id_begin, const char* str_id_end) { ImGui::PushID(str_id_begin, str_id_end); }
ID(const void* ptr_id) { ImGui::PushID(ptr_id); }
ID(int int_id) { ImGui::PushID(int_id); }
~ID() { ImGui::PopID(); }
IMGUI_DELETE_MOVE_COPY(ID);
};
struct Combo
{
bool IsOpen;
Combo(const char* label, const char* preview_value, ImGuiComboFlags flags = 0) { IsOpen = ImGui::BeginCombo(label, preview_value, flags); }
~Combo() { if (IsOpen) ImGui::EndCombo(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(Combo);
};
struct TreeNode
{
bool IsOpen;
TreeNode(const char* label) { IsOpen = ImGui::TreeNode(label); }
TreeNode(const char* str_id, const char* fmt, ...) IM_FMTARGS(3) { va_list ap; va_start(ap, fmt); IsOpen = ImGui::TreeNodeV(str_id, fmt, ap); va_end(ap); }
TreeNode(const void* ptr_id, const char* fmt, ...) IM_FMTARGS(3) { va_list ap; va_start(ap, fmt); IsOpen = ImGui::TreeNodeV(ptr_id, fmt, ap); va_end(ap); }
~TreeNode() { if (IsOpen) ImGui::TreePop(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(TreeNode);
};
struct TreeNodeV
{
bool IsOpen;
TreeNodeV(const char* str_id, const char* fmt, va_list args) IM_FMTLIST(3) { IsOpen = ImGui::TreeNodeV(str_id, fmt, args); }
TreeNodeV(const void* ptr_id, const char* fmt, va_list args) IM_FMTLIST(3) { IsOpen = ImGui::TreeNodeV(ptr_id, fmt, args); }
~TreeNodeV() { if (IsOpen) ImGui::TreePop(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(TreeNodeV);
};
struct TreeNodeEx
{
bool IsOpen;
TreeNodeEx(const char* label, ImGuiTreeNodeFlags flags = 0) { IM_ASSERT(!(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)); IsOpen = ImGui::TreeNodeEx(label, flags); }
TreeNodeEx(const char* str_id, ImGuiTreeNodeFlags flags, const char* fmt, ...) IM_FMTARGS(4) { va_list ap; va_start(ap, fmt); IM_ASSERT(!(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)); IsOpen = ImGui::TreeNodeExV(str_id, flags, fmt, ap); va_end(ap); }
TreeNodeEx(const void* ptr_id, ImGuiTreeNodeFlags flags, const char* fmt, ...) IM_FMTARGS(4) { va_list ap; va_start(ap, fmt); IM_ASSERT(!(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)); IsOpen = ImGui::TreeNodeExV(ptr_id, flags, fmt, ap); va_end(ap); }
~TreeNodeEx() { if (IsOpen) ImGui::TreePop(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(TreeNodeEx);
};
struct TreeNodeExV
{
bool IsOpen;
TreeNodeExV(const char* str_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) IM_FMTLIST(4) { IM_ASSERT(!(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)); IsOpen = ImGui::TreeNodeExV(str_id, flags, fmt, args); }
TreeNodeExV(const void* ptr_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) IM_FMTLIST(4) { IM_ASSERT(!(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)); IsOpen = ImGui::TreeNodeExV(ptr_id, flags, fmt, args); }
~TreeNodeExV() { if (IsOpen) ImGui::TreePop(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(TreeNodeExV);
};
struct MainMenuBar
{
bool IsOpen;
MainMenuBar() { IsOpen = ImGui::BeginMainMenuBar(); }
~MainMenuBar() { if (IsOpen) ImGui::EndMainMenuBar(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(MainMenuBar);
};
struct MenuBar
{
bool IsOpen;
MenuBar() { IsOpen = ImGui::BeginMenuBar(); }
~MenuBar() { if (IsOpen) ImGui::EndMenuBar(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(MenuBar);
};
struct Menu
{
bool IsOpen;
Menu(const char* label, bool enabled = true) { IsOpen = ImGui::BeginMenu(label, enabled); }
~Menu() { if (IsOpen) ImGui::EndMenu(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(Menu);
};
struct Tooltip
{
Tooltip() { ImGui::BeginTooltip(); }
~Tooltip() { ImGui::EndTooltip(); }
IMGUI_DELETE_MOVE_COPY(Tooltip);
};
struct Popup
{
bool IsOpen;
Popup(const char* str_id, ImGuiWindowFlags flags = 0) { IsOpen = ImGui::BeginPopup(str_id, flags); }
~Popup() { if (IsOpen) ImGui::EndPopup(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(Popup);
};
struct PopupContextItem
{
bool IsOpen;
PopupContextItem(const char* str_id = NULL, int mouse_button = 1) { IsOpen = ImGui::BeginPopupContextItem(str_id, mouse_button); }
~PopupContextItem() { if (IsOpen) ImGui::EndPopup(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(PopupContextItem);
};
struct PopupContextWindow
{
bool IsOpen;
PopupContextWindow(const char* str_id = NULL, int mouse_button = 1, bool also_over_items = true) { IsOpen = ImGui::BeginPopupContextWindow(str_id, mouse_button, also_over_items); }
~PopupContextWindow() { if (IsOpen) ImGui::EndPopup(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(PopupContextWindow);
};
struct PopupContextVoid
{
bool IsOpen;
PopupContextVoid(const char* str_id = NULL, int mouse_button = 1) { IsOpen = ImGui::BeginPopupContextVoid(str_id, mouse_button); }
~PopupContextVoid() { if (IsOpen) ImGui::EndPopup(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(PopupContextVoid);
};
struct PopupModal
{
bool IsOpen;
PopupModal(const char* name, bool* p_open = NULL, ImGuiWindowFlags flags = 0) { IsOpen = ImGui::BeginPopupModal(name, p_open, flags); }
~PopupModal() { if (IsOpen) ImGui::EndPopup(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(PopupModal);
};
struct DragDropSource
{
bool IsOpen;
DragDropSource(ImGuiDragDropFlags flags = 0) { IsOpen = ImGui::BeginDragDropSource(flags); }
~DragDropSource() { if (IsOpen) ImGui::EndDragDropSource(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(DragDropSource);
};
struct DragDropTarget
{
bool IsOpen;
DragDropTarget() { IsOpen = ImGui::BeginDragDropTarget(); }
~DragDropTarget() { if (IsOpen) ImGui::EndDragDropTarget(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(DragDropTarget);
};
struct ClipRect
{
ClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect) { ImGui::PushClipRect(clip_rect_min, clip_rect_max, intersect_with_current_clip_rect); }
~ClipRect() { ImGui::PopClipRect(); }
IMGUI_DELETE_MOVE_COPY(ClipRect);
};
struct ChildFrame
{
bool IsOpen;
ChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags flags = 0) { IsOpen = ImGui::BeginChildFrame(id, size, flags); }
~ChildFrame() { ImGui::EndChildFrame(); }
explicit operator bool() const { return IsOpen; }
IMGUI_DELETE_MOVE_COPY(ChildFrame);
};
#undef IMGUI_DELETE_MOVE_COPY
} // namespace ImScoped