1
- # Dear Bindings Version v0.13 WIP
1
+ # Dear Bindings Version v0.13
2
2
# Generates C-language headers for Dear ImGui
3
3
# Developed by Ben Carter (e-mail: ben AT shironekolabs.com, github: @ShironekoBen)
4
4
@@ -95,8 +95,7 @@ def convert_header(
95
95
backend_include_dir ,
96
96
emit_combined_json_metadata ,
97
97
prefix_replacements
98
- ):
99
-
98
+ ):
100
99
# Set up context and DOM root
101
100
context = code_dom .ParseContext ()
102
101
dom_root = code_dom .DOMHeaderFileSet ()
@@ -164,7 +163,7 @@ def convert_header(
164
163
"ImNewDummy" , # ImGui <1.82
165
164
"ImNewWrapper" , # ImGui >=1.82
166
165
# Templated stuff in imgui_internal.h
167
- "ImBitArray" , # template with two parameters, not supported
166
+ "ImBitArray" , # template with two parameters, not supported
168
167
"ImSpanAllocator" ,
169
168
])
170
169
# Remove all functions from certain types, as they're not really useful
@@ -187,10 +186,9 @@ def convert_header(
187
186
"ImGui::SliderBehaviorT" ,
188
187
"ImGui::RoundScalarWithFormatT" ,
189
188
"ImGui::CheckboxFlagsT" ])
190
-
189
+
191
190
mod_remove_functions .apply (dom_root , ["ImGui::GetInputTextState" ,
192
191
"ImGui::DebugNodeInputTextState" ])
193
-
194
192
195
193
mod_add_prefix_to_loose_functions .apply (dom_root , "c" )
196
194
@@ -229,32 +227,59 @@ def convert_header(
229
227
230
228
# If we have docking support, add some functions to allow overriding platform IO functions that return structures
231
229
if have_docking_support :
230
+ # Check if we have GetWindowFramebufferScale and GetWindowWorkAreaInsets, as those are relatively recent additions
231
+ # and they may not exist
232
+
233
+ have_getWindowFramebufferScale = False
234
+ have_getWindowWorkAreaInsets = False
235
+
236
+ for field in dom_root .list_all_children_of_type (code_dom .DOMFieldDeclaration ):
237
+ if field .get_fully_qualified_name () == "ImGuiPlatformIO::Platform_GetWindowFramebufferScale" :
238
+ have_getWindowFramebufferScale = True
239
+ if field .get_fully_qualified_name () == "ImGuiPlatformIO::Platform_GetWindowWorkAreaInsets" :
240
+ have_getWindowWorkAreaInsets = True
241
+
232
242
# Implementation for these is in templates/imgui-header-template.cpp
233
243
mod_add_manual_helper_functions .apply (dom_root ,
234
244
[
235
245
"void ImGuiPlatformIO_SetPlatform_GetWindowPos(void(*getWindowPosFunc)(ImGuiViewport* vp, ImVec2* result)); "
236
246
"// Set ImGuiPlatformIO::Platform_GetWindowPos in a C-compatible mannner" ,
237
247
"void ImGuiPlatformIO_SetPlatform_GetWindowSize(void(*getWindowSizeFunc)(ImGuiViewport* vp, ImVec2* result)); "
238
- "// Set ImGuiPlatformIO::Platform_GetWindowSize in a C-compatible mannner" ,
239
- "void ImGuiPlatformIO_SetPlatform_GetWindowFramebufferScale(void(*getWindowFramebufferScaleFunc)(ImGuiViewport* vp, ImVec2* result)); "
240
- "// Set ImGuiPlatformIO::Platform_GetWindowFramebufferScale in a C-compatible mannner" ,
241
- "void ImGuiPlatformIO_SetPlatform_GetWindowWorkAreaInsets(void(*getWindowWorkAreaInsetsFunc)(ImGuiViewport* vp, ImVec4* result)); "
242
- "// Set ImGuiPlatformIO::Platform_GetWindowWorkAreaInsets in a C-compatible mannner"
248
+ "// Set ImGuiPlatformIO::Platform_GetWindowSize in a C-compatible mannner"
243
249
])
250
+
251
+ if have_getWindowFramebufferScale :
252
+ mod_add_manual_helper_functions .apply (dom_root ,
253
+ [
254
+ "void ImGuiPlatformIO_SetPlatform_GetWindowFramebufferScale(void(*getWindowFramebufferScaleFunc)(ImGuiViewport* vp, ImVec2* result)); "
255
+ "// Set ImGuiPlatformIO::Platform_GetWindowFramebufferScale in a C-compatible mannner" ,
256
+ ])
257
+ mod_add_defines .apply (dom_root , [ "#define IMGUI_DEAR_BINDINGS_HAS_GETWINDOWFRAMEBUFFERSCALE" ])
258
+
259
+ if have_getWindowWorkAreaInsets :
260
+ mod_add_manual_helper_functions .apply (dom_root ,
261
+ [
262
+ "void ImGuiPlatformIO_SetPlatform_GetWindowWorkAreaInsets(void(*getWindowWorkAreaInsetsFunc)(ImGuiViewport* vp, ImVec4* result)); "
263
+ "// Set ImGuiPlatformIO::Platform_GetWindowWorkAreaInsets in a C-compatible mannner"
264
+ ])
265
+ mod_add_defines .apply (dom_root , ["#define IMGUI_DEAR_BINDINGS_HAS_GETWINDOWWORKAREAINSETS" ])
266
+
244
267
# Add comments to try and point people at the helpers
245
268
mod_add_field_comment .apply (dom_root ,
246
- "ImGuiPlatformIO::Platform_GetWindowPos" ,
247
- "(Use ImGuiPlatformIO_SetPlatform_GetWindowPos() to set this from C, otherwise you will likely encounter stack corruption)" )
269
+ "ImGuiPlatformIO::Platform_GetWindowPos" ,
270
+ "(Use ImGuiPlatformIO_SetPlatform_GetWindowPos() to set this from C, otherwise you will likely encounter stack corruption)" )
248
271
249
272
mod_add_field_comment .apply (dom_root ,
250
273
"ImGuiPlatformIO::Platform_GetWindowSize" ,
251
274
"(Use ImGuiPlatformIO_SetPlatform_GetWindowSize() to set this from C, otherwise you will likely encounter stack corruption)" )
252
275
253
- mod_add_field_comment .apply (dom_root ,
276
+ if have_getWindowFramebufferScale :
277
+ mod_add_field_comment .apply (dom_root ,
254
278
"ImGuiPlatformIO::Platform_GetWindowFramebufferScale" ,
255
279
"(Use ImGuiPlatformIO_SetPlatform_GetWindowFramebufferScale() to set this from C, otherwise you will likely encounter stack corruption)" )
256
280
257
- mod_add_field_comment .apply (dom_root ,
281
+ if have_getWindowWorkAreaInsets :
282
+ mod_add_field_comment .apply (dom_root ,
258
283
"ImGuiPlatformIO::Platform_GetWindowWorkAreaInsets" ,
259
284
"(Use ImGuiPlatformIO_SetPlatform_GetWindowWorkAreaInsets() to set this from C, otherwise you will likely encounter stack corruption)" )
260
285
@@ -307,15 +332,15 @@ def convert_header(
307
332
# only in the type of the callback function. The normal disambiguation system can't handle that, so instead we
308
333
# manually rename the older versions of those functions here.
309
334
mod_rename_function_by_signature .apply (dom_root ,
310
- 'ImGui_Combo' , # Function name
311
- 'old_callback' , # Argument to look for to identify this function
312
- 'ImGui_ComboObsolete' # New name
313
- )
335
+ 'ImGui_Combo' , # Function name
336
+ 'old_callback' , # Argument to look for to identify this function
337
+ 'ImGui_ComboObsolete' # New name
338
+ )
314
339
mod_rename_function_by_signature .apply (dom_root ,
315
- 'ImGui_ListBox' , # Function name
316
- 'old_callback' , # Argument to look for to identify this function
317
- 'ImGui_ListBoxObsolete' # New name
318
- )
340
+ 'ImGui_ListBox' , # Function name
341
+ 'old_callback' , # Argument to look for to identify this function
342
+ 'ImGui_ListBoxObsolete' # New name
343
+ )
319
344
320
345
# The DirectX backends declare some DirectX types that need to not have _t appended to their typedef names
321
346
mod_mark_structs_as_using_unmodified_name_for_typedef .apply (dom_root ,
@@ -379,7 +404,7 @@ def convert_header(
379
404
],
380
405
type_priorities = {
381
406
})
382
-
407
+
383
408
if not no_generate_default_arg_functions :
384
409
mod_generate_default_argument_functions .apply (dom_root ,
385
410
# We ignore functions that don't get called often because in those
@@ -415,7 +440,8 @@ def convert_header(
415
440
# Widgets
416
441
'ImGui_ProgressBar' ,
417
442
'ImGui_ColorPicker4' ,
418
- 'ImGui_TreePushPtr' , # Ensure why core lib has this default to NULL?
443
+ 'ImGui_TreePushPtr' ,
444
+ # Ensure why core lib has this default to NULL?
419
445
'ImGui_BeginListBox' ,
420
446
'ImGui_ListBox' ,
421
447
'ImGui_MenuItemBoolPtr' ,
@@ -510,7 +536,7 @@ def convert_header(
510
536
'ImGui_Text' ,
511
537
'ImGuiTextBuffer_appendf'
512
538
])
513
-
539
+
514
540
if is_imgui_internal :
515
541
mod_move_elements .apply (dom_root ,
516
542
main_src_root ,
@@ -573,7 +599,6 @@ def convert_header(
573
599
(code_dom .DOMPreprocessorIf , 'ImDrawIdx' , False , True ),
574
600
])
575
601
576
-
577
602
# Make all functions use CIMGUI_API/CIMGUI_IMPL_API
578
603
mod_make_all_functions_use_imgui_api .apply (dom_root )
579
604
# Rename the API defines
@@ -620,7 +645,7 @@ def convert_header(
620
645
])
621
646
622
647
mod_replace_typedef_with_opaque_buffer .apply (dom_root , [
623
- ("ImBitArrayForNamedKeys" , 20 ) # template with two parameters, not supported
648
+ ("ImBitArrayForNamedKeys" , 20 ) # template with two parameters, not supported
624
649
])
625
650
626
651
# Remove namespaced define
@@ -712,14 +737,14 @@ def convert_header(
712
737
print ("Dear Bindings: parse Dear ImGui headers, convert to C and output metadata." )
713
738
714
739
# Debug code
715
- #type_comprehender.get_type_description("void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd)").dump(0)
740
+ # type_comprehender.get_type_description("void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd)").dump(0)
716
741
717
742
default_template_dir = os .path .join (os .path .dirname (os .path .realpath (__file__ )), "src" , "templates" )
718
743
719
744
parser = argparse .ArgumentParser (
720
- add_help = True ,
721
- epilog = 'Result code 0 is returned on success, 1 on conversion failure and 2 on '
722
- 'parameter errors' )
745
+ add_help = True ,
746
+ epilog = 'Result code 0 is returned on success, 1 on conversion failure and 2 on '
747
+ 'parameter errors' )
723
748
parser .add_argument ('src' ,
724
749
help = 'Path to source header file to process (generally imgui.h)' )
725
750
parser .add_argument ('-o' , '--output' ,
@@ -803,7 +828,7 @@ def convert_header(
803
828
sys .exit (1 )
804
829
index = replacement_str .index ('=' )
805
830
old_prefix = replacement_str [:index ]
806
- new_prefix = replacement_str [(index + 1 ):]
831
+ new_prefix = replacement_str [(index + 1 ):]
807
832
prefix_replacements [old_prefix ] = new_prefix
808
833
809
834
# --custom-namespace-prefix is just handled as a handy short form for --replace-prefix ImGui_=<something>
0 commit comments