From 99f03824d688be0dbd0795d4e487381976eae0bd Mon Sep 17 00:00:00 2001 From: Charles Cross Date: Tue, 20 Feb 2024 12:36:03 -0800 Subject: [PATCH 1/5] Fixes incorrect output attribute ending in example (#171) --- example/color_node_editor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/color_node_editor.cpp b/example/color_node_editor.cpp index af17151..82e6670 100644 --- a/example/color_node_editor.cpp +++ b/example/color_node_editor.cpp @@ -513,7 +513,7 @@ class ColorNodeEditor const float label_width = ImGui::CalcTextSize("output").x; ImGui::Indent(node_width - label_width); ImGui::TextUnformatted("output"); - ImNodes::EndInputAttribute(); + ImNodes::EndOutputAttribute(); } ImNodes::EndNode(); From 5f6c581828836d30426c7d79aaf82bbd832866fc Mon Sep 17 00:00:00 2001 From: Jordan Peck Date: Wed, 21 Feb 2024 22:32:00 +0000 Subject: [PATCH 2/5] Fix CMake config to allow using imnodes as sub project (#182) * Fix compile with latest ImGui IMGUI_DEFINE_MATH_OPERATORS now needs to be defined before #include * Fix CMake config to allow using imnodes as sub project, option for building examples, custom imgui linking * Fix comment typo --- CMakeLists.txt | 125 +++++++++++++++++++++++++++++-------------------- 1 file changed, 73 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a397b2f..f84b551 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,25 @@ project(imnodes) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) -find_package(imgui CONFIG REQUIRED) -find_package(SDL2 CONFIG REQUIRED) + +# determine whether this is a standalone project or included by other projects +if (NOT DEFINED IMNODES_STANDALONE_PROJECT) + if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(IMNODES_STANDALONE_PROJECT ON) + else() + set(IMNODES_STANDALONE_PROJECT OFF) + endif () +endif() + +# cmake options +option(IMNODES_EXAMPLES "Build examples" ${IMNODES_STANDALONE_PROJECT}) + +# allow custom imgui target name since this can vary because imgui doesn't natively include a CMakeLists.txt +if(NOT DEFINED IMNODES_IMGUI_TARGET_NAME) + find_package(imgui CONFIG REQUIRED) + set(IMNODES_IMGUI_TARGET_NAME imgui::imgui) +endif() + if(MSVC) add_compile_definitions(SDL_MAIN_HANDLED) @@ -22,59 +39,63 @@ target_sources(imnodes PRIVATE imnodes.h imnodes_internal.h imnodes.cpp) -target_include_directories(imnodes PUBLIC ${CMAKE_SOURCE_DIR}) -target_link_libraries(imnodes PUBLIC imgui::imgui) +target_include_directories(imnodes PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(imnodes PUBLIC ${IMNODES_IMGUI_TARGET_NAME}) # Example projects +if(IMNODES_EXAMPLES) -add_executable(colornode - ${CMAKE_SOURCE_DIR}/imnodes.cpp - ${CMAKE_SOURCE_DIR}/example/main.cpp - ${CMAKE_SOURCE_DIR}/example/color_node_editor.cpp) -target_link_libraries(colornode imnodes SDL2::SDL2) -if (APPLE) - target_link_libraries(colornode "-framework OpenGL") -elseif(MSVC) - target_link_libraries(colornode "opengl32") -else() - target_link_libraries(colornode X11 Xext GL) -endif() + find_package(SDL2 CONFIG REQUIRED) -add_executable(multieditor - ${CMAKE_SOURCE_DIR}/imnodes.cpp - ${CMAKE_SOURCE_DIR}/example/main.cpp - ${CMAKE_SOURCE_DIR}/example/multi_editor.cpp) -target_link_libraries(multieditor imnodes SDL2::SDL2) -if (APPLE) - target_link_libraries(multieditor "-framework OpenGL") -elseif(MSVC) - target_link_libraries(multieditor "opengl32") -else() - target_link_libraries(multieditor X11 Xext GL) -endif() + add_executable(colornode + ${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/example/color_node_editor.cpp) + target_link_libraries(colornode imnodes SDL2::SDL2) + if (APPLE) + target_link_libraries(colornode "-framework OpenGL") + elseif(MSVC) + target_link_libraries(colornode "opengl32") + else() + target_link_libraries(colornode X11 Xext GL) + endif() -add_executable(saveload - ${CMAKE_SOURCE_DIR}/imnodes.cpp - ${CMAKE_SOURCE_DIR}/example/main.cpp - ${CMAKE_SOURCE_DIR}/example/save_load.cpp) -target_link_libraries(saveload imnodes SDL2::SDL2) -if (APPLE) - target_link_libraries(saveload "-framework OpenGL") -elseif(MSVC) - target_link_libraries(saveload "opengl32") -else() - target_link_libraries(saveload X11 Xext GL) -endif() + add_executable(multieditor + ${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/example/multi_editor.cpp) + target_link_libraries(multieditor imnodes SDL2::SDL2) + if (APPLE) + target_link_libraries(multieditor "-framework OpenGL") + elseif(MSVC) + target_link_libraries(multieditor "opengl32") + else() + target_link_libraries(multieditor X11 Xext GL) + endif() -add_executable(hello - ${CMAKE_SOURCE_DIR}/imnodes.cpp - ${CMAKE_SOURCE_DIR}/example/main.cpp - ${CMAKE_SOURCE_DIR}/example/hello.cpp) -target_link_libraries(hello imnodes SDL2::SDL2) -if (APPLE) - target_link_libraries(hello "-framework OpenGL") -elseif(MSVC) - target_link_libraries(hello "opengl32") -else() - target_link_libraries(hello X11 Xext GL) -endif() + add_executable(saveload + ${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/example/save_load.cpp) + target_link_libraries(saveload imnodes SDL2::SDL2) + if (APPLE) + target_link_libraries(saveload "-framework OpenGL") + elseif(MSVC) + target_link_libraries(saveload "opengl32") + else() + target_link_libraries(saveload X11 Xext GL) + endif() + + add_executable(hello + ${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/example/hello.cpp) + target_link_libraries(hello imnodes SDL2::SDL2) + if (APPLE) + target_link_libraries(hello "-framework OpenGL") + elseif(MSVC) + target_link_libraries(hello "opengl32") + else() + target_link_libraries(hello X11 Xext GL) + endif() +endif() \ No newline at end of file From 667ac4aa8f57f94b19c7366ca0d93bc48a409258 Mon Sep 17 00:00:00 2001 From: Johann Muszynski Date: Fri, 23 Feb 2024 08:36:38 +0200 Subject: [PATCH 3/5] clang-format code --- example/color_node_editor.cpp | 3 +-- imnodes.cpp | 2 +- imnodes_internal.h | 7 +++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/example/color_node_editor.cpp b/example/color_node_editor.cpp index 82e6670..549bd81 100644 --- a/example/color_node_editor.cpp +++ b/example/color_node_editor.cpp @@ -205,8 +205,7 @@ class ColorNodeEditor // These are driven by the user, so we place this code before rendering the nodes { const bool open_popup = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && - ImNodes::IsEditorHovered() && - ImGui::IsKeyReleased(ImGuiKey_A); + ImNodes::IsEditorHovered() && ImGui::IsKeyReleased(ImGuiKey_A); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8.f, 8.f)); if (!ImGui::IsAnyItemHovered() && open_popup) diff --git a/imnodes.cpp b/imnodes.cpp index e8bddb8..79a1077 100644 --- a/imnodes.cpp +++ b/imnodes.cpp @@ -1731,7 +1731,7 @@ static inline void CalcMiniMapLayout() const ImVec2 grid_content_size = editor.GridContentBounds.IsInverted() ? max_size : ImFloor(editor.GridContentBounds.GetSize()); - const float grid_content_aspect_ratio = grid_content_size.x / grid_content_size.y; + const float grid_content_aspect_ratio = grid_content_size.x / grid_content_size.y; mini_map_size = ImFloor( grid_content_aspect_ratio > max_size_aspect_ratio ? ImVec2(max_size.x, max_size.x / grid_content_aspect_ratio) diff --git a/imnodes_internal.h b/imnodes_internal.h index 8cfb5d7..bb1ee8f 100644 --- a/imnodes_internal.h +++ b/imnodes_internal.h @@ -264,7 +264,7 @@ struct ImNodesEditorContext // Relative origins of selected nodes for snapping of dragged nodes ImVector SelectedNodeOffsets; // Offset of the primary node origin relative to the mouse cursor. - ImVec2 PrimaryNodeOffset; + ImVec2 PrimaryNodeOffset; ImClickInteractionState ClickInteraction; @@ -285,9 +285,8 @@ struct ImNodesEditorContext ImNodesEditorContext() : Nodes(), Pins(), Links(), Panning(0.f, 0.f), SelectedNodeIndices(), SelectedLinkIndices(), SelectedNodeOffsets(), PrimaryNodeOffset(0.f, 0.f), ClickInteraction(), - MiniMapEnabled(false), MiniMapSizeFraction(0.0f), - MiniMapNodeHoveringCallback(NULL), MiniMapNodeHoveringCallbackUserData(NULL), - MiniMapScaling(0.0f) + MiniMapEnabled(false), MiniMapSizeFraction(0.0f), MiniMapNodeHoveringCallback(NULL), + MiniMapNodeHoveringCallbackUserData(NULL), MiniMapScaling(0.0f) { } }; From e9bb6cadc0382e8288be70a524ccb557f9e8c422 Mon Sep 17 00:00:00 2001 From: Johann Muszynski Date: Fri, 23 Feb 2024 08:47:56 +0200 Subject: [PATCH 4/5] Remove deprecated IM_OFFSETOF. Close #193. --- imnodes.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/imnodes.cpp b/imnodes.cpp index 79a1077..a77c0a9 100644 --- a/imnodes.cpp +++ b/imnodes.cpp @@ -2644,35 +2644,35 @@ struct ImNodesStyleVarInfo static const ImNodesStyleVarInfo GStyleVarInfo[] = { // ImNodesStyleVar_GridSpacing - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, GridSpacing)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, GridSpacing)}, // ImNodesStyleVar_NodeCornerRounding - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, NodeCornerRounding)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, NodeCornerRounding)}, // ImNodesStyleVar_NodePadding - {ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImNodesStyle, NodePadding)}, + {ImGuiDataType_Float, 2, (ImU32)offsetof(ImNodesStyle, NodePadding)}, // ImNodesStyleVar_NodeBorderThickness - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, NodeBorderThickness)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, NodeBorderThickness)}, // ImNodesStyleVar_LinkThickness - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, LinkThickness)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, LinkThickness)}, // ImNodesStyleVar_LinkLineSegmentsPerLength - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, LinkLineSegmentsPerLength)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, LinkLineSegmentsPerLength)}, // ImNodesStyleVar_LinkHoverDistance - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, LinkHoverDistance)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, LinkHoverDistance)}, // ImNodesStyleVar_PinCircleRadius - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinCircleRadius)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, PinCircleRadius)}, // ImNodesStyleVar_PinQuadSideLength - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinQuadSideLength)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, PinQuadSideLength)}, // ImNodesStyleVar_PinTriangleSideLength - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinTriangleSideLength)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, PinTriangleSideLength)}, // ImNodesStyleVar_PinLineThickness - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinLineThickness)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, PinLineThickness)}, // ImNodesStyleVar_PinHoverRadius - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinHoverRadius)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, PinHoverRadius)}, // ImNodesStyleVar_PinOffset - {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinOffset)}, + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImNodesStyle, PinOffset)}, // ImNodesStyleVar_MiniMapPadding - {ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImNodesStyle, MiniMapPadding)}, + {ImGuiDataType_Float, 2, (ImU32)offsetof(ImNodesStyle, MiniMapPadding)}, // ImNodesStyleVar_MiniMapOffset - {ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImNodesStyle, MiniMapOffset)}, + {ImGuiDataType_Float, 2, (ImU32)offsetof(ImNodesStyle, MiniMapOffset)}, }; static const ImNodesStyleVarInfo* GetStyleVarInfo(ImNodesStyleVar idx) From 8563e1655bd9bb1f249e6552cc6274d506ee788b Mon Sep 17 00:00:00 2001 From: Jordan Peck Date: Tue, 12 Mar 2024 21:25:15 +0000 Subject: [PATCH 5/5] Update CMakeLists.txt Replace /W compiler flag if it already exists to avoid compiler warning --- CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f84b551..c4c8d50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,13 @@ endif() if(MSVC) add_compile_definitions(SDL_MAIN_HANDLED) - add_compile_options(/W4 /WX) + add_compile_options(/WX) + # replace existing /W to avoid warning + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + add_compile_options(/W4) + endif() else() add_compile_options(-Wall -Wextra -Wpedantic -Werror) endif() @@ -98,4 +104,4 @@ if(IMNODES_EXAMPLES) else() target_link_libraries(hello X11 Xext GL) endif() -endif() \ No newline at end of file +endif()