Imgui: Automatic C binding generator

Created on 27 Apr 2018  路  23Comments  路  Source: ocornut/imgui

Hi Omar,

After finishing automatic generation of enums and structs for 1.60 binding
https://github.com/sonoro1234/cimgui/blob/master160/cimgui/imgui_structs.h

I have begun with function automatic generation.
In this file each line has as the first word the struct which owns the function (or ImGui as namespace) and the the function prototype in c++ format (with defaults and function overloading)

I get 445 functions.
Is there anything to say at this stage of work?
imgui_funcs.txt

Best
victor

backenbinding language binding

Most helpful comment

I have changed file generation according to your suggestions
https://github.com/sonoro1234/cimgui/tree/master_auto

I think that now cimgui master_auto is providing the same functionallity as cimgui master.

As I personally dont have use cases for class constructors or ImVector templates I would prefer to stop here the development until someone has this extra needs.

The more open issue is overloaded function names but a naming algorythm and a dictionary are provided
https://github.com/sonoro1234/cimgui/blob/master_auto/cimgui/generator/generator.lua#L17
and the community has something to say (I guess)

All 23 comments

Not really sure what you are asking here :) but I'm super interested in as and hopefully in the future we could provide a script that would make it easy for people to use to recreate bindings for multiple languages (e.g. separate the parsing from the output).

Some suggestion:

  • For C output, you can group all the typedef next to next others (I think in C you can do the typedef before you know the struct definition?) that would make things nicer to read.
  • Preserving/recreating the spacing.
  • Preserving comments (would make the .h more useful for users).
  • Embedded C++ structure names should be prefixed with the parent structure in C version.
  • Preserving the IMGUI_DISABLE_OBSOLETE_FUNCTIONS pre-processor blocks would be ideal, or otherwise offer the option to either strip keep either keep them in.

I was asking if you missed any function in imgui_funcs.txt

Preserving the IMGUI_DISABLE_OBSOLETE_FUNCTIONS or not is now made in the generation phase
adding this define at
https://github.com/sonoro1234/cimgui/blob/master160/cimgui/gen_imgui_structs.bat#L5

