Skip to content

Commit 7dc74b2

Browse files
committed
Editor: Cycle canvas to correctly restore view on first frame (#159)
1 parent ab9236d commit 7dc74b2

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

Diff for: docs/CHANGELOG.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,6 @@ v0.9.1 (WIP):
214214

215215
BUGFIX: Editor: Don't steal input from active user widget (#172)
216216

217-
BUGFIX: Editor: Delete item from internal list only when action accepts (#178)
217+
BUGFIX: Editor: Delete item from internal list only when action accepts (#178)
218+
219+
BUGFIX: Editor: Cycle canvas to correctly restore view on first frame (#159)

Diff for: imgui_node_editor.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,22 @@ ed::EditorContext::~EditorContext()
11111111

11121112
void ed::EditorContext::Begin(const char* id, const ImVec2& size)
11131113
{
1114+
m_EditorActiveId = ImGui::GetID(id);
1115+
ImGui::PushID(id);
1116+
1117+
auto availableContentSize = ImGui::GetContentRegionAvail();
1118+
ImVec2 canvasSize = ImFloor(size);
1119+
if (canvasSize.x <= 0.0f)
1120+
canvasSize.x = ImMax(4.0f, availableContentSize.x);
1121+
if (canvasSize.y <= 0.0f)
1122+
canvasSize.y = ImMax(4.0f, availableContentSize.y);
1123+
11141124
if (!m_IsInitialized)
11151125
{
1126+
// Cycle canvas so it has a change to setup its size before settings are loaded
1127+
m_Canvas.Begin(id, canvasSize);
1128+
m_Canvas.End();
1129+
11161130
LoadSettings();
11171131
m_IsInitialized = true;
11181132
}
@@ -1146,16 +1160,6 @@ void ed::EditorContext::Begin(const char* id, const ImVec2& size)
11461160
ImDrawList_SwapSplitter(m_DrawList, m_Splitter);
11471161
m_ExternalChannel = m_DrawList->_Splitter._Current;
11481162

1149-
m_EditorActiveId = ImGui::GetID(id);
1150-
ImGui::PushID(id);
1151-
1152-
auto availableContentSize = ImGui::GetContentRegionAvail();
1153-
ImVec2 canvasSize = ImFloor(size);
1154-
if (canvasSize.x <= 0.0f)
1155-
canvasSize.x = ImMax(4.0f, availableContentSize.x);
1156-
if (canvasSize.y <= 0.0f)
1157-
canvasSize.y = ImMax(4.0f, availableContentSize.y);
1158-
11591163
if (m_CurrentAction && m_CurrentAction->IsDragging() && m_NavigateAction.MoveOverEdge(canvasSize))
11601164
{
11611165
auto& io = ImGui::GetIO();

0 commit comments

Comments
 (0)