From 31b42e4e4ba4e9bd3c4e180b2104487b7fda6b5f Mon Sep 17 00:00:00 2001 From: thedmd Date: Sun, 18 Sep 2022 17:52:48 +0200 Subject: [PATCH 01/28] Editor: Correctly initialize 'width' for view resize code (thx @gnif) --- docs/CHANGELOG.txt | 9 ++++++++- imgui_node_editor.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 78da3565..765cb821 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -1,4 +1,11 @@ -v0.9.1 (WIP): +v0.9.2 (WIP): + + BUGFIX: Editor: Correctly initialize 'width' for view resize code (thx @gnif) + + + + +v0.9.1 (2022-08-27): CHANGE: Remove unwanted extra frame height from node bottom diff --git a/imgui_node_editor.cpp b/imgui_node_editor.cpp index 3e153928..0dad38db 100644 --- a/imgui_node_editor.cpp +++ b/imgui_node_editor.cpp @@ -1194,7 +1194,7 @@ void ed::EditorContext::Begin(const char* id, const ImVec2& size) auto centerY = (previousVisibleRect.Max.y + previousVisibleRect.Min.y) * 0.5f; auto currentVisibleRect = m_Canvas.ViewRect(); auto currentAspectRatio = currentVisibleRect.GetHeight() ? (currentVisibleRect.GetWidth() / currentVisibleRect.GetHeight()) : 0.0f; - auto width = previousVisibleRect.GetHeight(); + auto width = previousVisibleRect.GetWidth(); auto height = previousVisibleRect.GetHeight(); if (m_Config.CanvasSizeMode == ax::NodeEditor::CanvasSizeMode::FitVerticalView) From 18fe5bd1691fb7fa5bf9df4e145d58867637618a Mon Sep 17 00:00:00 2001 From: thedmd Date: Wed, 2 Nov 2022 07:38:04 +0100 Subject: [PATCH 02/28] Examples: Handle node deletion before links (#182) Deleting node queue connected links for deletion. --- docs/CHANGELOG.txt | 2 ++ .../blueprints-example/blueprints-example.cpp | 20 +++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 765cb821..b3756b5c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -2,6 +2,8 @@ v0.9.2 (WIP): BUGFIX: Editor: Correctly initialize 'width' for view resize code (thx @gnif) + BUGFIX: Examples: Handle node deletion before links (#182) + Deleting node queue connected links for deletion. diff --git a/examples/blueprints-example/blueprints-example.cpp b/examples/blueprints-example/blueprints-example.cpp index c14c2e39..e6da1dab 100644 --- a/examples/blueprints-example/blueprints-example.cpp +++ b/examples/blueprints-example/blueprints-example.cpp @@ -1537,25 +1537,25 @@ struct Example: if (ed::BeginDelete()) { - ed::LinkId linkId = 0; - while (ed::QueryDeletedLink(&linkId)) + ed::NodeId nodeId = 0; + while (ed::QueryDeletedNode(&nodeId)) { if (ed::AcceptDeletedItem()) { - auto id = std::find_if(m_Links.begin(), m_Links.end(), [linkId](auto& link) { return link.ID == linkId; }); - if (id != m_Links.end()) - m_Links.erase(id); + auto id = std::find_if(m_Nodes.begin(), m_Nodes.end(), [nodeId](auto& node) { return node.ID == nodeId; }); + if (id != m_Nodes.end()) + m_Nodes.erase(id); } } - ed::NodeId nodeId = 0; - while (ed::QueryDeletedNode(&nodeId)) + ed::LinkId linkId = 0; + while (ed::QueryDeletedLink(&linkId)) { if (ed::AcceptDeletedItem()) { - auto id = std::find_if(m_Nodes.begin(), m_Nodes.end(), [nodeId](auto& node) { return node.ID == nodeId; }); - if (id != m_Nodes.end()) - m_Nodes.erase(id); + auto id = std::find_if(m_Links.begin(), m_Links.end(), [linkId](auto& link) { return link.ID == linkId; }); + if (id != m_Links.end()) + m_Links.erase(id); } } } From 7ee2e08093c8d88e05213df0da67dcc75fde376a Mon Sep 17 00:00:00 2001 From: georgeto Date: Mon, 3 Oct 2022 22:18:25 +0200 Subject: [PATCH 03/28] Blueprints example: Fix calculation broken during refactoring The refactoring in commit 2d5864dc83cfb06d39e526a094d6e989f5dd69d7 broke both the calculation of the separator rectangle and the calculation of the p2.y argument in the following AddLine call. --- examples/blueprints-example/utilities/builders.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/blueprints-example/utilities/builders.cpp b/examples/blueprints-example/utilities/builders.cpp index dd6abf6c..00cf0939 100644 --- a/examples/blueprints-example/utilities/builders.cpp +++ b/examples/blueprints-example/utilities/builders.cpp @@ -74,13 +74,13 @@ void util::BlueprintNodeBuilder::End() auto headerSeparatorMin = ImVec2(HeaderMin.x, HeaderMax.y); - auto headerSeparatorMax = ImVec2(HeaderMax.x, HeaderMin.y); + auto headerSeparatorMax = ImVec2(ContentMax.x, ContentMin.y); if ((headerSeparatorMax.x > headerSeparatorMin.x) && (headerSeparatorMax.y > headerSeparatorMin.y)) { drawList->AddLine( - headerSeparatorMin + ImVec2(-(8 - halfBorderWidth), -0.5f), - headerSeparatorMax + ImVec2( (8 - halfBorderWidth), -0.5f), + ImVec2(headerSeparatorMin.x - (8 - halfBorderWidth), headerSeparatorMin.y -0.5f), + ImVec2(headerSeparatorMax.x + (8 - halfBorderWidth), headerSeparatorMin.y - 0.5f), ImColor(255, 255, 255, 96 * alpha / (3 * 255)), 1.0f); } } From 1525ffbb079aa3bdb6c00c52b8bc8007a90cc7eb Mon Sep 17 00:00:00 2001 From: georgeto Date: Mon, 3 Oct 2022 22:21:49 +0200 Subject: [PATCH 04/28] Blueprints example: Simplify drawing of header-content separator line The calculation to draw the header-content separator line were unnecessarily complicated. --- examples/blueprints-example/utilities/builders.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/blueprints-example/utilities/builders.cpp b/examples/blueprints-example/utilities/builders.cpp index 00cf0939..a57ac9e4 100644 --- a/examples/blueprints-example/utilities/builders.cpp +++ b/examples/blueprints-example/utilities/builders.cpp @@ -72,15 +72,11 @@ void util::BlueprintNodeBuilder::End() headerColor, GetStyle().NodeRounding, 1 | 2); #endif - - auto headerSeparatorMin = ImVec2(HeaderMin.x, HeaderMax.y); - auto headerSeparatorMax = ImVec2(ContentMax.x, ContentMin.y); - - if ((headerSeparatorMax.x > headerSeparatorMin.x) && (headerSeparatorMax.y > headerSeparatorMin.y)) + if (ContentMin.y > HeaderMax.y) { drawList->AddLine( - ImVec2(headerSeparatorMin.x - (8 - halfBorderWidth), headerSeparatorMin.y -0.5f), - ImVec2(headerSeparatorMax.x + (8 - halfBorderWidth), headerSeparatorMin.y - 0.5f), + ImVec2(HeaderMin.x - (8 - halfBorderWidth), HeaderMax.y - 0.5f), + ImVec2(HeaderMax.x + (8 - halfBorderWidth), HeaderMax.y - 0.5f), ImColor(255, 255, 255, 96 * alpha / (3 * 255)), 1.0f); } } From ebaa9f83a10a51302ba218d2c43cc10d628da7b0 Mon Sep 17 00:00:00 2001 From: thedmd Date: Wed, 2 Nov 2022 08:04:54 +0100 Subject: [PATCH 05/28] Examples: Simplify and fix drawing of node header line (#180) --- docs/CHANGELOG.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index b3756b5c..32e13293 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -5,6 +5,7 @@ v0.9.2 (WIP): BUGFIX: Examples: Handle node deletion before links (#182) Deleting node queue connected links for deletion. + BUGFIX: Examples: Simplify and fix drawing of node header line (#180) v0.9.1 (2022-08-27): From 5f077c4e92fb919fa50744c5631f32d219559924 Mon Sep 17 00:00:00 2001 From: MultiPain <32590972+MultiPain@users.noreply.github.com> Date: Sat, 27 Aug 2022 13:26:29 +0900 Subject: [PATCH 06/28] Editor: Add offset of hover/select to style (thanks @MultiPain) --- docs/CHANGELOG.txt | 2 + .../blueprints-example/blueprints-example.cpp | 2 + imgui_node_editor.cpp | 14 +++-- imgui_node_editor.h | 58 ++++++++++--------- imgui_node_editor_internal.h | 2 +- 5 files changed, 46 insertions(+), 32 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 32e13293..b95bc5b6 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -1,5 +1,7 @@ v0.9.2 (WIP): + NEW: Editor: Add offset of hover/select to style (thanks @MultiPain) + BUGFIX: Editor: Correctly initialize 'width' for view resize code (thx @gnif) BUGFIX: Examples: Handle node deletion before links (#182) diff --git a/examples/blueprints-example/blueprints-example.cpp b/examples/blueprints-example/blueprints-example.cpp index e6da1dab..1eec9671 100644 --- a/examples/blueprints-example/blueprints-example.cpp +++ b/examples/blueprints-example/blueprints-example.cpp @@ -648,7 +648,9 @@ struct Example: ImGui::DragFloat("Node Rounding", &editorStyle.NodeRounding, 0.1f, 0.0f, 40.0f); ImGui::DragFloat("Node Border Width", &editorStyle.NodeBorderWidth, 0.1f, 0.0f, 15.0f); ImGui::DragFloat("Hovered Node Border Width", &editorStyle.HoveredNodeBorderWidth, 0.1f, 0.0f, 15.0f); + ImGui::DragFloat("Hovered Node Border Offset", &editorStyle.HoverNodeBorderOffset, 0.1f, -40.0f, 40.0f); ImGui::DragFloat("Selected Node Border Width", &editorStyle.SelectedNodeBorderWidth, 0.1f, 0.0f, 15.0f); + ImGui::DragFloat("Selected Node Border Offset", &editorStyle.SelectedNodeBorderOffset, 0.1f, -40.0f, 40.0f); ImGui::DragFloat("Pin Rounding", &editorStyle.PinRounding, 0.1f, 0.0f, 40.0f); ImGui::DragFloat("Pin Border Width", &editorStyle.PinBorderWidth, 0.1f, 0.0f, 15.0f); ImGui::DragFloat("Link Strength", &editorStyle.LinkStrength, 1.0f, 0.0f, 500.0f); diff --git a/imgui_node_editor.cpp b/imgui_node_editor.cpp index 0dad38db..c0ab57ea 100644 --- a/imgui_node_editor.cpp +++ b/imgui_node_editor.cpp @@ -688,7 +688,7 @@ void ed::Node::Draw(ImDrawList* drawList, DrawFlags flags) drawList->ChannelsSetCurrent(m_Channel + c_NodeBaseChannel); - DrawBorder(drawList, borderColor, editorStyle.SelectedNodeBorderWidth); + DrawBorder(drawList, borderColor, editorStyle.SelectedNodeBorderWidth, editorStyle.SelectedNodeBorderOffset); } else if (!IsGroup(this) && (flags & Hovered)) { @@ -697,16 +697,18 @@ void ed::Node::Draw(ImDrawList* drawList, DrawFlags flags) drawList->ChannelsSetCurrent(m_Channel + c_NodeBaseChannel); - DrawBorder(drawList, borderColor, editorStyle.HoveredNodeBorderWidth); + DrawBorder(drawList, borderColor, editorStyle.HoveredNodeBorderWidth, editorStyle.HoverNodeBorderOffset); } } -void ed::Node::DrawBorder(ImDrawList* drawList, ImU32 color, float thickness) +void ed::Node::DrawBorder(ImDrawList* drawList, ImU32 color, float thickness, float offset) { if (thickness > 0.0f) { - drawList->AddRect(m_Bounds.Min, m_Bounds.Max, - color, m_Rounding, c_AllRoundCornersFlags, thickness); + const ImVec2 extraOffset = ImVec2(offset, offset); + + drawList->AddRect(m_Bounds.Min - extraOffset, m_Bounds.Max + extraOffset, + color, ImMax(0.0f, m_Rounding + offset), c_AllRoundCornersFlags, thickness); } } @@ -5683,6 +5685,8 @@ float* ed::Style::GetVarFloatAddr(StyleVar idx) case StyleVar_GroupBorderWidth: return &GroupBorderWidth; case StyleVar_HighlightConnectedLinks: return &HighlightConnectedLinks; case StyleVar_SnapLinkToPinDir: return &SnapLinkToPinDir; + case StyleVar_HoveredNodeBorderOffset: return &HoverNodeBorderOffset; + case StyleVar_SelectedNodeBorderOffset: return &SelectedNodeBorderOffset; default: return nullptr; } } diff --git a/imgui_node_editor.h b/imgui_node_editor.h index a173cde3..b81a89c9 100644 --- a/imgui_node_editor.h +++ b/imgui_node_editor.h @@ -173,6 +173,8 @@ enum StyleVar StyleVar_GroupBorderWidth, StyleVar_HighlightConnectedLinks, StyleVar_SnapLinkToPinDir, + StyleVar_HoveredNodeBorderOffset, + StyleVar_SelectedNodeBorderOffset, StyleVar_Count }; @@ -183,7 +185,9 @@ struct Style float NodeRounding; float NodeBorderWidth; float HoveredNodeBorderWidth; + float HoverNodeBorderOffset; float SelectedNodeBorderWidth; + float SelectedNodeBorderOffset; float PinRounding; float PinBorderWidth; float LinkStrength; @@ -208,35 +212,37 @@ struct Style Style() { - NodePadding = ImVec4(8, 8, 8, 8); - NodeRounding = 12.0f; - NodeBorderWidth = 1.5f; - HoveredNodeBorderWidth = 3.5f; - SelectedNodeBorderWidth = 3.5f; - PinRounding = 4.0f; - PinBorderWidth = 0.0f; - LinkStrength = 100.0f; - SourceDirection = ImVec2(1.0f, 0.0f); - TargetDirection = ImVec2(-1.0f, 0.0f); - ScrollDuration = 0.35f; - FlowMarkerDistance = 30.0f; - FlowSpeed = 150.0f; - FlowDuration = 2.0f; - PivotAlignment = ImVec2(0.5f, 0.5f); - PivotSize = ImVec2(0.0f, 0.0f); - PivotScale = ImVec2(1, 1); + NodePadding = ImVec4(8, 8, 8, 8); + NodeRounding = 12.0f; + NodeBorderWidth = 1.5f; + HoveredNodeBorderWidth = 3.5f; + HoverNodeBorderOffset = 0.0f; + SelectedNodeBorderWidth = 3.5f; + SelectedNodeBorderOffset = 0.0f; + PinRounding = 4.0f; + PinBorderWidth = 0.0f; + LinkStrength = 100.0f; + SourceDirection = ImVec2(1.0f, 0.0f); + TargetDirection = ImVec2(-1.0f, 0.0f); + ScrollDuration = 0.35f; + FlowMarkerDistance = 30.0f; + FlowSpeed = 150.0f; + FlowDuration = 2.0f; + PivotAlignment = ImVec2(0.5f, 0.5f); + PivotSize = ImVec2(0.0f, 0.0f); + PivotScale = ImVec2(1, 1); #if IMGUI_VERSION_NUM > 18101 - PinCorners = ImDrawFlags_RoundCornersAll; + PinCorners = ImDrawFlags_RoundCornersAll; #else - PinCorners = ImDrawCornerFlags_All; + PinCorners = ImDrawCornerFlags_All; #endif - PinRadius = 0.0f; - PinArrowSize = 0.0f; - PinArrowWidth = 0.0f; - GroupRounding = 6.0f; - GroupBorderWidth = 1.0f; - HighlightConnectedLinks = 0.0f; - SnapLinkToPinDir = 0.0f; + PinRadius = 0.0f; + PinArrowSize = 0.0f; + PinArrowWidth = 0.0f; + GroupRounding = 6.0f; + GroupBorderWidth = 1.0f; + HighlightConnectedLinks = 0.0f; + SnapLinkToPinDir = 0.0f; Colors[StyleColor_Bg] = ImColor( 60, 60, 70, 200); Colors[StyleColor_Grid] = ImColor(120, 120, 120, 40); diff --git a/imgui_node_editor_internal.h b/imgui_node_editor_internal.h index 4c57725f..20e0b7b5 100644 --- a/imgui_node_editor_internal.h +++ b/imgui_node_editor_internal.h @@ -433,7 +433,7 @@ struct Node final: Object virtual bool IsSelectable() override { return true; } virtual void Draw(ImDrawList* drawList, DrawFlags flags = None) override final; - void DrawBorder(ImDrawList* drawList, ImU32 color, float thickness = 1.0f); + void DrawBorder(ImDrawList* drawList, ImU32 color, float thickness = 1.0f, float offset = 0.0f); void GetGroupedNodes(std::vector& result, bool append = false); From 0039aed4fa2ff77414b959d121a6d7c12df0dd38 Mon Sep 17 00:00:00 2001 From: thedmd Date: Wed, 2 Nov 2022 08:42:14 +0100 Subject: [PATCH 07/28] Editor: Cleanup tabs. --- docs/CHANGELOG.txt | 2 ++ imgui_node_editor.cpp | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index b95bc5b6..5f7e4d0c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -8,6 +8,8 @@ v0.9.2 (WIP): Deleting node queue connected links for deletion. BUGFIX: Examples: Simplify and fix drawing of node header line (#180) + + BUGFIX: Editor: Cleanup tabs. v0.9.1 (2022-08-27): diff --git a/imgui_node_editor.cpp b/imgui_node_editor.cpp index c0ab57ea..480ea475 100644 --- a/imgui_node_editor.cpp +++ b/imgui_node_editor.cpp @@ -202,34 +202,34 @@ static void ImDrawListSplitter_Grow(ImDrawList* draw_list, ImDrawListSplitter* s static void ImDrawList_ChannelsGrow(ImDrawList* draw_list, int channels_count) { - ImDrawListSplitter_Grow(draw_list, &draw_list->_Splitter, channels_count); + ImDrawListSplitter_Grow(draw_list, &draw_list->_Splitter, channels_count); } static void ImDrawListSplitter_SwapChannels(ImDrawListSplitter* splitter, int left, int right) { - IM_ASSERT(left < splitter->_Count && right < splitter->_Count); - if (left == right) - return; + IM_ASSERT(left < splitter->_Count && right < splitter->_Count); + if (left == right) + return; - auto currentChannel = splitter->_Current; + auto currentChannel = splitter->_Current; - auto* leftCmdBuffer = &splitter->_Channels[left]._CmdBuffer; - auto* leftIdxBuffer = &splitter->_Channels[left]._IdxBuffer; - auto* rightCmdBuffer = &splitter->_Channels[right]._CmdBuffer; - auto* rightIdxBuffer = &splitter->_Channels[right]._IdxBuffer; + auto* leftCmdBuffer = &splitter->_Channels[left]._CmdBuffer; + auto* leftIdxBuffer = &splitter->_Channels[left]._IdxBuffer; + auto* rightCmdBuffer = &splitter->_Channels[right]._CmdBuffer; + auto* rightIdxBuffer = &splitter->_Channels[right]._IdxBuffer; - leftCmdBuffer->swap(*rightCmdBuffer); - leftIdxBuffer->swap(*rightIdxBuffer); + leftCmdBuffer->swap(*rightCmdBuffer); + leftIdxBuffer->swap(*rightIdxBuffer); - if (currentChannel == left) - splitter->_Current = right; - else if (currentChannel == right) - splitter->_Current = left; + if (currentChannel == left) + splitter->_Current = right; + else if (currentChannel == right) + splitter->_Current = left; } static void ImDrawList_SwapChannels(ImDrawList* drawList, int left, int right) { - ImDrawListSplitter_SwapChannels(&drawList->_Splitter, left, right); + ImDrawListSplitter_SwapChannels(&drawList->_Splitter, left, right); } static void ImDrawList_SwapSplitter(ImDrawList* drawList, ImDrawListSplitter& splitter) @@ -1972,7 +1972,7 @@ void ed::EditorContext::Resume(SuspendFlags flags) bool ed::EditorContext::IsSuspended() { - return m_Canvas.IsSuspended(); + return m_Canvas.IsSuspended(); } bool ed::EditorContext::IsFocused() From 7f1f8559baa9c6476be45f4b3af99ce6e22d53a6 Mon Sep 17 00:00:00 2001 From: thedmd Date: Thu, 3 Nov 2022 02:20:25 +0100 Subject: [PATCH 08/28] Editor: Use ImGuiKey directly with ImGui r18822 (#183) --- docs/CHANGELOG.txt | 2 ++ imgui_node_editor.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 5f7e4d0c..080d77a2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -10,6 +10,8 @@ v0.9.2 (WIP): BUGFIX: Examples: Simplify and fix drawing of node header line (#180) BUGFIX: Editor: Cleanup tabs. + + BUGFIX: Editor: Use ImGuiKey directly with ImGui r18822 (#183) v0.9.1 (2022-08-27): diff --git a/imgui_node_editor.cpp b/imgui_node_editor.cpp index 480ea475..32b98984 100644 --- a/imgui_node_editor.cpp +++ b/imgui_node_editor.cpp @@ -40,6 +40,7 @@ namespace ax { namespace NodeEditor { namespace Detail { +# if !defined(IMGUI_VERSION_NUM) || (IMGUI_VERSION_NUM < 18822) # define DECLARE_KEY_TESTER(Key) \ DECLARE_HAS_NESTED(Key, Key) \ struct KeyTester_ ## Key \ @@ -69,6 +70,17 @@ static inline int GetKeyIndexForD() { return KeyTester_ImGuiKey_D::Get(nullptr); } +# else +static inline ImGuiKey GetKeyIndexForF() +{ + return ImGuiKey_F; +} + +static inline ImGuiKey GetKeyIndexForD() +{ + return ImGuiKey_D; +} +# endif } // namespace Detail } // namespace NodeEditor From a916e6af2fa7a687d4c1f1eb018a198be95cd8e6 Mon Sep 17 00:00:00 2001 From: thedmd Date: Thu, 3 Nov 2022 02:20:59 +0100 Subject: [PATCH 09/28] Examples: Use ImGuiKey directly with ImGui r18822 (#183) --- docs/CHANGELOG.txt | 6 ++++-- examples/application/source/imgui_extra_keys.h | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 080d77a2..20939c54 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -8,11 +8,13 @@ v0.9.2 (WIP): Deleting node queue connected links for deletion. BUGFIX: Examples: Simplify and fix drawing of node header line (#180) - + BUGFIX: Editor: Cleanup tabs. - + BUGFIX: Editor: Use ImGuiKey directly with ImGui r18822 (#183) + BUGFIX: Examples: Use ImGuiKey directly with ImGui r18822 (#183) + v0.9.1 (2022-08-27): diff --git a/examples/application/source/imgui_extra_keys.h b/examples/application/source/imgui_extra_keys.h index 850d51ad..2135b402 100644 --- a/examples/application/source/imgui_extra_keys.h +++ b/examples/application/source/imgui_extra_keys.h @@ -1,5 +1,8 @@ # pragma once # include + +# if !defined(IMGUI_VERSION_NUM) || (IMGUI_VERSION_NUM < 18822) + # include // https://stackoverflow.com/a/8597498 @@ -46,3 +49,17 @@ static inline int GetEnumValueForD() { return KeyTester_ImGuiKey_D::Get(nullptr); } + +# else + +static inline ImGuiKey GetEnumValueForF() +{ + return ImGuiKey_F; +} + +static inline ImGuiKey GetEnumValueForD() +{ + return ImGuiKey_D; +} + +# endif \ No newline at end of file From 99ec923a39062f556ec7676fb9ba6d302d109f76 Mon Sep 17 00:00:00 2001 From: thedmd Date: Thu, 3 Nov 2022 02:22:25 +0100 Subject: [PATCH 10/28] Examples: Use ImGuiKey_KeypadEnter with ImGui r18604 (#183) --- docs/CHANGELOG.txt | 2 ++ examples/application/source/imgui_impl_win32.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 20939c54..3cc03bcb 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -15,6 +15,8 @@ v0.9.2 (WIP): BUGFIX: Examples: Use ImGuiKey directly with ImGui r18822 (#183) + BUGFIX: Examples: Use ImGuiKey_KeypadEnter with ImGui r18604 (#183) + v0.9.1 (2022-08-27): diff --git a/examples/application/source/imgui_impl_win32.cpp b/examples/application/source/imgui_impl_win32.cpp index 6f158de2..f6ccb3e3 100644 --- a/examples/application/source/imgui_impl_win32.cpp +++ b/examples/application/source/imgui_impl_win32.cpp @@ -93,7 +93,11 @@ bool ImGui_ImplWin32_Init(void* hwnd) io.KeyMap[ImGuiKey_Space] = VK_SPACE; io.KeyMap[ImGuiKey_Enter] = VK_RETURN; io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; +# if defined(IMGUI_VERSION_NUM) && (IMGUI_VERSION_NUM >= 18604) + io.KeyMap[ImGuiKey_KeypadEnter] = VK_RETURN; +# else io.KeyMap[ImGuiKey_KeyPadEnter] = VK_RETURN; +# endif io.KeyMap[ImGuiKey_A] = 'A'; io.KeyMap[ImGuiKey_C] = 'C'; io.KeyMap[ImGuiKey_V] = 'V'; From 1a84dba26869b90b5789c38f8b66399d0779ec3c Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 14 Mar 2023 20:15:22 +0100 Subject: [PATCH 11/28] Editor: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut --- docs/CHANGELOG.txt | 2 ++ imgui_canvas.cpp | 4 +++- imgui_extra_math.h | 2 +- imgui_extra_math.inl | 2 +- imgui_node_editor_internal.h | 4 +++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 3cc03bcb..146bb06a 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -2,6 +2,8 @@ v0.9.2 (WIP): NEW: Editor: Add offset of hover/select to style (thanks @MultiPain) + CHANGE: Editor: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut + BUGFIX: Editor: Correctly initialize 'width' for view resize code (thx @gnif) BUGFIX: Examples: Handle node deletion before links (#182) diff --git a/imgui_canvas.cpp b/imgui_canvas.cpp index c71a4131..84796d0b 100644 --- a/imgui_canvas.cpp +++ b/imgui_canvas.cpp @@ -1,4 +1,6 @@ -# define IMGUI_DEFINE_MATH_OPERATORS +# ifndef IMGUI_DEFINE_MATH_OPERATORS +# define IMGUI_DEFINE_MATH_OPERATORS +# endif # include "imgui_canvas.h" # include diff --git a/imgui_extra_math.h b/imgui_extra_math.h index 30220556..83380f4e 100644 --- a/imgui_extra_math.h +++ b/imgui_extra_math.h @@ -15,10 +15,10 @@ //------------------------------------------------------------------------------ -# include # ifndef IMGUI_DEFINE_MATH_OPERATORS # define IMGUI_DEFINE_MATH_OPERATORS # endif +# include # include diff --git a/imgui_extra_math.inl b/imgui_extra_math.inl index 13cf9906..51fb5951 100644 --- a/imgui_extra_math.inl +++ b/imgui_extra_math.inl @@ -34,7 +34,7 @@ inline ImVec2 operator*(const float lhs, const ImVec2& rhs) return ImVec2(lhs * rhs.x, lhs * rhs.y); } -inline ImVec2 operator-(const ImVec2& lhs) +inline static ImVec2 operator-(const ImVec2& lhs) { return ImVec2(-lhs.x, -lhs.y); } diff --git a/imgui_node_editor_internal.h b/imgui_node_editor_internal.h index 20e0b7b5..33c74225 100644 --- a/imgui_node_editor_internal.h +++ b/imgui_node_editor_internal.h @@ -15,12 +15,14 @@ //------------------------------------------------------------------------------ +# ifndef IMGUI_DEFINE_MATH_OPERATORS +# define IMGUI_DEFINE_MATH_OPERATORS +# endif # include "imgui_node_editor.h" //------------------------------------------------------------------------------ # include -# define IMGUI_DEFINE_MATH_OPERATORS # include # include "imgui_extra_math.h" # include "imgui_bezier_math.h" From d7b19f21a650df8fccb256d300750de45944432c Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 2 May 2023 01:21:46 +0200 Subject: [PATCH 12/28] Examples: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut --- docs/CHANGELOG.txt | 2 ++ examples/blueprints-example/blueprints-example.cpp | 3 +-- examples/blueprints-example/utilities/builders.cpp | 2 +- examples/blueprints-example/utilities/drawing.cpp | 2 +- examples/blueprints-example/utilities/widgets.cpp | 2 +- examples/canvas-example/canvas-example.cpp | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 146bb06a..9d3adf86 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -4,6 +4,8 @@ v0.9.2 (WIP): CHANGE: Editor: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut + CHANGE: Examples: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut + BUGFIX: Editor: Correctly initialize 'width' for view resize code (thx @gnif) BUGFIX: Examples: Handle node deletion before links (#182) diff --git a/examples/blueprints-example/blueprints-example.cpp b/examples/blueprints-example/blueprints-example.cpp index 1eec9671..82d84430 100644 --- a/examples/blueprints-example/blueprints-example.cpp +++ b/examples/blueprints-example/blueprints-example.cpp @@ -1,10 +1,9 @@ +#define IMGUI_DEFINE_MATH_OPERATORS #include #include "utilities/builders.h" #include "utilities/widgets.h" #include - -#define IMGUI_DEFINE_MATH_OPERATORS #include #include diff --git a/examples/blueprints-example/utilities/builders.cpp b/examples/blueprints-example/utilities/builders.cpp index a57ac9e4..e8ae020a 100644 --- a/examples/blueprints-example/utilities/builders.cpp +++ b/examples/blueprints-example/utilities/builders.cpp @@ -7,8 +7,8 @@ // CREDITS // Written by Michal Cichon //------------------------------------------------------------------------------ -# include "builders.h" # define IMGUI_DEFINE_MATH_OPERATORS +# include "builders.h" # include diff --git a/examples/blueprints-example/utilities/drawing.cpp b/examples/blueprints-example/utilities/drawing.cpp index 208c9cef..1f255eec 100644 --- a/examples/blueprints-example/utilities/drawing.cpp +++ b/examples/blueprints-example/utilities/drawing.cpp @@ -1,5 +1,5 @@ -# include "drawing.h" # define IMGUI_DEFINE_MATH_OPERATORS +# include "drawing.h" # include void ax::Drawing::DrawIcon(ImDrawList* drawList, const ImVec2& a, const ImVec2& b, IconType type, bool filled, ImU32 color, ImU32 innerColor) diff --git a/examples/blueprints-example/utilities/widgets.cpp b/examples/blueprints-example/utilities/widgets.cpp index 9faa5e02..202c8e23 100644 --- a/examples/blueprints-example/utilities/widgets.cpp +++ b/examples/blueprints-example/utilities/widgets.cpp @@ -1,5 +1,5 @@ -# include "widgets.h" # define IMGUI_DEFINE_MATH_OPERATORS +# include "widgets.h" # include void ax::Widgets::Icon(const ImVec2& size, IconType type, bool filled, const ImVec4& color/* = ImVec4(1, 1, 1, 1)*/, const ImVec4& innerColor/* = ImVec4(0, 0, 0, 0)*/) diff --git a/examples/canvas-example/canvas-example.cpp b/examples/canvas-example/canvas-example.cpp index 370f97be..f07c3e38 100644 --- a/examples/canvas-example/canvas-example.cpp +++ b/examples/canvas-example/canvas-example.cpp @@ -1,5 +1,5 @@ -# include # define IMGUI_DEFINE_MATH_OPERATORS +# include # include # include # include From 26e0511bfe3f855eb27d5c5c921963152e4d83a5 Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 2 May 2023 01:26:59 +0200 Subject: [PATCH 13/28] Editor: Support ImGui r18836 after SetItemUsingMouseWheel removal (#218), thanks @ocornut # Conflicts: # docs/CHANGELOG.txt --- docs/CHANGELOG.txt | 2 ++ imgui_node_editor.cpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 9d3adf86..50430c27 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -2,6 +2,8 @@ v0.9.2 (WIP): NEW: Editor: Add offset of hover/select to style (thanks @MultiPain) + CHANGE: Editor: Support ImGui r18836 after SetItemUsingMouseWheel removal (#218), thanks @ocornut + CHANGE: Editor: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut CHANGE: Examples: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut diff --git a/imgui_node_editor.cpp b/imgui_node_editor.cpp index 32b98984..0295892b 100644 --- a/imgui_node_editor.cpp +++ b/imgui_node_editor.cpp @@ -2560,7 +2560,10 @@ ed::Control ed::EditorContext::BuildControl(bool allowOffscreen) if (!allowOffscreen && !m_IsHovered) return Control(); -# if IMGUI_VERSION_NUM >= 17909 +# if IMGUI_VERSION_NUM >= 18836 + if (m_IsHoveredWithoutOverlapp) + ImGui::SetItemKeyOwner(ImGuiKey_MouseWheelY); +# elif IMGUI_VERSION_NUM >= 17909 if (m_IsHoveredWithoutOverlapp) ImGui::SetItemUsingMouseWheel(); # endif From d3d46898d905ddbf9977c40a2f475002df635bd8 Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 2 May 2023 01:30:52 +0200 Subject: [PATCH 14/28] Examples: Add missing include for std::intptr_t (#199) --- docs/CHANGELOG.txt | 2 ++ examples/application/source/renderer_ogl3.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 50430c27..e3bb5c43 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -23,6 +23,8 @@ v0.9.2 (WIP): BUGFIX: Examples: Use ImGuiKey_KeypadEnter with ImGui r18604 (#183) + BUGFIX: Examples: Add missing include for std::intptr_t (#199) + v0.9.1 (2022-08-27): diff --git a/examples/application/source/renderer_ogl3.cpp b/examples/application/source/renderer_ogl3.cpp index 72a7dfc3..69f825be 100644 --- a/examples/application/source/renderer_ogl3.cpp +++ b/examples/application/source/renderer_ogl3.cpp @@ -4,6 +4,7 @@ # include "platform.h" # include +# include // std::intptr_t # if PLATFORM(WINDOWS) # define NOMINMAX From 7d0f3150768e3d7aead4d3838825aecc42d1c1c4 Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 2 May 2023 17:25:05 +0200 Subject: [PATCH 15/28] Examples: Don't use empty string as identifier --- docs/CHANGELOG.txt | 2 ++ examples/blueprints-example/blueprints-example.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index e3bb5c43..d0eb171c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -25,6 +25,8 @@ v0.9.2 (WIP): BUGFIX: Examples: Add missing include for std::intptr_t (#199) + BUGFIX: Examples: Don't use empty string as identifier + v0.9.1 (2022-08-27): diff --git a/examples/blueprints-example/blueprints-example.cpp b/examples/blueprints-example/blueprints-example.cpp index 82d84430..58f5e1bf 100644 --- a/examples/blueprints-example/blueprints-example.cpp +++ b/examples/blueprints-example/blueprints-example.cpp @@ -683,7 +683,7 @@ struct Example: ImGui::EndHorizontal(); static ImGuiTextFilter filter; - filter.Draw("", paneWidth); + filter.Draw("##filter", paneWidth); ImGui::Spacing(); From 268e5fec2dcdfc1cf06fff078f798f819e09f780 Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 2 May 2023 17:38:45 +0200 Subject: [PATCH 16/28] Editor: Add IMGUI_NODE_EDITOR_API to support building editor as a shared library (#189) --- docs/CHANGELOG.txt | 2 + imgui_node_editor.h | 290 ++++++++++++++++++++++---------------------- 2 files changed, 150 insertions(+), 142 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d0eb171c..bc13c365 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -2,6 +2,8 @@ v0.9.2 (WIP): NEW: Editor: Add offset of hover/select to style (thanks @MultiPain) + NEW: Editor: Add IMGUI_NODE_EDITOR_API to support building editor as a shared library (#189) + CHANGE: Editor: Support ImGui r18836 after SetItemUsingMouseWheel removal (#218), thanks @ocornut CHANGE: Editor: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut diff --git a/imgui_node_editor.h b/imgui_node_editor.h index b81a89c9..48bc209d 100644 --- a/imgui_node_editor.h +++ b/imgui_node_editor.h @@ -25,6 +25,12 @@ # define IMGUI_NODE_EDITOR_VERSION_NUM 000902 +//------------------------------------------------------------------------------ +#ifndef IMGUI_NODE_EDITOR_API +#define IMGUI_NODE_EDITOR_API +#endif + + //------------------------------------------------------------------------------ namespace ax { namespace NodeEditor { @@ -272,150 +278,150 @@ struct EditorContext; //------------------------------------------------------------------------------ -void SetCurrentEditor(EditorContext* ctx); -EditorContext* GetCurrentEditor(); -EditorContext* CreateEditor(const Config* config = nullptr); -void DestroyEditor(EditorContext* ctx); -const Config& GetConfig(EditorContext* ctx = nullptr); - -Style& GetStyle(); -const char* GetStyleColorName(StyleColor colorIndex); - -void PushStyleColor(StyleColor colorIndex, const ImVec4& color); -void PopStyleColor(int count = 1); - -void PushStyleVar(StyleVar varIndex, float value); -void PushStyleVar(StyleVar varIndex, const ImVec2& value); -void PushStyleVar(StyleVar varIndex, const ImVec4& value); -void PopStyleVar(int count = 1); - -void Begin(const char* id, const ImVec2& size = ImVec2(0, 0)); -void End(); - -void BeginNode(NodeId id); -void BeginPin(PinId id, PinKind kind); -void PinRect(const ImVec2& a, const ImVec2& b); -void PinPivotRect(const ImVec2& a, const ImVec2& b); -void PinPivotSize(const ImVec2& size); -void PinPivotScale(const ImVec2& scale); -void PinPivotAlignment(const ImVec2& alignment); -void EndPin(); -void Group(const ImVec2& size); -void EndNode(); - -bool BeginGroupHint(NodeId nodeId); -ImVec2 GetGroupMin(); -ImVec2 GetGroupMax(); -ImDrawList* GetHintForegroundDrawList(); -ImDrawList* GetHintBackgroundDrawList(); -void EndGroupHint(); +IMGUI_NODE_EDITOR_API void SetCurrentEditor(EditorContext* ctx); +IMGUI_NODE_EDITOR_API EditorContext* GetCurrentEditor(); +IMGUI_NODE_EDITOR_API EditorContext* CreateEditor(const Config* config = nullptr); +IMGUI_NODE_EDITOR_API void DestroyEditor(EditorContext* ctx); +IMGUI_NODE_EDITOR_API const Config& GetConfig(EditorContext* ctx = nullptr); + +IMGUI_NODE_EDITOR_API Style& GetStyle(); +IMGUI_NODE_EDITOR_API const char* GetStyleColorName(StyleColor colorIndex); + +IMGUI_NODE_EDITOR_API void PushStyleColor(StyleColor colorIndex, const ImVec4& color); +IMGUI_NODE_EDITOR_API void PopStyleColor(int count = 1); + +IMGUI_NODE_EDITOR_API void PushStyleVar(StyleVar varIndex, float value); +IMGUI_NODE_EDITOR_API void PushStyleVar(StyleVar varIndex, const ImVec2& value); +IMGUI_NODE_EDITOR_API void PushStyleVar(StyleVar varIndex, const ImVec4& value); +IMGUI_NODE_EDITOR_API void PopStyleVar(int count = 1); + +IMGUI_NODE_EDITOR_API void Begin(const char* id, const ImVec2& size = ImVec2(0, 0)); +IMGUI_NODE_EDITOR_API void End(); + +IMGUI_NODE_EDITOR_API void BeginNode(NodeId id); +IMGUI_NODE_EDITOR_API void BeginPin(PinId id, PinKind kind); +IMGUI_NODE_EDITOR_API void PinRect(const ImVec2& a, const ImVec2& b); +IMGUI_NODE_EDITOR_API void PinPivotRect(const ImVec2& a, const ImVec2& b); +IMGUI_NODE_EDITOR_API void PinPivotSize(const ImVec2& size); +IMGUI_NODE_EDITOR_API void PinPivotScale(const ImVec2& scale); +IMGUI_NODE_EDITOR_API void PinPivotAlignment(const ImVec2& alignment); +IMGUI_NODE_EDITOR_API void EndPin(); +IMGUI_NODE_EDITOR_API void Group(const ImVec2& size); +IMGUI_NODE_EDITOR_API void EndNode(); + +IMGUI_NODE_EDITOR_API bool BeginGroupHint(NodeId nodeId); +IMGUI_NODE_EDITOR_API ImVec2 GetGroupMin(); +IMGUI_NODE_EDITOR_API ImVec2 GetGroupMax(); +IMGUI_NODE_EDITOR_API ImDrawList* GetHintForegroundDrawList(); +IMGUI_NODE_EDITOR_API ImDrawList* GetHintBackgroundDrawList(); +IMGUI_NODE_EDITOR_API void EndGroupHint(); // TODO: Add a way to manage node background channels -ImDrawList* GetNodeBackgroundDrawList(NodeId nodeId); - -bool Link(LinkId id, PinId startPinId, PinId endPinId, const ImVec4& color = ImVec4(1, 1, 1, 1), float thickness = 1.0f); - -void Flow(LinkId linkId, FlowDirection direction = FlowDirection::Forward); - -bool BeginCreate(const ImVec4& color = ImVec4(1, 1, 1, 1), float thickness = 1.0f); -bool QueryNewLink(PinId* startId, PinId* endId); -bool QueryNewLink(PinId* startId, PinId* endId, const ImVec4& color, float thickness = 1.0f); -bool QueryNewNode(PinId* pinId); -bool QueryNewNode(PinId* pinId, const ImVec4& color, float thickness = 1.0f); -bool AcceptNewItem(); -bool AcceptNewItem(const ImVec4& color, float thickness = 1.0f); -void RejectNewItem(); -void RejectNewItem(const ImVec4& color, float thickness = 1.0f); -void EndCreate(); - -bool BeginDelete(); -bool QueryDeletedLink(LinkId* linkId, PinId* startId = nullptr, PinId* endId = nullptr); -bool QueryDeletedNode(NodeId* nodeId); -bool AcceptDeletedItem(bool deleteDependencies = true); -void RejectDeletedItem(); -void EndDelete(); - -void SetNodePosition(NodeId nodeId, const ImVec2& editorPosition); -void SetGroupSize(NodeId nodeId, const ImVec2& size); -ImVec2 GetNodePosition(NodeId nodeId); -ImVec2 GetNodeSize(NodeId nodeId); -void CenterNodeOnScreen(NodeId nodeId); -void SetNodeZPosition(NodeId nodeId, float z); // Sets node z position, nodes with higher value are drawn over nodes with lower value -float GetNodeZPosition(NodeId nodeId); // Returns node z position, defaults is 0.0f - -void RestoreNodeState(NodeId nodeId); - -void Suspend(); -void Resume(); -bool IsSuspended(); - -bool IsActive(); - -bool HasSelectionChanged(); -int GetSelectedObjectCount(); -int GetSelectedNodes(NodeId* nodes, int size); -int GetSelectedLinks(LinkId* links, int size); -bool IsNodeSelected(NodeId nodeId); -bool IsLinkSelected(LinkId linkId); -void ClearSelection(); -void SelectNode(NodeId nodeId, bool append = false); -void SelectLink(LinkId linkId, bool append = false); -void DeselectNode(NodeId nodeId); -void DeselectLink(LinkId linkId); - -bool DeleteNode(NodeId nodeId); -bool DeleteLink(LinkId linkId); - -bool HasAnyLinks(NodeId nodeId); // Returns true if node has any link connected -bool HasAnyLinks(PinId pinId); // Return true if pin has any link connected -int BreakLinks(NodeId nodeId); // Break all links connected to this node -int BreakLinks(PinId pinId); // Break all links connected to this pin - -void NavigateToContent(float duration = -1); -void NavigateToSelection(bool zoomIn = false, float duration = -1); - -bool ShowNodeContextMenu(NodeId* nodeId); -bool ShowPinContextMenu(PinId* pinId); -bool ShowLinkContextMenu(LinkId* linkId); -bool ShowBackgroundContextMenu(); - -void EnableShortcuts(bool enable); -bool AreShortcutsEnabled(); - -bool BeginShortcut(); -bool AcceptCut(); -bool AcceptCopy(); -bool AcceptPaste(); -bool AcceptDuplicate(); -bool AcceptCreateNode(); -int GetActionContextSize(); -int GetActionContextNodes(NodeId* nodes, int size); -int GetActionContextLinks(LinkId* links, int size); -void EndShortcut(); - -float GetCurrentZoom(); - -NodeId GetHoveredNode(); -PinId GetHoveredPin(); -LinkId GetHoveredLink(); -NodeId GetDoubleClickedNode(); -PinId GetDoubleClickedPin(); -LinkId GetDoubleClickedLink(); -bool IsBackgroundClicked(); -bool IsBackgroundDoubleClicked(); -ImGuiMouseButton GetBackgroundClickButtonIndex(); // -1 if none -ImGuiMouseButton GetBackgroundDoubleClickButtonIndex(); // -1 if none - -bool GetLinkPins(LinkId linkId, PinId* startPinId, PinId* endPinId); // pass nullptr if particular pin do not interest you - -bool PinHadAnyLinks(PinId pinId); - -ImVec2 GetScreenSize(); -ImVec2 ScreenToCanvas(const ImVec2& pos); -ImVec2 CanvasToScreen(const ImVec2& pos); - -int GetNodeCount(); // Returns number of submitted nodes since Begin() call -int GetOrderedNodeIds(NodeId* nodes, int size); // Fills an array with node id's in order they're drawn; up to 'size` elements are set. Returns actual size of filled id's. +IMGUI_NODE_EDITOR_API ImDrawList* GetNodeBackgroundDrawList(NodeId nodeId); + +IMGUI_NODE_EDITOR_API bool Link(LinkId id, PinId startPinId, PinId endPinId, const ImVec4& color = ImVec4(1, 1, 1, 1), float thickness = 1.0f); + +IMGUI_NODE_EDITOR_API void Flow(LinkId linkId, FlowDirection direction = FlowDirection::Forward); + +IMGUI_NODE_EDITOR_API bool BeginCreate(const ImVec4& color = ImVec4(1, 1, 1, 1), float thickness = 1.0f); +IMGUI_NODE_EDITOR_API bool QueryNewLink(PinId* startId, PinId* endId); +IMGUI_NODE_EDITOR_API bool QueryNewLink(PinId* startId, PinId* endId, const ImVec4& color, float thickness = 1.0f); +IMGUI_NODE_EDITOR_API bool QueryNewNode(PinId* pinId); +IMGUI_NODE_EDITOR_API bool QueryNewNode(PinId* pinId, const ImVec4& color, float thickness = 1.0f); +IMGUI_NODE_EDITOR_API bool AcceptNewItem(); +IMGUI_NODE_EDITOR_API bool AcceptNewItem(const ImVec4& color, float thickness = 1.0f); +IMGUI_NODE_EDITOR_API void RejectNewItem(); +IMGUI_NODE_EDITOR_API void RejectNewItem(const ImVec4& color, float thickness = 1.0f); +IMGUI_NODE_EDITOR_API void EndCreate(); + +IMGUI_NODE_EDITOR_API bool BeginDelete(); +IMGUI_NODE_EDITOR_API bool QueryDeletedLink(LinkId* linkId, PinId* startId = nullptr, PinId* endId = nullptr); +IMGUI_NODE_EDITOR_API bool QueryDeletedNode(NodeId* nodeId); +IMGUI_NODE_EDITOR_API bool AcceptDeletedItem(bool deleteDependencies = true); +IMGUI_NODE_EDITOR_API void RejectDeletedItem(); +IMGUI_NODE_EDITOR_API void EndDelete(); + +IMGUI_NODE_EDITOR_API void SetNodePosition(NodeId nodeId, const ImVec2& editorPosition); +IMGUI_NODE_EDITOR_API void SetGroupSize(NodeId nodeId, const ImVec2& size); +IMGUI_NODE_EDITOR_API ImVec2 GetNodePosition(NodeId nodeId); +IMGUI_NODE_EDITOR_API ImVec2 GetNodeSize(NodeId nodeId); +IMGUI_NODE_EDITOR_API void CenterNodeOnScreen(NodeId nodeId); +IMGUI_NODE_EDITOR_API void SetNodeZPosition(NodeId nodeId, float z); // Sets node z position, nodes with higher value are drawn over nodes with lower value +IMGUI_NODE_EDITOR_API float GetNodeZPosition(NodeId nodeId); // Returns node z position, defaults is 0.0f + +IMGUI_NODE_EDITOR_API void RestoreNodeState(NodeId nodeId); + +IMGUI_NODE_EDITOR_API void Suspend(); +IMGUI_NODE_EDITOR_API void Resume(); +IMGUI_NODE_EDITOR_API bool IsSuspended(); + +IMGUI_NODE_EDITOR_API bool IsActive(); + +IMGUI_NODE_EDITOR_API bool HasSelectionChanged(); +IMGUI_NODE_EDITOR_API int GetSelectedObjectCount(); +IMGUI_NODE_EDITOR_API int GetSelectedNodes(NodeId* nodes, int size); +IMGUI_NODE_EDITOR_API int GetSelectedLinks(LinkId* links, int size); +IMGUI_NODE_EDITOR_API bool IsNodeSelected(NodeId nodeId); +IMGUI_NODE_EDITOR_API bool IsLinkSelected(LinkId linkId); +IMGUI_NODE_EDITOR_API void ClearSelection(); +IMGUI_NODE_EDITOR_API void SelectNode(NodeId nodeId, bool append = false); +IMGUI_NODE_EDITOR_API void SelectLink(LinkId linkId, bool append = false); +IMGUI_NODE_EDITOR_API void DeselectNode(NodeId nodeId); +IMGUI_NODE_EDITOR_API void DeselectLink(LinkId linkId); + +IMGUI_NODE_EDITOR_API bool DeleteNode(NodeId nodeId); +IMGUI_NODE_EDITOR_API bool DeleteLink(LinkId linkId); + +IMGUI_NODE_EDITOR_API bool HasAnyLinks(NodeId nodeId); // Returns true if node has any link connected +IMGUI_NODE_EDITOR_API bool HasAnyLinks(PinId pinId); // Return true if pin has any link connected +IMGUI_NODE_EDITOR_API int BreakLinks(NodeId nodeId); // Break all links connected to this node +IMGUI_NODE_EDITOR_API int BreakLinks(PinId pinId); // Break all links connected to this pin + +IMGUI_NODE_EDITOR_API void NavigateToContent(float duration = -1); +IMGUI_NODE_EDITOR_API void NavigateToSelection(bool zoomIn = false, float duration = -1); + +IMGUI_NODE_EDITOR_API bool ShowNodeContextMenu(NodeId* nodeId); +IMGUI_NODE_EDITOR_API bool ShowPinContextMenu(PinId* pinId); +IMGUI_NODE_EDITOR_API bool ShowLinkContextMenu(LinkId* linkId); +IMGUI_NODE_EDITOR_API bool ShowBackgroundContextMenu(); + +IMGUI_NODE_EDITOR_API void EnableShortcuts(bool enable); +IMGUI_NODE_EDITOR_API bool AreShortcutsEnabled(); + +IMGUI_NODE_EDITOR_API bool BeginShortcut(); +IMGUI_NODE_EDITOR_API bool AcceptCut(); +IMGUI_NODE_EDITOR_API bool AcceptCopy(); +IMGUI_NODE_EDITOR_API bool AcceptPaste(); +IMGUI_NODE_EDITOR_API bool AcceptDuplicate(); +IMGUI_NODE_EDITOR_API bool AcceptCreateNode(); +IMGUI_NODE_EDITOR_API int GetActionContextSize(); +IMGUI_NODE_EDITOR_API int GetActionContextNodes(NodeId* nodes, int size); +IMGUI_NODE_EDITOR_API int GetActionContextLinks(LinkId* links, int size); +IMGUI_NODE_EDITOR_API void EndShortcut(); + +IMGUI_NODE_EDITOR_API float GetCurrentZoom(); + +IMGUI_NODE_EDITOR_API NodeId GetHoveredNode(); +IMGUI_NODE_EDITOR_API PinId GetHoveredPin(); +IMGUI_NODE_EDITOR_API LinkId GetHoveredLink(); +IMGUI_NODE_EDITOR_API NodeId GetDoubleClickedNode(); +IMGUI_NODE_EDITOR_API PinId GetDoubleClickedPin(); +IMGUI_NODE_EDITOR_API LinkId GetDoubleClickedLink(); +IMGUI_NODE_EDITOR_API bool IsBackgroundClicked(); +IMGUI_NODE_EDITOR_API bool IsBackgroundDoubleClicked(); +IMGUI_NODE_EDITOR_API ImGuiMouseButton GetBackgroundClickButtonIndex(); // -1 if none +IMGUI_NODE_EDITOR_API ImGuiMouseButton GetBackgroundDoubleClickButtonIndex(); // -1 if none + +IMGUI_NODE_EDITOR_API bool GetLinkPins(LinkId linkId, PinId* startPinId, PinId* endPinId); // pass nullptr if particular pin do not interest you + +IMGUI_NODE_EDITOR_API bool PinHadAnyLinks(PinId pinId); + +IMGUI_NODE_EDITOR_API ImVec2 GetScreenSize(); +IMGUI_NODE_EDITOR_API ImVec2 ScreenToCanvas(const ImVec2& pos); +IMGUI_NODE_EDITOR_API ImVec2 CanvasToScreen(const ImVec2& pos); + +IMGUI_NODE_EDITOR_API int GetNodeCount(); // Returns number of submitted nodes since Begin() call +IMGUI_NODE_EDITOR_API int GetOrderedNodeIds(NodeId* nodes, int size); // Fills an array with node id's in order they're drawn; up to 'size` elements are set. Returns actual size of filled id's. From 190757edab5acf419375e0798d675feeb6bc0f89 Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 2 May 2023 17:39:28 +0200 Subject: [PATCH 17/28] Canvas: Add IMGUIEX_CANVAS_API to support building canvas as a shared library (#189) --- docs/CHANGELOG.txt | 2 ++ imgui_canvas.h | 44 ++++++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index bc13c365..8c83f7e7 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -4,6 +4,8 @@ v0.9.2 (WIP): NEW: Editor: Add IMGUI_NODE_EDITOR_API to support building editor as a shared library (#189) + NEW: Canvas: Add IMGUIEX_CANVAS_API to support building canvas as a shared library (#189) + CHANGE: Editor: Support ImGui r18836 after SetItemUsingMouseWheel removal (#218), thanks @ocornut CHANGE: Editor: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut diff --git a/imgui_canvas.h b/imgui_canvas.h index e5e49594..73a4db72 100644 --- a/imgui_canvas.h +++ b/imgui_canvas.h @@ -51,6 +51,10 @@ # include # include // ImRect, ImFloor +#ifndef IMGUIEX_CANVAS_API +#define IMGUIEX_CANVAS_API +#endif + namespace ImGuiEx { struct CanvasView @@ -106,13 +110,13 @@ struct Canvas // // You can query size of the canvas while it is being drawn // by calling Rect(). - bool Begin(const char* id, const ImVec2& size); - bool Begin(ImGuiID id, const ImVec2& size); + IMGUIEX_CANVAS_API bool Begin(const char* id, const ImVec2& size); + IMGUIEX_CANVAS_API bool Begin(ImGuiID id, const ImVec2& size); // Ends interaction with canvas plane. // // Must be called only when Begin() retuned true. - void End(); + IMGUIEX_CANVAS_API void End(); // Sets visible region of canvas plane. // @@ -120,50 +124,50 @@ struct Canvas // corner of the canvas. // // Scale greater than 1 make canvas content be bigger, less than 1 smaller. - void SetView(const ImVec2& origin, float scale); - void SetView(const CanvasView& view); + IMGUIEX_CANVAS_API void SetView(const ImVec2& origin, float scale); + IMGUIEX_CANVAS_API void SetView(const CanvasView& view); // Centers view over specific point on canvas plane. // // View will be centered on specific point by changing origin // but not scale. - void CenterView(const ImVec2& canvasPoint); + IMGUIEX_CANVAS_API void CenterView(const ImVec2& canvasPoint); // Calculates view over specific point on canvas plane. - CanvasView CalcCenterView(const ImVec2& canvasPoint) const; + IMGUIEX_CANVAS_API CanvasView CalcCenterView(const ImVec2& canvasPoint) const; // Centers view over specific rectangle on canvas plane. // // Whole rectangle will fit in canvas view. This will affect both // origin and scale. - void CenterView(const ImRect& canvasRect); + IMGUIEX_CANVAS_API void CenterView(const ImRect& canvasRect); // Calculates view over specific rectangle on canvas plane. - CanvasView CalcCenterView(const ImRect& canvasRect) const; + IMGUIEX_CANVAS_API CanvasView CalcCenterView(const ImRect& canvasRect) const; // Suspends canvas by returning to normal ImGui transformation space. // While suspended UI will not be drawn on canvas plane. // // Calls to Suspend()/Resume() are symetrical. Each call to Suspend() // must be matched with call to Resume(). - void Suspend(); - void Resume(); + IMGUIEX_CANVAS_API void Suspend(); + IMGUIEX_CANVAS_API void Resume(); // Transforms point from canvas plane to ImGui. - ImVec2 FromLocal(const ImVec2& point) const; - ImVec2 FromLocal(const ImVec2& point, const CanvasView& view) const; + IMGUIEX_CANVAS_API ImVec2 FromLocal(const ImVec2& point) const; + IMGUIEX_CANVAS_API ImVec2 FromLocal(const ImVec2& point, const CanvasView& view) const; // Transforms vector from canvas plant to ImGui. - ImVec2 FromLocalV(const ImVec2& vector) const; - ImVec2 FromLocalV(const ImVec2& vector, const CanvasView& view) const; + IMGUIEX_CANVAS_API ImVec2 FromLocalV(const ImVec2& vector) const; + IMGUIEX_CANVAS_API ImVec2 FromLocalV(const ImVec2& vector, const CanvasView& view) const; // Transforms point from ImGui to canvas plane. - ImVec2 ToLocal(const ImVec2& point) const; - ImVec2 ToLocal(const ImVec2& point, const CanvasView& view) const; + IMGUIEX_CANVAS_API ImVec2 ToLocal(const ImVec2& point) const; + IMGUIEX_CANVAS_API ImVec2 ToLocal(const ImVec2& point, const CanvasView& view) const; // Transforms vector from ImGui to canvas plane. - ImVec2 ToLocalV(const ImVec2& vector) const; - ImVec2 ToLocalV(const ImVec2& vector, const CanvasView& view) const; + IMGUIEX_CANVAS_API ImVec2 ToLocalV(const ImVec2& vector) const; + IMGUIEX_CANVAS_API ImVec2 ToLocalV(const ImVec2& vector, const CanvasView& view) const; // Returns widget bounds. // @@ -175,7 +179,7 @@ struct Canvas const ImRect& ViewRect() const { return m_ViewRect; } // Calculates visible region for view. - ImRect CalcViewRect(const CanvasView& view) const; + IMGUIEX_CANVAS_API ImRect CalcViewRect(const CanvasView& view) const; // Returns current view. const CanvasView& View() const { return m_View; } From 9385318725eff854ab83811c9d0b30407b965479 Mon Sep 17 00:00:00 2001 From: thedmd Date: Thu, 31 Aug 2023 22:43:25 +0200 Subject: [PATCH 18/28] Canvas: Don't use deprecated SetItemAllowOverlap (#250) --- docs/CHANGELOG.txt | 2 ++ imgui_canvas.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8c83f7e7..468ab45a 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -12,6 +12,8 @@ v0.9.2 (WIP): CHANGE: Examples: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut + CHANGE: Canvas: Don't use deprecated SetItemAllowOverlap (#250) + BUGFIX: Editor: Correctly initialize 'width' for view resize code (thx @gnif) BUGFIX: Examples: Handle node deletion before links (#182) diff --git a/imgui_canvas.cpp b/imgui_canvas.cpp index 84796d0b..8d3721d2 100644 --- a/imgui_canvas.cpp +++ b/imgui_canvas.cpp @@ -133,6 +133,10 @@ bool ImGuiEx::Canvas::Begin(ImGuiID id, const ImVec2& size) EnterLocalSpace(); +# if IMGUI_VERSION_NUM >= 18967 + ImGui::SetNextItemAllowOverlap(); +# endif + // Emit dummy widget matching bounds of the canvas. ImGui::SetCursorScreenPos(m_ViewRect.Min); ImGui::Dummy(m_ViewRect.GetSize()); @@ -164,7 +168,9 @@ void ImGuiEx::Canvas::End() ImGui::GetCurrentWindow()->DC.CursorMaxPos = m_WindowCursorMaxBackup; +# if IMGUI_VERSION_NUM < 18967 ImGui::SetItemAllowOverlap(); +# endif // Emit dummy widget matching bounds of the canvas. ImGui::SetCursorScreenPos(m_WidgetPosition); From b7f4aa47ee56fcea3649db7a89f364ba497d0de3 Mon Sep 17 00:00:00 2001 From: thedmd Date: Thu, 31 Aug 2023 22:46:44 +0200 Subject: [PATCH 19/28] Editor: Unary operator- for ImVec2 is defined by ImGui since r18955 --- docs/CHANGELOG.txt | 4 ++++ imgui_extra_math.h | 2 ++ imgui_extra_math.inl | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 468ab45a..a830b152 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -14,6 +14,10 @@ v0.9.2 (WIP): CHANGE: Canvas: Don't use deprecated SetItemAllowOverlap (#250) + CHANGE: Editor: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut + + CHANGE: Editor: Unary operator- for ImVec2 is defined by ImGui since r18955 (#248) + BUGFIX: Editor: Correctly initialize 'width' for view resize code (thx @gnif) BUGFIX: Examples: Handle node deletion before links (#182) diff --git a/imgui_extra_math.h b/imgui_extra_math.h index 83380f4e..5c46cc43 100644 --- a/imgui_extra_math.h +++ b/imgui_extra_math.h @@ -33,7 +33,9 @@ struct ImLine inline bool operator==(const ImVec2& lhs, const ImVec2& rhs); inline bool operator!=(const ImVec2& lhs, const ImVec2& rhs); inline ImVec2 operator*(const float lhs, const ImVec2& rhs); +# if IMGUI_VERSION_NUM < 18955 inline ImVec2 operator-(const ImVec2& lhs); +# endif //------------------------------------------------------------------------------ diff --git a/imgui_extra_math.inl b/imgui_extra_math.inl index 51fb5951..8b1b0714 100644 --- a/imgui_extra_math.inl +++ b/imgui_extra_math.inl @@ -34,10 +34,12 @@ inline ImVec2 operator*(const float lhs, const ImVec2& rhs) return ImVec2(lhs * rhs.x, lhs * rhs.y); } -inline static ImVec2 operator-(const ImVec2& lhs) +# if IMGUI_VERSION_NUM < 18955 +inline ImVec2 operator-(const ImVec2& lhs) { return ImVec2(-lhs.x, -lhs.y); } +# endif //------------------------------------------------------------------------------ From be0e8128291e3e3a4c2f4d99e39085b3308acce0 Mon Sep 17 00:00:00 2001 From: thedmd Date: Thu, 31 Aug 2023 22:52:34 +0200 Subject: [PATCH 20/28] Examples: Don't use deprecated SetItemAllowOverlap (#250) --- docs/CHANGELOG.txt | 2 ++ examples/blueprints-example/blueprints-example.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index a830b152..c8bc8cf0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -14,6 +14,8 @@ v0.9.2 (WIP): CHANGE: Canvas: Don't use deprecated SetItemAllowOverlap (#250) + CHANGE: Examples: Don't use deprecated SetItemAllowOverlap (#250) + CHANGE: Editor: Define IMGUI_DEFINE_MATH_OPERATORS before (#209), thanks @ocornut CHANGE: Editor: Unary operator- for ImVec2 is defined by ImGui since r18955 (#248) diff --git a/examples/blueprints-example/blueprints-example.cpp b/examples/blueprints-example/blueprints-example.cpp index 58f5e1bf..f72f3ad1 100644 --- a/examples/blueprints-example/blueprints-example.cpp +++ b/examples/blueprints-example/blueprints-example.cpp @@ -766,6 +766,9 @@ struct Example: } bool isSelected = std::find(selectedNodes.begin(), selectedNodes.end(), node.ID) != selectedNodes.end(); +# if IMGUI_VERSION_NUM >= 18967 + ImGui::SetNextItemAllowOverlap(); +# endif if (ImGui::Selectable((node.Name + "##" + std::to_string(reinterpret_cast(node.ID.AsPointer()))).c_str(), &isSelected)) { if (io.KeyCtrl) @@ -794,7 +797,11 @@ struct Example: auto drawList = ImGui::GetWindowDrawList(); ImGui::SetCursorScreenPos(iconPanelPos); +# if IMGUI_VERSION_NUM < 18967 ImGui::SetItemAllowOverlap(); +# else + ImGui::SetNextItemAllowOverlap(); +# endif if (node.SavedState.empty()) { if (ImGui::InvisibleButton("save", ImVec2((float)saveIconWidth, (float)saveIconHeight))) @@ -814,7 +821,11 @@ struct Example: } ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x); +# if IMGUI_VERSION_NUM < 18967 ImGui::SetItemAllowOverlap(); +# else + ImGui::SetNextItemAllowOverlap(); +# endif if (!node.SavedState.empty()) { if (ImGui::InvisibleButton("restore", ImVec2((float)restoreIconWidth, (float)restoreIconHeight))) @@ -838,7 +849,9 @@ struct Example: } ImGui::SameLine(0, 0); +# if IMGUI_VERSION_NUM < 18967 ImGui::SetItemAllowOverlap(); +# endif ImGui::Dummy(ImVec2(0, (float)restoreIconHeight)); ImGui::PopID(); From 4bd301290b34ec7f6379b31bb21e8eb40f6614ca Mon Sep 17 00:00:00 2001 From: thedmd Date: Thu, 31 Aug 2023 23:16:14 +0200 Subject: [PATCH 21/28] Editor: Clean long to int implicit cast warning in crude_json --- crude_json.cpp | 4 ++-- docs/CHANGELOG.txt | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crude_json.cpp b/crude_json.cpp index a9f7c707..078427a2 100644 --- a/crude_json.cpp +++ b/crude_json.cpp @@ -1,4 +1,4 @@ -// Crude implementation of JSON value object and parser. +// Crude implementation of JSON value object and parser. // // VERSION 0.1 // @@ -561,7 +561,7 @@ struct value::parser if (end != hex.c_str() + hex.size()) return false; - c = v; + c = static_cast(v); return true; } diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c8bc8cf0..20fce55d 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -39,6 +39,8 @@ v0.9.2 (WIP): BUGFIX: Examples: Don't use empty string as identifier + BUGFIX: Editor: Clean long to int implicit cast warning in crude_json + v0.9.1 (2022-08-27): From 3fdb8e33eed80d5fc6e978794c8914acbebd145d Mon Sep 17 00:00:00 2001 From: thedmd Date: Fri, 1 Sep 2023 14:31:08 +0200 Subject: [PATCH 22/28] Canvas: Ensure canvas draw commands are separated from other ImGui draw commands (#205, #250) --- docs/CHANGELOG.txt | 2 ++ imgui_canvas.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 20fce55d..e2cae54f 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -41,6 +41,8 @@ v0.9.2 (WIP): BUGFIX: Editor: Clean long to int implicit cast warning in crude_json + BUGFIX: Canvas: Ensure canvas draw commands are separated from other ImGui draw commands (#205, #250) + v0.9.1 (2022-08-27): diff --git a/imgui_canvas.cpp b/imgui_canvas.cpp index 8d3721d2..3bd13229 100644 --- a/imgui_canvas.cpp +++ b/imgui_canvas.cpp @@ -68,6 +68,12 @@ struct VtxCurrentOffsetRef } }; +static void SentinelDrawCallback(const ImDrawList* parent_list, const ImDrawCmd* cmd) +{ + // This is a sentinel draw callback, it's only purpose is to mark draw list command. + IM_ASSERT(false && "This draw callback should never be called."); +} + } // namespace ImCanvasDetails // Returns a reference to _FringeScale extension to ImDrawList @@ -429,7 +435,7 @@ void ImGuiEx::Canvas::EnterLocalSpace() // // More investigation is needed. To get to the bottom of this. if ((!m_DrawList->CmdBuffer.empty() && m_DrawList->CmdBuffer.back().ElemCount > 0) || m_DrawList->_Splitter._Count > 1) - m_DrawList->AddDrawCmd(); + m_DrawList->AddCallback(&ImCanvasDetails::SentinelDrawCallback, nullptr); # if IMGUI_EX_CANVAS_DEFERED() m_Ranges.resize(m_Ranges.Size + 1); @@ -547,6 +553,10 @@ void ImGuiEx::Canvas::LeaveLocalSpace() } } + // Remove sentinel draw command if present + if (m_DrawListCommadBufferSize > 0 && m_DrawList->CmdBuffer.size() >= m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize - 1].UserCallback == &ImCanvasDetails::SentinelDrawCallback) + m_DrawList->CmdBuffer.erase(m_DrawList->CmdBuffer.Data + m_DrawListCommadBufferSize - 1); + auto& fringeScale = ImFringeScaleRef(m_DrawList); fringeScale = m_LastFringeScale; From df1d2afe429be56addf44d4823079808dd97a5a5 Mon Sep 17 00:00:00 2001 From: thedmd Date: Fri, 1 Sep 2023 14:45:32 +0200 Subject: [PATCH 23/28] Editor: Don't call Canvas.End() when Canvas.Begin() failed (#186) --- docs/CHANGELOG.txt | 2 ++ imgui_node_editor.cpp | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index e2cae54f..fe0a5915 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -43,6 +43,8 @@ v0.9.2 (WIP): BUGFIX: Canvas: Ensure canvas draw commands are separated from other ImGui draw commands (#205, #250) + BUGFIX: Editor: Don't call Canvas.End() when Canvas.Begin() failed (#186), thanks @pthom, @TheZoc + v0.9.1 (2022-08-27): diff --git a/imgui_node_editor.cpp b/imgui_node_editor.cpp index 0295892b..41ba6f02 100644 --- a/imgui_node_editor.cpp +++ b/imgui_node_editor.cpp @@ -1137,9 +1137,9 @@ void ed::EditorContext::Begin(const char* id, const ImVec2& size) if (!m_IsInitialized) { - // Cycle canvas so it has a change to setup its size before settings are loaded - m_Canvas.Begin(id, canvasSize); - m_Canvas.End(); + // Cycle canvas, so it has a chance to initialize its size before settings are loaded + if (m_Canvas.Begin(id, canvasSize)) + m_Canvas.End(); LoadSettings(); m_IsInitialized = true; From 79765852a1f70c07cfaf974d0d02903ad6dbaf19 Mon Sep 17 00:00:00 2001 From: thedmd Date: Fri, 1 Sep 2023 15:53:55 +0200 Subject: [PATCH 24/28] Release v0.9.2 --- docs/CHANGELOG.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index fe0a5915..745b2523 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -1,4 +1,4 @@ -v0.9.2 (WIP): +v0.9.2 (2023-09-01): NEW: Editor: Add offset of hover/select to style (thanks @MultiPain) From 4a5a6db2574b8aef2bfc304938228ea8a2ded747 Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 19 Sep 2023 08:53:46 +0200 Subject: [PATCH 25/28] Bump version to 0.9.3 --- docs/CHANGELOG.txt | 5 +++++ imgui_node_editor.h | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 745b2523..db769366 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -1,3 +1,8 @@ +v0.9.3 (WIP): + + nothing yet + + v0.9.2 (2023-09-01): NEW: Editor: Add offset of hover/select to style (thanks @MultiPain) diff --git a/imgui_node_editor.h b/imgui_node_editor.h index 48bc209d..e932744f 100644 --- a/imgui_node_editor.h +++ b/imgui_node_editor.h @@ -21,8 +21,8 @@ //------------------------------------------------------------------------------ -# define IMGUI_NODE_EDITOR_VERSION "0.9.2" -# define IMGUI_NODE_EDITOR_VERSION_NUM 000902 +# define IMGUI_NODE_EDITOR_VERSION "0.9.3" +# define IMGUI_NODE_EDITOR_VERSION_NUM 000903 //------------------------------------------------------------------------------ From 6e662a4f61f8fae439026908e5f76155d91c5dcb Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 19 Sep 2023 08:56:34 +0200 Subject: [PATCH 26/28] Canvas: Ensure SentinelDrawCallback cleanup (#255) --- docs/CHANGELOG.txt | 2 +- imgui_canvas.cpp | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index db769366..f6b5b9fa 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -1,6 +1,6 @@ v0.9.3 (WIP): - nothing yet + BUGFIX: Canvas: Ensure SentinelDrawCallback cleanup (#255) v0.9.2 (2023-09-01): diff --git a/imgui_canvas.cpp b/imgui_canvas.cpp index 3bd13229..bb4846e4 100644 --- a/imgui_canvas.cpp +++ b/imgui_canvas.cpp @@ -421,6 +421,15 @@ void ImGuiEx::Canvas::EnterLocalSpace() auto clipped_clip_rect = m_DrawList->_ClipRectStack.back(); ImGui::PopClipRect(); +# if IMGUI_EX_CANVAS_DEFERED() + m_Ranges.resize(m_Ranges.Size + 1); + m_CurrentRange = &m_Ranges.back(); + m_CurrentRange->BeginComandIndex = ImMax(m_DrawList->CmdBuffer.Size, 0); + m_CurrentRange->BeginVertexIndex = m_DrawList->_VtxCurrentIdx + ImVtxOffsetRef(m_DrawList); +# endif + m_DrawListCommadBufferSize = ImMax(m_DrawList->CmdBuffer.Size, 0); + m_DrawListStartVertexIndex = m_DrawList->_VtxCurrentIdx + ImVtxOffsetRef(m_DrawList); + // Make sure we do not share draw command with anyone. We don't want to mess // with someones clip rectangle. @@ -437,15 +446,6 @@ void ImGuiEx::Canvas::EnterLocalSpace() if ((!m_DrawList->CmdBuffer.empty() && m_DrawList->CmdBuffer.back().ElemCount > 0) || m_DrawList->_Splitter._Count > 1) m_DrawList->AddCallback(&ImCanvasDetails::SentinelDrawCallback, nullptr); -# if IMGUI_EX_CANVAS_DEFERED() - m_Ranges.resize(m_Ranges.Size + 1); - m_CurrentRange = &m_Ranges.back(); - m_CurrentRange->BeginComandIndex = ImMax(m_DrawList->CmdBuffer.Size - 1, 0); - m_CurrentRange->BeginVertexIndex = m_DrawList->_VtxCurrentIdx + ImVtxOffsetRef(m_DrawList); -# endif - m_DrawListCommadBufferSize = ImMax(m_DrawList->CmdBuffer.Size - 1, 0); - m_DrawListStartVertexIndex = m_DrawList->_VtxCurrentIdx + ImVtxOffsetRef(m_DrawList); - # if defined(IMGUI_HAS_VIEWPORT) auto window = ImGui::GetCurrentWindow(); window->Pos = ImVec2(0.0f, 0.0f); @@ -554,8 +554,13 @@ void ImGuiEx::Canvas::LeaveLocalSpace() } // Remove sentinel draw command if present - if (m_DrawListCommadBufferSize > 0 && m_DrawList->CmdBuffer.size() >= m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize - 1].UserCallback == &ImCanvasDetails::SentinelDrawCallback) - m_DrawList->CmdBuffer.erase(m_DrawList->CmdBuffer.Data + m_DrawListCommadBufferSize - 1); + if (m_DrawListCommadBufferSize > 0) + { + if (m_DrawList->CmdBuffer.size() > m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize].UserCallback == &ImCanvasDetails::SentinelDrawCallback) + m_DrawList->CmdBuffer.erase(m_DrawList->CmdBuffer.Data + m_DrawListCommadBufferSize); + else if (m_DrawList->CmdBuffer.size() >= m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize - 1].UserCallback == &ImCanvasDetails::SentinelDrawCallback) + m_DrawList->CmdBuffer.erase(m_DrawList->CmdBuffer.Data + m_DrawListCommadBufferSize - 1); + } auto& fringeScale = ImFringeScaleRef(m_DrawList); fringeScale = m_LastFringeScale; From 8afc83bb5e50ea990761f609aa37b6b2b978b9a2 Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 19 Sep 2023 08:57:14 +0200 Subject: [PATCH 27/28] Editor: Don't call Reasume/Suspend on invisible canvas (#255) --- docs/CHANGELOG.txt | 2 ++ imgui_node_editor.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index f6b5b9fa..73e7437b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -2,6 +2,8 @@ v0.9.3 (WIP): BUGFIX: Canvas: Ensure SentinelDrawCallback cleanup (#255) + BUGFIX: Editor: Don't call Reasume/Suspend on invisible canvas (#255) + v0.9.2 (2023-09-01): diff --git a/imgui_node_editor.cpp b/imgui_node_editor.cpp index 41ba6f02..335920cf 100644 --- a/imgui_node_editor.cpp +++ b/imgui_node_editor.cpp @@ -1965,7 +1965,8 @@ void ed::EditorContext::Suspend(SuspendFlags flags) IM_ASSERT(m_DrawList != nullptr && "Suspend was called outiside of Begin/End."); auto lastChannel = m_DrawList->_Splitter._Current; m_DrawList->ChannelsSetCurrent(m_ExternalChannel); - m_Canvas.Suspend(); + if (m_IsCanvasVisible) + m_Canvas.Suspend(); m_DrawList->ChannelsSetCurrent(lastChannel); if ((flags & SuspendFlags::KeepSplitter) != SuspendFlags::KeepSplitter) ImDrawList_SwapSplitter(m_DrawList, m_Splitter); @@ -1978,7 +1979,8 @@ void ed::EditorContext::Resume(SuspendFlags flags) ImDrawList_SwapSplitter(m_DrawList, m_Splitter); auto lastChannel = m_DrawList->_Splitter._Current; m_DrawList->ChannelsSetCurrent(m_ExternalChannel); - m_Canvas.Resume(); + if (m_IsCanvasVisible) + m_Canvas.Resume(); m_DrawList->ChannelsSetCurrent(lastChannel); } From af7fa51bb9d68c9b44477c341f13a7dadee3e359 Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 19 Sep 2023 09:05:19 +0200 Subject: [PATCH 28/28] Canvas: Use ImDrawCallback_ImCanvas macro as draw callback sentinel (#256) --- docs/CHANGELOG.txt | 2 ++ imgui_canvas.cpp | 17 ++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 73e7437b..109aaf96 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -1,5 +1,7 @@ v0.9.3 (WIP): + CHANGE: Canvas: Use ImDrawCallback_ImCanvas macro as draw callback sentinel (#256), thanks @nspitko + BUGFIX: Canvas: Ensure SentinelDrawCallback cleanup (#255) BUGFIX: Editor: Don't call Reasume/Suspend on invisible canvas (#255) diff --git a/imgui_canvas.cpp b/imgui_canvas.cpp index bb4846e4..85a1e701 100644 --- a/imgui_canvas.cpp +++ b/imgui_canvas.cpp @@ -27,6 +27,11 @@ static constexpr bool value = (sizeof(yes_type) == sizeof(test(0))); \ } +// Special sentinel value. This needs to be unique, so allow it to be overridden in the user's ImGui config +# ifndef ImDrawCallback_ImCanvas +# define ImDrawCallback_ImCanvas (ImDrawCallback)(-2) +# endif + namespace ImCanvasDetails { DECLARE_HAS_MEMBER(HasFringeScale, _FringeScale); @@ -68,12 +73,6 @@ struct VtxCurrentOffsetRef } }; -static void SentinelDrawCallback(const ImDrawList* parent_list, const ImDrawCmd* cmd) -{ - // This is a sentinel draw callback, it's only purpose is to mark draw list command. - IM_ASSERT(false && "This draw callback should never be called."); -} - } // namespace ImCanvasDetails // Returns a reference to _FringeScale extension to ImDrawList @@ -444,7 +443,7 @@ void ImGuiEx::Canvas::EnterLocalSpace() // // More investigation is needed. To get to the bottom of this. if ((!m_DrawList->CmdBuffer.empty() && m_DrawList->CmdBuffer.back().ElemCount > 0) || m_DrawList->_Splitter._Count > 1) - m_DrawList->AddCallback(&ImCanvasDetails::SentinelDrawCallback, nullptr); + m_DrawList->AddCallback(ImDrawCallback_ImCanvas, nullptr); # if defined(IMGUI_HAS_VIEWPORT) auto window = ImGui::GetCurrentWindow(); @@ -556,9 +555,9 @@ void ImGuiEx::Canvas::LeaveLocalSpace() // Remove sentinel draw command if present if (m_DrawListCommadBufferSize > 0) { - if (m_DrawList->CmdBuffer.size() > m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize].UserCallback == &ImCanvasDetails::SentinelDrawCallback) + if (m_DrawList->CmdBuffer.size() > m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize].UserCallback == ImDrawCallback_ImCanvas) m_DrawList->CmdBuffer.erase(m_DrawList->CmdBuffer.Data + m_DrawListCommadBufferSize); - else if (m_DrawList->CmdBuffer.size() >= m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize - 1].UserCallback == &ImCanvasDetails::SentinelDrawCallback) + else if (m_DrawList->CmdBuffer.size() >= m_DrawListCommadBufferSize && m_DrawList->CmdBuffer[m_DrawListCommadBufferSize - 1].UserCallback == ImDrawCallback_ImCanvas) m_DrawList->CmdBuffer.erase(m_DrawList->CmdBuffer.Data + m_DrawListCommadBufferSize - 1); }