From 9d89b3e98c91ba2b414c9ad1cdf7e9c48510c6f0 Mon Sep 17 00:00:00 2001 From: Auburn Date: Sun, 4 Feb 2024 16:28:28 +0000 Subject: [PATCH] Copy all of the ImGui IO config section into zoom context Fixes difference between contexts due to missing config --- imnodes.cpp | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/imnodes.cpp b/imnodes.cpp index 55710a5..a56a729 100644 --- a/imnodes.cpp +++ b/imnodes.cpp @@ -2279,16 +2279,29 @@ 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; @@ -2296,16 +2309,9 @@ void BeginNodeEditor() 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) @@ -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)); @@ -2352,6 +2356,7 @@ void BeginNodeEditor() } } + // Cache inputs GImNodes->MousePos = ImGui::GetIO().MousePos; GImNodes->LeftMouseClicked = ImGui::IsMouseClicked(0); GImNodes->LeftMouseReleased = ImGui::IsMouseReleased(0);