dearimgui / dear_bindings

C header (and language binding metadata) generator for Dear ImGui
MIT License
221 stars 12 forks source link

Adjustment to *Ex() functions #10

Closed ocornut closed 1 year ago

ocornut commented 2 years ago

Possibly more contentiously, I had a go at adding default argument "helpers" - i.e. version of functions that elide defaulted arguments. After playing with this a bit I actually felt like it worked best when the "helpers" are the default, so you get functions like this:

CIMGUI_API bool ImGui_BeginCombo(const char* label, const char* preview_value); // Implied flags = 0
CIMGUI_API bool ImGui_BeginComboEx(const char* label, const char* preview_value, ImGuiComboFlags flags /* = 0 */);

...the logic being that this gives an experience close to C++, where if you type "ImGui_BeginCombo(" you get the version with only the required arguments, and if you want to specify everything you need ImGui_BeginComboEx() instead.

I picked "Ex" as the suffix for that after considering a bunch of alternatives ("WithArgs", and even at one point just "_" as a kind of minimilist "doesn't get in the way when reading code" option), mainly because it's short and also there's a bit of prior history in that the Win32 API has a reasonable number of places where there are "basic" versions of function calls and then "Ex" versions with more arguments (for slightly different reasons, admittedly, but still).

The downside of this is that there are already a couple of places that use "Ex" in the code, though, so I'm not 100% sure this is the right avenue to go down. Other suggestions gratefully accepted!

I believe this is a great idea but it'll require a few passes of tweaking.




I would go as far as suggesting to consider including functions which are semi-frequently called but also frequently expanded on and easy to call with default parameters (no non-trivial types):

bool ImGui_BeginEx(const char* name, bool* p_open /* = NULL */, ImGuiWindowFlags flags /* = 0 */);

But we can iterate on the specific functions once we've done a first pass.

ShironekoBen commented 2 years ago

e2f03ea31a8f8e091bccdbdb13a363d01437a3c8 adds selective suppression of default argument helpers, with a few more additions to the list I found whilst scanning through the headers.

ocornut commented 1 year ago

NEVER MIND my post was looking at wrong copy of cimgui.h (download from Actions but may be opened wrong one?) Adding new functions now :)

~~Thanks. I can see the block:~~

    mod_generate_default_argument_functions.apply(dom_root,
                                                  # We ignore functions that don't get called often because in those
                                                  # cases the default helper doesn't add much value but does clutter
                                                  # up the header file
                                                  functions_to_ignore=[
                                                      'ImGui_LoadIniSettingsFromDisk',
                                                      'ImGui_LoadIniSettingsFromMemory',
                                                      'ImGui_SaveIniSettingsToMemory',
                                                      'ImGui_SaveIniSettingsToMemory',
                                                      'ImGui_SetAllocatorFunctions',
                                                      'ImGui_CreateContext',
                                                      'ImGui_DestroyContext',
                                                      'ImGui_ShowDemoWindow',
                                                      'ImGui_ShowMetricsWindow',
                                                      'ImGui_ShowAboutWindow',
                                                      'ImGui_ShowStyleEditor',
                                                      'ImGui_StyleColorsDark',
                                                      'ImGui_StyleColorsLight',
                                                      'ImGui_StyleColorsClassic',
[...]

But they seem to still appear in cimgui.h ?

CIMGUI_API void ImGui_StyleColorsDarkEx(ImGuiStyle* dst /* = NULL */);     // new, recommended style (default)
CIMGUI_API void ImGui_StyleColorsDark();                                   // Implied dst = NULL

So maybe something doesn't work with it currently?

ocornut commented 1 year ago

I have done a pass on cimgui.h and removed a few more Ex functions: a3c59ed There are probably other tweaks needed but for now it seems reasonable to close this. Thank you!