From f37314b21c285d7cb0e12f3db83a60c41c3b1771 Mon Sep 17 00:00:00 2001 From: Jacopin Eliott Date: Tue, 2 May 2023 18:41:32 +0900 Subject: [PATCH] [Add] Suspend/Resume Canvas Zoom by desactivating Navigation ## Major: - Original NavigateAction (m_NavigateAction of the EditorContext) already has a m_IsActive boolean - Added methods To gloabal API to directly set it to true (ResumeNavigation) or false (SuspendNavigation). - As a result, we can call the couple Suspend/Resume to momentarily deactivate the canvas zoom. --- imgui_node_editor.h | 3 +++ imgui_node_editor_api.cpp | 10 ++++++++++ imgui_node_editor_internal.h | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/imgui_node_editor.h b/imgui_node_editor.h index a173cde3..a1640b0d 100644 --- a/imgui_node_editor.h +++ b/imgui_node_editor.h @@ -368,6 +368,9 @@ int BreakLinks(PinId pinId); // Break all links connected to this pin void NavigateToContent(float duration = -1); void NavigateToSelection(bool zoomIn = false, float duration = -1); +void SuspendNavigation(); +void ResumeNavigation(); + bool ShowNodeContextMenu(NodeId* nodeId); bool ShowPinContextMenu(PinId* pinId); bool ShowLinkContextMenu(LinkId* linkId); diff --git a/imgui_node_editor_api.cpp b/imgui_node_editor_api.cpp index c8c7c3ff..4adf15ff 100644 --- a/imgui_node_editor_api.cpp +++ b/imgui_node_editor_api.cpp @@ -576,6 +576,16 @@ void ax::NodeEditor::NavigateToSelection(bool zoomIn, float duration) s_Editor->NavigateTo(s_Editor->GetSelectionBounds(), zoomIn, duration); } +void ax::NodeEditor::SuspendNavigation() +{ + s_Editor->SuspendNavigation(); +} + +void ax::NodeEditor::ResumeNavigation() +{ + s_Editor->ResumeNavigation(); +} + bool ax::NodeEditor::ShowNodeContextMenu(NodeId* nodeId) { return s_Editor->GetContextMenu().ShowNodeContextMenu(nodeId); diff --git a/imgui_node_editor_internal.h b/imgui_node_editor_internal.h index 4c57725f..fba41970 100644 --- a/imgui_node_editor_internal.h +++ b/imgui_node_editor_internal.h @@ -1433,6 +1433,16 @@ struct EditorContext m_NavigateAction.NavigateTo(bounds, zoomMode, duration); } + inline void SuspendNavigation() + { + m_NavigateAction.m_IsActive = false; + } + + inline void ResumeNavigation() + { + m_NavigateAction.m_IsActive = true; + } + void RegisterAnimation(Animation* animation); void UnregisterAnimation(Animation* animation);