From 43a800a83857709b0adca35f2f3a228680431ed0 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Thu, 2 Sep 2021 22:33:34 +0200 Subject: [PATCH] LibGUI: Set correct value on click with set jump_to_cursor() in Slider Prior this change, clicking on a slider with set jump_to_cursor() flag didn't exactly match the knob to the mouse position, and therefore the slider values were a bit off in the corners. The calculation used the whole widget size to set new values, which isn't correct as the track slider has margins on both ends. I noticed this while seeking in the Sound Player. --- Userland/Libraries/LibGUI/Slider.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGUI/Slider.cpp b/Userland/Libraries/LibGUI/Slider.cpp index 02665a02e9..5c07c19d36 100644 --- a/Userland/Libraries/LibGUI/Slider.cpp +++ b/Userland/Libraries/LibGUI/Slider.cpp @@ -93,9 +93,9 @@ void Slider::mousedown_event(MouseEvent& event) if (jump_to_cursor()) { float normalized_mouse_offset = 0.0f; if (orientation() == Orientation::Vertical) { - normalized_mouse_offset = static_cast(mouse_offset) / static_cast(height()); + normalized_mouse_offset = static_cast(mouse_offset - track_margin()) / static_cast(inner_rect().height()); } else { - normalized_mouse_offset = static_cast(mouse_offset) / static_cast(width()); + normalized_mouse_offset = static_cast(mouse_offset - track_margin()) / static_cast(inner_rect().width()); } int new_value = static_cast(min() + ((max() - min()) * normalized_mouse_offset));