I have added spacing preserving (has to be corrected for embeded structs at the end.

The main problem now is function name generation for overloaded functions. (There are already overloaded names asigned in cimgui)

this is a list of overloaded functions in 1.60

ImGui_Selectable    2
1   (const char* label, bool selected , ImGuiSelectableFlags flags , const ImVec2& size )
2   (const char* label, bool* p_selected, ImGuiSelectableFlags flags , const ImVec2& size )
ImGui_PushStyleColor    2
1   (ImGuiCol idx, ImU32 col)
2   (ImGuiCol idx, const ImVec4& col)
ImGui_TreeNodeExV   2
1   (const char* str_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args)
2   (const void* ptr_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args)
ImGui_MenuItem  2
1   (const char* label, const char* shortcut , bool selected , bool enabled )
2   (const char* label, const char* shortcut, bool* p_selected, bool enabled )
ImDrawList_AddText  2
1   (const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end )
2   (const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end , float wrap_width , const ImVec4* cpu_fine_clip_rect )
ImGui_SetWindowSize 2
1   (const ImVec2& size, ImGuiCond cond )
2   (const char* name, const ImVec2& size, ImGuiCond cond )
ImGui_SetWindowCollapsed    2
1   (bool collapsed, ImGuiCond cond )
2   (const char* name, bool collapsed, ImGuiCond cond )
ImGui_RadioButton   2
1   (const char* label, bool active)
2   (const char* label, int* v, int v_button)
ImGui_BeginChild    2
1   (const char* str_id, const ImVec2& size , bool border , ImGuiWindowFlags flags )
2   (ImGuiID id, const ImVec2& size , bool border , ImGuiWindowFlags flags )
ImGui_GetColorU32   3
1   (ImGuiCol idx, float alpha_mul )
2   (const ImVec4& col)
3   (ImU32 col)
ImGui_TreeNodeV 2
1   (const char* str_id, const char* fmt, va_list args)
2   (const void* ptr_id, const char* fmt, va_list args)
ImGui_SetWindowPos  2
1   (const ImVec2& pos, ImGuiCond cond )
2   (const char* name, const ImVec2& pos, ImGuiCond cond )
ImGui_ListBoxHeader 2
1   (const char* label, const ImVec2& size )
2   (const char* label, int items_count, int height_in_items )
ImGui_TreeNode  3
1   (const char* label)
2   (const char* str_id, const char* fmt, ...)
3   (const void* ptr_id, const char* fmt, ...)
ImGui_Begin 2
1   (const char* name, bool* p_open , ImGuiWindowFlags flags )
2   (const char* name, bool* p_open, const ImVec2& size_on_first_use, float bg_alpha_override , ImGuiWindowFlags flags )
ImGui_GetID 3
1   (const char* str_id)
2   (const char* str_id_begin, const char* str_id_end)
3   (const void* ptr_id)
ImGui_CollapsingHeader  3
1   (const char* label, ImGuiTreeNodeFlags flags )
2   (const char* label, bool* p_open, ImGuiTreeNodeFlags flags )
3   (const char* label, const char* str_id, bool framed , bool default_open )
ImGui_PlotLines 2
1   (const char* label, const float* values, int values_count, int values_offset , const char* overlay_text , float scale_min , float scale_max , ImVec2 graph_size , int stride )
2   (const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset , const char* overlay_text , float scale_min , float scale_max , ImVec2 graph_size )
ImGui_SetWindowFocus    2
1   ()
2   (const char* name)
ImGui_PushStyleVar  2
1   (ImGuiStyleVar idx, float val)
2   (ImGuiStyleVar idx, const ImVec2& val)
ImGui_PlotHistogram 2
1   (const char* label, const float* values, int values_count, int values_offset , const char* overlay_text , float scale_min , float scale_max , ImVec2 graph_size , int stride )
2   (const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset , const char* overlay_text , float scale_min , float scale_max , ImVec2 graph_size )
ImGui_Combo 3
1   (const char* label, int* current_item, const char* const items[], int items_count, int popup_max_height_in_items )
2   (const char* label, int* current_item, const char* items_separated_by_zeros, int popup_max_height_in_items )
3   (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 )
ImGui_ListBox   2
1   (const char* label, int* current_item, const char* const items[], int items_count, int height_in_items )
2   (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 )
ImGui_IsRectVisible 2
1   (const ImVec2& size)
2   (const ImVec2& rect_min, const ImVec2& rect_max)
ImGui_PushID    4
1   (const char* str_id)
2   (const char* str_id_begin, const char* str_id_end)
3   (const void* ptr_id)
4   (int int_id)
ImGui_Value 4
1   (const char* prefix, bool b)
2   (const char* prefix, int v)
3   (const char* prefix, unsigned int v)
4   (const char* prefix, float v, const char* float_format )
ImGui_TreePush  2
1   (const char* str_id)
2   (const void* ptr_id )
ImGui_TreeNodeEx    3
1   (const char* label, ImGuiTreeNodeFlags flags )
2   (const char* str_id, ImGuiTreeNodeFlags flags, const char* fmt, ...)
3   (const void* ptr_id, ImGuiTreeNodeFlags flags, const char* fmt, ...)

any suggestion?

Does not seem easy to find a naming algorythm for overloaded functions, perhaps will be easier to have a dictionary from number to desired name:

ImGui_PushID    4
1   ImGui_PushIDStr(const char* str_id) 
2   ImGui_PushIDStrRange(const char* str_id_begin, const char* str_id_end)
3   ImGui_PushIDPtr(const void* ptr_id)
4   ImGui_PushIDInt(int int_id)

The dificult part with this dictionary is that new overloadings should appear after old ones in imgui.h for getting new numbers, and if some overloaded function is eliminated the dictionary should be updated.

Some helpers perhaps could have been done as one function in imgui

ImGui_SetWindowSize 2
1   (const ImVec2& size, ImGuiCond cond )
2   (const char* name, const ImVec2& size, ImGuiCond cond )

for example could have been only the second form and when name==NULL behave as the first form

Perhaps solution for the dictionary would be instead of mapping number to name, do mapping of function signature to name

ImGui_PushID    4
1   (const char*)  to ImGui_PushIDStr
2   (const char*,const char*) to ImGui_PushIDStrRange
3   (const void*) to ImGui_PushIDPtr
4   (int) to ImGui_PushIDInt

So that ordering does not matter and a new overloading (with a new signature) could be automatically detected

this is the signatures listing

ImGui_Selectable    2
1   (const char*,bool,ImGuiSelectableFlags,const ImVec2)
2   (const char*,bool*,ImGuiSelectableFlags,const ImVec2)
ImGui_PushStyleColor    2
1   (ImGuiCol,ImU32)
2   (ImGuiCol,const ImVec4)
ImGui_TreeNodeExV   2
1   (const char*,ImGuiTreeNodeFlags,const char*,va_list)
2   (const void*,ImGuiTreeNodeFlags,const char*,va_list)
ImGui_MenuItem  2
1   (const char*,const char*,bool,bool)
2   (const char*,const char*,bool*,bool)
ImDrawList_AddText  2
1   (const ImVec2,ImU32,const char*,const char*)
2   (const ImFont*,float,const ImVec2,ImU32,const char*,const char*,float,const ImVec4*)
ImGui_SetWindowSize 2
1   (const ImVec2,ImGuiCond)
2   (const char*,const ImVec2,ImGuiCond)
ImGui_SetWindowCollapsed    2
1   (bool,ImGuiCond)
2   (const char*,bool,ImGuiCond)
ImGui_RadioButton   2
1   (const char*,bool)
2   (const char*,int*,int)
ImGui_BeginChild    2
1   (const char*,const ImVec2,bool,ImGuiWindowFlags)
2   (ImGuiID,const ImVec2,bool,ImGuiWindowFlags)
ImGui_GetColorU32   3
1   (ImGuiCol,float)
2   (const ImVec4)
3   (ImU32)
ImGui_TreeNodeV 2
1   (const char*,const char*,va_list)
2   (const void*,const char*,va_list)
ImGui_SetWindowPos  2
1   (const ImVec2,ImGuiCond)
2   (const char*,const ImVec2,ImGuiCond)
ImGui_ListBoxHeader 2
1   (const char*,const ImVec2)
2   (const char*,int,int)
ImGui_TreeNode  3
1   (const char*)
2   (const char*,const char*,...)
3   (const void*,const char*,...)
ImGui_Begin 2
1   (const char*,bool*,ImGuiWindowFlags)
2   (const char*,bool*,const ImVec2,float,ImGuiWindowFlags)
ImGui_GetID 3
1   (const char*)
2   (const char*,const char*)
3   (const void*)
ImGui_CollapsingHeader  3
1   (const char*,ImGuiTreeNodeFlags)
2   (const char*,bool*,ImGuiTreeNodeFlags)
3   (const char*,const char*,bool,bool)
ImGui_PlotLines 2
1   (const char*,const float*,int,int,const char*,float,float,ImVec2,int)
2   (const char*,float (*values_getter)(void*,int),void*,int,int,const char*,float,float,ImVec2)
ImGui_SetWindowFocus    2
1   ()
2   (const char*)
ImGui_PushStyleVar  2
1   (ImGuiStyleVar,float)
2   (ImGuiStyleVar,const ImVec2)
ImGui_PlotHistogram 2
1   (const char*,const float*,int,int,const char*,float,float,ImVec2,int)
2   (const char*,float (*values_getter)(void*,int),void*,int,int,const char*,float,float,ImVec2)
ImGui_Combo 3
1   (const char*,int*,const char* const items[],int,int)
2   (const char*,int*,const char*,int)
3   (const char*,int*,bool(*items_getter)(void*,int,const char**),void*,int,int)
ImGui_ListBox   2
1   (const char*,int*,const char* const items[],int,int)
2   (const char*,int*,bool (*items_getter)(void*,int,const char**),void*,int,int)
ImGui_IsRectVisible 2
1   (const ImVec2)
2   (const ImVec2,const ImVec2)
ImGui_PushID    4
1   (const char*)
2   (const char*,const char*)
3   (const void*)
4   (int)
ImGui_Value 4
1   (const char*,bool)
2   (const char*,int)
3   (const char*,unsigned int)
4   (const char*,float,const char*)
ImGui_TreePush  2
1   (const char*)
2   (const void*)
ImGui_TreeNodeEx    3
1   (const char*,ImGuiTreeNodeFlags)
2   (const char*,ImGuiTreeNodeFlags,const char*,...)
3   (const void*,ImGuiTreeNodeFlags,const char*,...)

66 overloaded functions in all

Perhaps solution for the dictionary would be instead of mapping number to name, do mapping of function signature to name

This would work nicely with ImGui_Value as well. For char/void combinations (eg ImGui_TreePush) you could maybe decide that the void pointer variant is used rarely and name it ImGui_TreePushPtr and let the name for char* be ImGui_TreePush - or change it to ImGui_TreePushId.
Not sure about the cases like ImGui_IsRectVisible, maybe just number it.

It's a tricky problem to solve. The library wasn't designed with other languages in mind so finding those names is going to be a little unsatisfactory.

Here are some suggestions.. please take those with a pinch of salt.

ImGui_Selectable    2
1   ImGui_Selectable(const char*,bool,ImGuiSelectableFlags,const ImVec2)
2   ImGui_SelectableBoolPtr(const char*,bool*,ImGuiSelectableFlags,const ImVec2)
ImGui_PushStyleColor    2
1   ImGui_PushStyleColorU32(ImGuiCol,ImU32)
2   ImGui_PushStyleColorVec4(ImGuiCol,const ImVec4)
ImGui_TreeNodeExV   2
1   ImGui_TreeNodeExStrIdV(const char*,ImGuiTreeNodeFlags,const char*,va_list)
2   ImGui_TreeNodeExVoidIdV(const void*,ImGuiTreeNodeFlags,const char*,va_list)
ImGui_MenuItem  2
1   ImGui_MenuItem(const char*,const char*,bool,bool)
2   ImGui_MenuItemBoolPtr(const char*,const char*,bool*,bool)
ImDrawList_AddText  2
1   ImDrawList_AddText(const ImVec2,ImU32,const char*,const char*)
2   ImDrawList_AddTextWithFont(const ImFont*,float,const ImVec2,ImU32,const char*,const char*,float,const ImVec4*)
ImGui_SetWindowSize 2
1   ImGui_SetWindowSize(const ImVec2,ImGuiCond)
2   ImGui_SetWindowSizeByName(const char*,const ImVec2,ImGuiCond)
ImGui_SetWindowCollapsed    2
1   ImGui_SetWindowCollapsed(bool,ImGuiCond)
2   ImGui_SetWindowCollapsedByName(const char*,bool,ImGuiCond)
ImGui_RadioButton   2
1   ImGui_RadioButton(const char*,bool)
2   ImGui_RadioButtonFlags(const char*,int*,int)
ImGui_BeginChild    2
1   ImGui_BeginChild(const char*,const ImVec2,bool,ImGuiWindowFlags)
2   ImGui_BeginChildByID(ImGuiID,const ImVec2,bool,ImGuiWindowFlags)
ImGui_GetColorU32    3
1   ImGui_GetColorU32(ImGuiCol,float)
2   ImGui_GetColorU32FromVec4(const ImVec4)
3   ImGui_GetColorU32FromU32(ImU32)
ImGui_TreeNodeV 2
1   ImGui_TreeNodeStrIdV(const char*,const char*,va_list)
2   ImGui_TreeNodePtrIdV(const void*,const char*,va_list)
ImGui_SetWindowPos  2
1   ImGui_SetWindowPos(const ImVec2,ImGuiCond)
2   ImGui_SetWindowPosByName(const char*,const ImVec2,ImGuiCond)
ImGui_ListBoxHeader 2
1   ImGui_ListBoxHeader(const char*,const ImVec2)
2   ImGui_ListBoxHeaderByCount  (const char*,int,int) // will obsolete
ImGui_TreeNode  3
1   ImGui_TreeNode(const char*)
2   ImGui_TreeNodeStrId(const char*,const char*,...)
3   ImGui_TreeNodePtrId(const void*,const char*,...)
ImGui_Begin 2
1   ImGui_Begin(const char*,bool*,ImGuiWindowFlags)
2   ImGui_BeginOld(const char*,bool*,const ImVec2,float,ImGuiWindowFlags)
ImGui_GetID 3
1   ImGui_GetIdFromStr(const char*)
2   ImGui_GetIdFromStrRange(const char*,const char*)
3   ImGui_GetIdFromPtr(const void*)
ImGui_CollapsingHeader  3
1   ImGui_CollapsingHeader(const char*,ImGuiTreeNodeFlags)
2   ImGui_CollapsingHeaderBoolPtr(const char*,bool*,ImGuiTreeNodeFlags)
3   ImGui_CollapsingHeaderOld(const char*,const char*,bool,bool)
ImGui_PlotLines 2
1   ImGui_PlotLinesFloat(const char*,const float*,int,int,const char*,float,float,ImVec2,int)
2   ImGui_PlotLinesFunc(const char*,float (*values_getter)(void*,int),void*,int,int,const char*,float,float,ImVec2)
ImGui_SetWindowFocus    2
1   ImGui_SetWindowFocus()
2   ImGui_SetWindowFocusByName(const char*)
ImGui_PushStyleVar  2
1   ImGui_PushStyleVar  Float(ImGuiStyleVar,float)
2   ImGui_PushStyleVar  Vec2(ImGuiStyleVar,const ImVec2)
ImGui_PlotHistogram 2
1   ImGui_PlotHistogramFloat(const char*,const float*,int,int,const char*,float,float,ImVec2,int)
2   ImGui_PlotHistogramFunc(const char*,float (*values_getter)(void*,int),void*,int,int,const char*,float,float,ImVec2)
ImGui_Combo 3
1   ImGui_ComboStrArray(const char*,int*,const char* const items[],int,int)
2   ImGui_ComboStr(const char*,int*,const char*,int)
3   ImGui_ComboFunc(const char*,int*,bool(*items_getter)(void*,int,const char**),void*,int,int)
ImGui_ListBox   2
1   ImGui_ListBoxStrArray(const char*,int*,const char* const items[],int,int)
2   ImGui_ListBoxFunc(const char*,int*,bool (*items_getter)(void*,int,const char**),void*,int,int)
ImGui_IsRectVisible 2
1   ImGui_IsRectVisibleBySize(const ImVec2)
2   ImGui_IsRectVisible(const ImVec2,const ImVec2)
ImGui_PushID    4
1   ImGui_PushIdStr(const char*)
2   ImGui_PushIdStrRange(const char*,const char*)
3   ImGui_PushIdPtr(const void*)
4   ImGui_PushIdInt(int)
ImGui_Value 4
1   ImGui_ValueBool(const char*,bool)
2   ImGui_ValueInt(const char*,int)
3   ImGui_ValueUint(const char*,unsigned int)
4   ImGui_ValueFloat(const char*,float,const char*)
ImGui_TreePush  2
1   ImGui_TreePuhStrId(const char*)
2   ImGui_TreePushPtrId(const void*)
ImGui_TreeNodeEx    3
1   ImGui_TreeNodeEx(const char*,ImGuiTreeNodeFlags)
2   ImGui_TreeNodeExStrId(const char*,ImGuiTreeNodeFlags,const char*,...)
3   ImGui_TreeNodeExPtr(const void*,ImGuiTreeNodeFlags,const char*,...)

If you are going to change those names then you might as well eliminate the obsolete functions completely..

now without obsolete functions
succes: true means that the algorythm which compares arguments up to second one succeds.
(only fails with unsigned int)

igCombo 3   succes: false   true
1   (const char*,int*,const char* const items[],int,int)    int*
2   (const char*,int*,const char*,int)  int*
3   (const char*,int*,bool(*items_getter)(void*,int,const char**),void*,int,int)    int*
igValue 4   succes: false   false
1   (const char*,bool)  bool
2   (const char*,int)   int
3   (const char*,unsigned int)  int
4   (const char*,float,const char*) float
igPushStyleVar  2   succes: true    false
1   (ImGuiStyleVar,float)   float
2   (ImGuiStyleVar,const ImVec2)    ImVec2
igSetWindowFocus    2   succes: true    false
1   ()  nil
2   (const char*)   char*
igIsRectVisible 2   succes: true    false
1   (const ImVec2)  nil
2   (const ImVec2,const ImVec2) ImVec2
igRadioButton   2   succes: true    false
1   (const char*,bool)  bool
2   (const char*,int*,int)  int*
igSetWindowCollapsed    2   succes: true    false
1   (bool,ImGuiCond)    bool
2   (const char*,bool,ImGuiCond)    char*
igPlotLines 2   succes: true    false
1   (const char*,const float*,int,int,const char*,float,float,ImVec2,int)   float*
2   (const char*,float (*values_getter)(void*,int),void*,int,int,const char*,float,float,ImVec2)    *values_getter
igPushStyleColor    2   succes: true    false
1   (ImGuiCol,ImU32)    ImU32
2   (ImGuiCol,const ImVec4) ImVec4
igPlotHistogram 2   succes: true    false
1   (const char*,const float*,int,int,const char*,float,float,ImVec2,int)   float*
2   (const char*,float (*values_getter)(void*,int),void*,int,int,const char*,float,float,ImVec2)    *values_getter
igTreeNodeExV   2   succes: true    false
1   (const char*,ImGuiTreeNodeFlags,const char*,va_list)    char*
2   (const void*,ImGuiTreeNodeFlags,const char*,va_list)    void*
igGetID 3   succes: false   false
1   (const char*)   char*
2   (const char*,const char*)   char*
3   (const void*)   void*
igBeginChild    2   succes: true    false
1   (const char*,const ImVec2,bool,ImGuiWindowFlags)    char*
2   (ImGuiID,const ImVec2,bool,ImGuiWindowFlags)    ImGuiID
igSelectable    2   succes: true    false
1   (const char*,bool,ImGuiSelectableFlags,const ImVec2)    bool
2   (const char*,bool*,ImGuiSelectableFlags,const ImVec2)   bool*
igListBox   2   succes: false   true
1   (const char*,int*,const char* const items[],int,int)    int*
2   (const char*,int*,bool (*items_getter)(void*,int,const char**),void*,int,int)   int*
ImDrawList_AddText  2   succes: true    false
1   (const ImVec2,ImU32,const char*,const char*)    ImVec2
2   (const ImFont*,float,const ImVec2,ImU32,const char*,const char*,float,const ImVec4*)    ImFont*
igGetColorU32   3   succes: true    false
1   (ImGuiCol,float)    ImGuiCol
2   (const ImVec4)  ImVec4
3   (ImU32) ImU32
igSetWindowSize 2   succes: true    false
1   (const ImVec2,ImGuiCond)    ImVec2
2   (const char*,const ImVec2,ImGuiCond)    char*
igListBoxHeader 2   succes: true    false
1   (const char*,const ImVec2)  ImVec2
2   (const char*,int,int)   int
igCollapsingHeader  2   succes: true    false
1   (const char*,ImGuiTreeNodeFlags)    ImGuiTreeNodeFlags
2   (const char*,bool*,ImGuiTreeNodeFlags)  bool*
igMenuItem  2   succes: false   true
1   (const char*,const char*,bool,bool) char*
2   (const char*,const char*,bool*,bool)    char*
igSetWindowPos  2   succes: true    false
1   (const ImVec2,ImGuiCond)    ImVec2
2   (const char*,const ImVec2,ImGuiCond)    char*
igTreeNodeEx    3   succes: false   false
1   (const char*,ImGuiTreeNodeFlags)    char*
2   (const char*,ImGuiTreeNodeFlags,const char*,...)    char*
3   (const void*,ImGuiTreeNodeFlags,const char*,...)    void*
igTreePush  2   succes: true    false
1   (const char*)   char*
2   (const void*)   void*
igTreeNode  3   succes: false   false
1   (const char*)   char*
2   (const char*,const char*,...)   char*
3   (const void*,const char*,...)   void*
igTreeNodeV 2   succes: true    false
1   (const char*,const char*,va_list)   char*
2   (const void*,const char*,va_list)   void*
59  overloaded

In each line the rigthmost part is the different type found.
From every type we could get the function name termination as char* to Str or void* to Ptr
If it is working for some function I would prefer that because it is automatic but if it is failing or we simply want more control on any other function we always have the dictionary.

So, Is there any automatic naming (with succed:true) that could avoid to use dictionary?

last problems with embeded structs:
I had to made a typecast in function return for getting ImFontAtlas::CustomRect as a C struct CustomRect

struct CustomRect
{
    unsigned int ID;
    unsigned short Width, Height;
    unsigned short X, Y;
    float GlyphAdvanceX;
    ImVec2 GlyphOffset;
    ImFont* Font;
};
typedef struct CustomRect CustomRect;
CIMGUI_API const CustomRect*  ImFontAtlas_GetCustomRectByIndex(ImFontAtlas* self,int index)
{
    return (CustomRect*)self->GetCustomRectByIndex(index);
}

Will this work?
@Extrawurst @ocornut

Would be posible to have in C++ a default conversion from ImFontAtlas::CustomRect to struct CustomRect?

solved last problems

@Extrawurst @ocornut

cimgui_auto is working and should be reviewed!!

https://github.com/sonoro1234/cimgui/tree/master_auto

When all is ok I will clean the lua scripts to make them more easy to be changed

That looks like wonderful work :)

