-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimgui.i
More file actions
317 lines (283 loc) · 12.1 KB
/
imgui.i
File metadata and controls
317 lines (283 loc) · 12.1 KB
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
// SWIG-4.0.2 binding for Dear ImGui 1.85 master branch
// Notes:
//
// Unsupported functions:
// Functions taking function-pointers as parameters
// ImVector<> - "You generally do NOT need to care or use this ever. But we need to make it available in imgui.h because some of our public structures are relying on it." (imgui.h)
//
// Ignored functions:
// Some operator overrides (`operator new`, `operator delete`)
// Functions from nested structures
// Obsolete functions and types - "Please keep your copy of dear imgui up to date! Occasionally set '#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS' in imconfig.h to stay ahead." (imgui.h)
// Functions taking `va_list` as the last parameter whose names end with `V` (Other functions taking `va_args` are not ignored)
//
// Renamed functions:
// All languages: Combo_itemsSeperatedByZeros <- Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_max_height_in_items = -1);
// All languages: Combo_itemsGetter <- Combo(const char* label, int* current_item, bool(*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_max_height_in_items = -1);
// All languages: ListBox_itemsGetter <- ListBox(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1);
// All languages: GetColorU32_ImU32 <- GetColorU32(ImU32 col);
// Lua: Functions whose names are `end`: They are renamed to `c_end` because `end` is a Lua keyword
// Lua: Type conversion operators: They are renamed to `toXXX` (`tobool`, `toImU32`, ...)
//
// Shadowed functions:
// Lua: Shadowed because float number is preferred: Value(const char*, int), Value(const char*, unsigned int) are not usable
// Lua: Shadowed because float number is preferred: ImColor::ImColor(int, int, int), ImColor::ImColor(int, int, int, int) are not usable
//
// `va_list` related behaviours:
// Functions like `void Text(const char* fmt, ...)` are binded using the default behaviour of SWIG, which is, skipping the `...` entirely.
// e.g. In Lua, you call `imgui.Text(string.format("%s%d", "This is formatted in Lua instead.", 123))`.
// Note that as listed above, functions like `void TextV(const char* fmt, va_list args)` are not binded (ignored) at all.
//
// Lua: All bindings now should be in Lua style: featuring multi-val return, etc.
// eg. `local isShown, isOpened = imgui.Begin("Window", isOpened, flags)`
//
//------
// Module declaration
//------
%module imgui
#ifdef SWIGLUA
%luacode {
local _moduleName = "imgui"
local _swig = _G[_moduleName]
_G[_moduleName] = nil
}
#endif
%{
#include "imgui.h"
%}
//------
// General tags
//------
%ignore TextV;
%ignore TextColoredV;
%ignore TextDisabledV;
%ignore TextWrappedV;
%ignore LabelTextV;
%ignore BulletTextV;
%ignore TreeNodeV;
%ignore TreeNodeExV;
%ignore SetTooltipV;
%ignore LogTextV;
%ignore ImGuiTextBuffer::appendfv;
%ignore operator new(size_t, ImNewWrapper, void*); // Ignored because SWIG doesn't support this operator
%ignore operator delete(void*, ImNewWrapper, void*); // Ignored because SWIG doesn't support this operator
%ignore ImGuiTextFilter::ImGuiTextRange; // Ignored because SWIG doesn't support nested structs
%ignore ImGuiStorage::ImGuiStoragePair; // Ignored because SWIG doesn't support nested structs
#ifdef SWIGLUA
%ignore Value(const char*, int); // Always use float version instead
%ignore Value(const char*, unsigned int); // Always use float version instead
%ignore ImColor::ImColor(int, int, int); // Always use float version instead
%ignore ImColor::ImColor(int, int, int, int); // Always use float version instead
%rename(c_end) end;
%rename(tobool) ImGuiOnceUponAFrame::operator bool;
%rename(toImU32) ImColor::operator ImU32;
%rename(toImVec4) ImColor::operator ImVec4;
#endif
%ignore Selectable(const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0, 0)); // Always use `p_selected` version instead
%ignore MenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true); // Always use `p_selected` version instead
%rename(RadioButton_shortcut) RadioButton(const char* label, int* v, int v_button);
%rename(CollapsingHeader_shortcut) CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags = 0);
%rename(Combo_itemsSeperatedByZeros) Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_max_height_in_items = -1);
%rename(Combo_itemsGetter) Combo(const char* label, int* current_item, bool(*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_max_height_in_items = -1);
%rename(ListBox_itemsGetter) ListBox(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1);
%rename(GetColorU32_ImU32) GetColorU32(ImU32 col);
%newobject ImGui::GetVersion;
%newobject ImGui::ImDrawList::CloneOutput;
%immutable ImGuiIO::IniFilename;
%immutable ImGuiIO::LogFilename;
%immutable ImGuiIO::BackendPlatformName;
%immutable ImGuiIO::BackendRendererName;
%immutable ImDrawList::_OwnerName;
//------
// Array type tags
//------
%include <carrays.i>
%array_functions(bool, BoolArray)
%array_functions(int, IntArray)
%array_functions(float, FloatArray)
%array_functions(char, CharArray)
%array_functions(unsigned int, UintArray)
%array_functions(unsigned char, UcharArray)
%array_functions(char*, CharPArray)
%array_functions(ImDrawVert, ImDrawVertArray)
%array_functions(ImFontGlyph, ImFontGlyphArray)
%array_functions(ImColor, ImColorArray)
%array_functions(ImGuiStorage, ImGuiStorageArray)
%array_functions(ImGuiViewport, ImGuiViewportArray)
//------
// Typemap tags + Import the headers
//------
%include <typemaps.i>
//-- Compactify default args of most of the overload functions, so that SWIG can successfully apply `argout` typemaps to overcome arg type checks of overloads; except for the cases where the count of `argout` arguments is uncertain
%feature("compactdefaultargs");
%feature("compactdefaultargs", "0") ShowDemoWindow;
%feature("compactdefaultargs", "0") ShowMetricsWindow;
%feature("compactdefaultargs", "0") ShowStackToolWindow;
%feature("compactdefaultargs", "0") ShowAboutWindow;
%feature("compactdefaultargs", "0") Begin;
%feature("compactdefaultargs", "0") BeginPopupModal;
%feature("compactdefaultargs", "0") BeginTabItem;
//-- Split some of the overload functions, so that SWIG can know how many args is for `in` and `argout` typemaps
// These functions are renamed by suffixing the count of accepted arguments. It is the wrapper on different script languages that decides whether the splitted functions should be glued back together.
%rename(ShowDemoWindow_0) ShowDemoWindow();
%rename(ShowDemoWindow_1) ShowDemoWindow(bool*);
%rename(ShowMetricsWindow_0) ShowMetricsWindow();
%rename(ShowMetricsWindow_1) ShowMetricsWindow(bool*);
%rename(ShowStackToolWindow_0) ShowStackToolWindow();
%rename(ShowStackToolWindow_1) ShowStackToolWindow(bool*);
%rename(ShowAboutWindow_0) ShowAboutWindow();
%rename(ShowAboutWindow_1) ShowAboutWindow(bool*);
%rename(Begin_1) Begin(const char*);
%rename(Begin_2) Begin(const char*, bool*);
%rename(Begin_3) Begin(const char*, bool*, ImGuiWindowFlags);
%rename(BeginPopupModal_1) BeginPopupModal(const char*);
%rename(BeginPopupModal_2) BeginPopupModal(const char*, bool*);
%rename(BeginPopupModal_3) BeginPopupModal(const char*, bool*, ImGuiWindowFlags);
%rename(BeginTabItem_1) BeginTabItem(const char*);
%rename(BeginTabItem_2) BeginTabItem(const char*, bool*);
%rename(BeginTabItem_3) BeginTabItem(const char*, bool*, ImGuiTabItemFlags);
//-- Apply some typemaps and import the headers, then clear the typemaps
%apply bool* INOUT {bool* p_open, bool* p_visible, bool* p_selected};
%apply bool* INOUT {bool* v};
%apply int* INOUT {int* v};
%apply int* INOUT {int* v_current_min, int* v_current_max};
%apply float* INOUT {float* v};
%apply float* INOUT {float* v_current_min, float* v_current_max, float* v_rad};
%apply double* INOUT {double* v};
%apply int* INOUT {int* current_item};
%apply int* OUTPUT {int* out_items_display_start, int* out_items_display_end, int* out_width, int* out_height, int* out_bytes_per_pixel};
%apply SWIGTYPE** OUTPUT {unsigned char** out_pixels};
%apply int { size_t };
#ifdef IMGUI_USER_CONFIG
%include IMGUI_USER_CONFIG
#endif
#if !defined(IMGUI_DISABLE_INCLUDE_IMCONFIG_H) || defined(IMGUI_INCLUDE_IMCONFIG_H)
%include "imconfig.h"
#endif
%include "imgui.h"
%clear bool* p_open, bool* p_visible, bool* p_selected;
%clear bool* v;
%clear int* v;
%clear int* v_current_min, int* v_current_max;
%clear float* v;
%clear float* v_current_min, float* v_current_max, float* v_rad;
%clear double* v;
%clear int* current_item;
%clear int* out_items_display_start, int* out_items_display_end, int* out_width, int* out_height, int* out_bytes_per_pixel;
%clear unsigned char** out_pixels;
%clear char** remaining;
%clear size_t;
//------
// Helper functions
//------
%inline %{
bool _SWIGExtra_IMGUI_CHECKVERSION(){
return IMGUI_CHECKVERSION();
}
float* ImVec2AsFloatP(ImVec2* vec){
return (float*) vec;
}
float* ImVec4AsFloatP(ImVec4* vec){
return (float*) vec;
}
ImVec2* FloatPAsImVec2(float* p){
return (ImVec2*) p;
}
ImVec4* FloatPAsImVec4(float* p){
return (ImVec4*) p;
}
%}
//------
// Macros and aliases
//------
#ifdef SWIGLUA
%define REG_CONST(type, name)
%constant type _SWIGExtra_##name = name;
%luacode %{ _swig[#name] = _swig._SWIGExtra_##name %}
%enddef
%define REG_ALIAS(dest, source)
%luacode %{ _swig[#dest] = _swig[#source] %}
%enddef
#endif
//floats
REG_CONST(float, FLT_MIN)
REG_CONST(float, FLT_MAX)
//swig extras
REG_ALIAS(IMGUI_CHECKVERSION, _SWIGExtra_IMGUI_CHECKVERSION)
//------
// Lua wrapper functions
//------
#ifdef SWIGLUA
%luacode {
package.loaded[_moduleName] = _swig
local _originals = {}
do
local copylist = {
"ShowDemoWindow_0",
"ShowDemoWindow_1",
"ShowMetricsWindow_0",
"ShowMetricsWindow_1",
"ShowStackToolWindow_0",
"ShowStackToolWindow_1",
"ShowAboutWindow_0",
"ShowAboutWindow_1",
"Begin_1",
"Begin_2",
"Begin_3",
"BeginPopupModal_1",
"BeginPopupModal_2",
"BeginPopupModal_3",
"BeginTabItem_1",
"BeginTabItem_2",
"BeginTabItem_3",
"RadioButton_shortcut",
"CollapsingHeader_shortcut",
}
for i = 1, #copylist do _originals[copylist[i]] = _swig[copylist[i]] end
end
do
local function _mergeSplittedFuncs(name)
return function(...)
local n = select('#', ...)
local resolved = string.format("%s_%d", name, n)
if _originals[resolved] then
return _originals[resolved](...)
else
return _originals[name](...)
end
end
end
local _data = {
"ShowDemoWindow",
"ShowMetricsWindow",
"ShowStackToolWindow",
"ShowAboutWindow",
"Begin",
"BeginPopupModal",
"BeginTabItem",
}
for i = 1, #_data do
_swig[_data[i]] = _mergeSplittedFuncs(_data[i])
end
end
do
local function _mergeShortcutFuncs(name, argIndex, thatArgOriginalType)
return function(...)
local arg = select(argIndex, ...)
if type(arg) == thatArgOriginalType then
return _originals[name](...)
else
return _originals[name.."_shortcut"](...)
end
end
end
local _data = {
"RadioButton", 2, "boolean",
"CollapsingHeader", 2, "boolean",
}
for i = 1, #_data, 3 do
_swig[_data[i]] = _mergeShortcutFuncs(_data[i], _data[i+1], _data[i+2])
end
end
}
#endif