From c71a43c9c947615162f24ee3dbd7c09292d0cba7 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Wed, 18 Jan 2023 11:26:48 -0700 Subject: [PATCH] emscripten: Scale horizontal scroll events to be reasonable In my browser, I noticed that zooming seemed jumpy and unreliable. Turns out that my fingers were moving horizontally on my trackpad, and the x-scroll was causing the unexpected behavior. --- profiler/src/imgui/imgui_impl_glfw.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/profiler/src/imgui/imgui_impl_glfw.cpp b/profiler/src/imgui/imgui_impl_glfw.cpp index a724b5b5..568a0c7f 100644 --- a/profiler/src/imgui/imgui_impl_glfw.cpp +++ b/profiler/src/imgui/imgui_impl_glfw.cpp @@ -313,6 +313,11 @@ void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int acti void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset) { +#if defined(__EMSCRIPTEN__) + // Running under Emscripten, GLFW reports grossly mis-scaled scroll events and even flips the X axis. + xoffset /= -20.0f; +#endif + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); if (bd->PrevUserCallbackScroll != nullptr && window == bd->Window) bd->PrevUserCallbackScroll(window, xoffset, yoffset);