Quick feedback: it's not clear from the repiository which files are part of the generator and which files are the "output". Perhaps they should be separated? So e.g. on the root folder you would have the latest output, ready to grab and use for most users, and e.g. a generator/ folder would have all the script and cruft to regenerate it.?

Just done.

The only left things to do (apart from script cleaning) are implement constructors and ImVector specializations methods

IMHO the output files should be merged. So maybe in generator there's are e.g. cimgui_template.c and the generator outputs cimgui.cpp cimgui.h (only 2 files)

Ideally spacing and comments would also be preserved, so things like enums would look identical on both side of the fence

The output files are merged. They are: auto_funcs.h, auto_funcs.cpp and imgui_structs.h.
cimgui.cpp and cimgui.h are hand written and they use #include for getting the generated files.

Well they perhaps should be fully merged so there's only 2 files for the end-user and not 5 files with different prefix and terminology? I understand cimgui.* are currently hand written this is why I suggest moving them to generator/ as being "templates" and making the generator combine all of it.

Note of that is mandatory but I'm suggesting what I would personally do to make the code maximum friendly to the end-user.

I agree with you but let me do that at the end of all work.

I am not sure about this constructor:

CIMGUI_API void ImFontConfig_DefaultConstructor(ImFontConfig *config)
{
    *config = ImFontConfig();
}

It seems that is config is already allocated (but not initialized) then *config = ImFontConfig(); would do another allocation then an assignment to *config (and so initializes it) but I am not sure if memory allocated in ImFontConfig(); should be deallocated (freed)

ImFontConfig has no destructor so it's not a problem there.
You can use placement new and destructor directly:

CIMGUI_API void ImFontConfig_Construct(ImFontConfig *config)
{
    IM_PLACEMENT_NEW(config) ImFontConfig();
}

I have changed file generation according to your suggestions
https://github.com/sonoro1234/cimgui/tree/master_auto

I think that now cimgui master_auto is providing the same functionallity as cimgui master.

As I personally dont have use cases for class constructors or ImVector templates I would prefer to stop here the development until someone has this extra needs.

The more open issue is overloaded function names but a naming algorythm and a dictionary are provided
https://github.com/sonoro1234/cimgui/blob/master_auto/cimgui/generator/generator.lua#L17
and the community has something to say (I guess)

Closing this topic as the conversation and work moved to #1879.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spaderthomas picture spaderthomas  路  3Comments

KaungZawHtet picture KaungZawHtet  路  3Comments

NPatch picture NPatch  路  3Comments

bizehao picture bizehao  路  3Comments

Folling picture Folling  路  3Comments