Nelarius / imnodes

A small, dependency-free node editor for dear imgui
MIT License
1.97k stars 241 forks source link

cimnodes puzzle #125

Closed sonoro1234 closed 2 years ago

sonoro1234 commented 2 years ago

Hi,

Having the struct tag EmulateThreeButtonMouse equal to the field name EmulateThreeButtonMouse makes a problem for cimnodes:

Change was introduced when emulate_three_button_mouse was renamed to EmulateThreeButtonMouse

this is used in cimnodes.h so that EmulateThreeButtonMouse can be used as a type from both C and C++:

#ifndef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
typedef ImNodesIO::EmulateThreeButtonMouse EmulateThreeButtonMouse;
typedef ImNodesIO::LinkDetachWithModifierClick LinkDetachWithModifierClick;
#endif //CIMGUI_DEFINE_ENUMS_AND_STRUCTS

with CIMGUI_DEFINE_ENUMS_AND_STRUCTS defined for C usage and without it for C++ usage

but that makes cpp compiler complain

[  3%] Building CXX object CMakeFiles/cimgui_base.dir/cimnodes/cimnodes.cpp.obj
In file included from C:\LuaGL\gitsources\anima\LuaJIT-ImGui\cimnodes\cimnodes.cpp:6:
C:\LuaGL\gitsources\anima\LuaJIT-ImGui\cimnodes\cimnodes.h:135:20: error: 'EmulateThreeButtonMouse' in 'struct ImNodesIO' does not name a type
 typedef ImNodesIO::EmulateThreeButtonMouse EmulateThreeButtonMouse;
                    ^~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\LuaGL\gitsources\anima\LuaJIT-ImGui\cimnodes\cimnodes.cpp:5:
C:/LuaGL/gitsources/anima/LuaJIT-ImGui/cimnodes/imnodes/imnodes.h:110:7: note: 'ImNodesIO::EmulateThreeButtonMouse' declared here
     } EmulateThreeButtonMouse;
       ^~~~~~~~~~~~~~~~~~~~~~~

The same happens with LinkDetachWithModifierClick Problem disappears if both tag name and field name are different. I am not able to solve it myself

The worst part for imnodes code is that changing the tag name makes necessary to change the constructor name also: if tag is EmulateThreeButtonMouse for example then constructor should be EmulateThreeButtonMouse () (But perhaps end user is not expected to use this constructor)

sonoro1234 commented 2 years ago

It seems that adding struct keyword solves the ambiguity

#ifndef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
typedef struct ImNodesIO::EmulateThreeButtonMouse EmulateThreeButtonMouse;
typedef struct ImNodesIO::LinkDetachWithModifierClick LinkDetachWithModifierClick;
#endif //CIMGUI_DEFINE_ENUMS_AND_STRUCTS