From 7dc74b2920ab2fae079111aad4fc149f6170fedd Mon Sep 17 00:00:00 2001 From: thedmd Date: Thu, 25 Aug 2022 20:20:07 +0200 Subject: [PATCH] Editor: Cycle canvas to correctly restore view on first frame (#159) --- docs/CHANGELOG.txt | 4 +++- imgui_node_editor.cpp | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 98f8b73c..8ab6975b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -214,4 +214,6 @@ v0.9.1 (WIP): BUGFIX: Editor: Don't steal input from active user widget (#172) - BUGFIX: Editor: Delete item from internal list only when action accepts (#178) \ No newline at end of file + BUGFIX: Editor: Delete item from internal list only when action accepts (#178) + + BUGFIX: Editor: Cycle canvas to correctly restore view on first frame (#159) \ No newline at end of file diff --git a/imgui_node_editor.cpp b/imgui_node_editor.cpp index d5bda283..37f43964 100644 --- a/imgui_node_editor.cpp +++ b/imgui_node_editor.cpp @@ -1111,8 +1111,22 @@ ed::EditorContext::~EditorContext() void ed::EditorContext::Begin(const char* id, const ImVec2& size) { + m_EditorActiveId = ImGui::GetID(id); + ImGui::PushID(id); + + auto availableContentSize = ImGui::GetContentRegionAvail(); + ImVec2 canvasSize = ImFloor(size); + if (canvasSize.x <= 0.0f) + canvasSize.x = ImMax(4.0f, availableContentSize.x); + if (canvasSize.y <= 0.0f) + canvasSize.y = ImMax(4.0f, availableContentSize.y); + 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(); + LoadSettings(); m_IsInitialized = true; } @@ -1146,16 +1160,6 @@ void ed::EditorContext::Begin(const char* id, const ImVec2& size) ImDrawList_SwapSplitter(m_DrawList, m_Splitter); m_ExternalChannel = m_DrawList->_Splitter._Current; - m_EditorActiveId = ImGui::GetID(id); - ImGui::PushID(id); - - auto availableContentSize = ImGui::GetContentRegionAvail(); - ImVec2 canvasSize = ImFloor(size); - if (canvasSize.x <= 0.0f) - canvasSize.x = ImMax(4.0f, availableContentSize.x); - if (canvasSize.y <= 0.0f) - canvasSize.y = ImMax(4.0f, availableContentSize.y); - if (m_CurrentAction && m_CurrentAction->IsDragging() && m_NavigateAction.MoveOverEdge(canvasSize)) { auto& io = ImGui::GetIO();