Skip to content

Commit

Permalink
Editor: Cycle canvas to correctly restore view on first frame (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
thedmd committed Aug 25, 2022
1 parent ab9236d commit 7dc74b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
4 changes: 3 additions & 1 deletion docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
BUGFIX: Editor: Delete item from internal list only when action accepts (#178)

BUGFIX: Editor: Cycle canvas to correctly restore view on first frame (#159)
24 changes: 14 additions & 10 deletions imgui_node_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 7dc74b2

Please sign in to comment.