Skip to content

Commit

Permalink
Copy all of the ImGui IO config section into zoom context
Browse files Browse the repository at this point in the history
Fixes difference between contexts due to missing config
  • Loading branch information
Auburn committed Feb 4, 2024
1 parent 0cda3b8 commit 9d89b3e
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions imnodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2279,33 +2279,39 @@ void BeginNodeEditor()
// Setup zoom context
ImVec2 canvas_size = ImGui::GetContentRegionAvail();
GImNodes->CanvasOriginalOrigin = ImGui::GetCursorScreenPos();
GImNodes->OriginalImgCtx = ImGui::GetCurrentContext();

// Button to capture mouse events and hover test
ImGui::InvisibleButton("canvas_no_drag", canvas_size);

ImGuiConfigFlags configFlags = ImGui::GetIO().ConfigFlags;
GImNodes->OriginalImgCtx = ImGui::GetCurrentContext();

// Copy config settings in IO from main context, avoiding input fields
memcpy(
&GImNodes->ZoomImgCtx->IO,
&GImNodes->OriginalImgCtx->IO,
offsetof(ImGuiIO, SetPlatformImeDataFn) +
sizeof(GImNodes->OriginalImgCtx->IO.SetPlatformImeDataFn));

GImNodes->ZoomImgCtx->IO.IniFilename = nullptr;
GImNodes->ZoomImgCtx->IO.ConfigInputTrickleEventQueue = false;
GImNodes->ZoomImgCtx->IO.DisplaySize = canvas_size / editor.ZoomScale;
GImNodes->ZoomImgCtx->Style = GImNodes->OriginalImgCtx->Style;

// Nav (tabbing) needs to be disabled otherwise it doubles up with the main context
// not sure how to get this working correctly
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoScrollWithMouse |
ImGuiWindowFlags_NoNavInputs;

// Button to capture mouse events and hover test
ImGui::InvisibleButton("canvas_no_drag", canvas_size);

if (ImGui::IsItemHovered())
{
GImNodes->IsHovered = true;
}
else
{
windowFlags |= ImGuiWindowFlags_NoInputs;
configFlags &= ImGuiConfigFlags_NoMouse;
GImNodes->ZoomImgCtx->IO.ConfigFlags &= ImGuiConfigFlags_NoMouse;
}

const ImGuiStyle& orig_style = ImGui::GetStyle();
const float delta_time = ImGui::GetIO().DeltaTime;
ImGui::SetCurrentContext(GImNodes->ZoomImgCtx);
ImGuiStyle& new_style = ImGui::GetStyle();
new_style = orig_style;
ImGui::GetIO().DeltaTime = delta_time;

// Copy IO events
GImNodes->ZoomImgCtx->InputEventsQueue = GImNodes->OriginalImgCtx->InputEventsTrail;
for (ImGuiInputEvent& e : GImNodes->ZoomImgCtx->InputEventsQueue)
Expand All @@ -2319,9 +2325,7 @@ void BeginNodeEditor()
}
}

ImGui::GetIO().DisplaySize = canvas_size / editor.ZoomScale;
ImGui::GetIO().ConfigInputTrickleEventQueue = false;
ImGui::GetIO().ConfigFlags = configFlags;
ImGui::SetCurrentContext(GImNodes->ZoomImgCtx);
ImGui::NewFrame();

ImGui::SetNextWindowPos(ImVec2(0, 0));
Expand Down Expand Up @@ -2352,6 +2356,7 @@ void BeginNodeEditor()
}
}

// Cache inputs
GImNodes->MousePos = ImGui::GetIO().MousePos;
GImNodes->LeftMouseClicked = ImGui::IsMouseClicked(0);
GImNodes->LeftMouseReleased = ImGui::IsMouseReleased(0);
Expand Down

0 comments on commit 9d89b3e

Please sign in to comment.