From eb789c02882adda08268ab4f37b799502c67e1c2 Mon Sep 17 00:00:00 2001 From: Mikko Mononen Date: Sun, 30 Nov 2014 12:20:25 +0200 Subject: [PATCH] Smoother scrolling - changed IO.MouseWheel to float, allows smoother scrolling --- imgui.cpp | 9 ++++----- imgui.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b6871778a..994e0324e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1431,16 +1431,15 @@ void ImGui::NewFrame() g.IO.WantCaptureKeyboard = (g.ActiveId != 0); // Scale & Scrolling - if (g.HoveredWindow && g.IO.MouseWheel != 0) + if (g.HoveredWindow && g.IO.MouseWheel != 0.0f) { ImGuiWindow* window = g.HoveredWindow; - const int mouse_wheel_dir = g.IO.MouseWheel > 0 ? +1 : -1; if (g.IO.KeyCtrl) { if (g.IO.FontAllowUserScaling) { // Zoom / Scale window - float new_font_scale = ImClamp(window->FontWindowScale + mouse_wheel_dir * 0.10f, 0.50f, 2.50f); + float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); float scale = new_font_scale / window->FontWindowScale; window->FontWindowScale = new_font_scale; @@ -1455,7 +1454,7 @@ void ImGui::NewFrame() { // Scroll const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5; - window->NextScrollY -= mouse_wheel_dir * window->FontSize() * scroll_lines; + window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines; } } @@ -1605,7 +1604,7 @@ void ImGui::Render() g.Windows.swap(sorted_windows); // Clear data for next frame - g.IO.MouseWheel = 0; + g.IO.MouseWheel = 0.0f; memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); } diff --git a/imgui.h b/imgui.h index 419631d8e..1e013e2ec 100644 --- a/imgui.h +++ b/imgui.h @@ -488,7 +488,7 @@ struct ImGuiIO ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience. - int MouseWheel; // Mouse wheel: -1,0,+1 + float MouseWheel; // Mouse wheel: 1 unit scrolls about 3 lines text. bool KeyCtrl; // Keyboard modifier pressed: Control bool KeyShift; // Keyboard modifier pressed: Shift bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)