Skip to content

Commit

Permalink
fix: Make all content scaling changes happen at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jul 17, 2024
1 parent 6c46e1d commit 0da0d83
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions lib/third_party/imgui/custom/source/imgui_impl_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,15 @@ struct ImGui_ImplGlfw_Data
#endif

// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
GLFWwindowfocusfun PrevUserCallbackWindowFocus;
GLFWcursorposfun PrevUserCallbackCursorPos;
GLFWcursorenterfun PrevUserCallbackCursorEnter;
GLFWmousebuttonfun PrevUserCallbackMousebutton;
GLFWscrollfun PrevUserCallbackScroll;
GLFWkeyfun PrevUserCallbackKey;
GLFWcharfun PrevUserCallbackChar;
GLFWmonitorfun PrevUserCallbackMonitor;
GLFWwindowfocusfun PrevUserCallbackWindowFocus;
GLFWcursorposfun PrevUserCallbackCursorPos;
GLFWcursorenterfun PrevUserCallbackCursorEnter;
GLFWmousebuttonfun PrevUserCallbackMousebutton;
GLFWscrollfun PrevUserCallbackScroll;
GLFWkeyfun PrevUserCallbackKey;
GLFWcharfun PrevUserCallbackChar;
GLFWmonitorfun PrevUserCallbackMonitor;
GLFWwindowcontentscalefun PrevUserCallbackContentScale;
#ifdef _WIN32
WNDPROC PrevWndProc;
#endif
Expand Down Expand Up @@ -519,6 +520,15 @@ void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor*, int)
bd->WantUpdateMonitors = true;
}

void ImGui_ImplGlfw_ContentScale(GLFWwindow *window, float scaleX, float scaleY)
{
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
bd->ScaleCoordinates = ImVec2(scaleX, scaleY);

if (bd->PrevUserCallbackContentScale != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
bd->PrevUserCallbackContentScale(window, scaleX, scaleY);
}

#ifdef __EMSCRIPTEN__
static EM_BOOL ImGui_ImplEmscripten_WheelCallback(int, const EmscriptenWheelEvent* ev, void*)
{
Expand Down Expand Up @@ -555,6 +565,7 @@ void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
bd->PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
bd->PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
bd->PrevUserCallbackMonitor = glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback);
bd->PrevUserCallbackContentScale = glfwSetWindowContentScaleCallback(window, ImGui_ImplGlfw_ContentScale);
bd->InstalledCallbacks = true;
}

Expand Down Expand Up @@ -957,15 +968,12 @@ void ImGui_ImplGlfw_NewFrame()
// Setup display size (every frame to accommodate for window resizing)
int w, h;
int display_w, display_h;
float scale_w, scale_h;
glfwGetWindowSize(bd->Window, &w, &h);
glfwGetFramebufferSize(bd->Window, &display_w, &display_h);
glfwGetWindowContentScale(bd->Window, &scale_w, &scale_h);
io.DisplaySize = ImVec2((float)w, (float)h);
if (w > 0 && h > 0)
io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);

bd->ScaleCoordinates = ImVec2(scale_w / io.DisplayFramebufferScale.x, scale_h / io.DisplayFramebufferScale.y);
if (std::abs(bd->ScaleCoordinates.x - 1.0F) < .001F && std::abs(bd->ScaleCoordinates.y - 1.0F) < .001F) {
bd->ScaleCoordinates = ImVec2(1.0F, 1.0F);
} else {
Expand Down

0 comments on commit 0da0d83

Please sign in to comment.