瀏覽代碼

LibGUI: Fix slider so dragging handle left and right feels similar

When dragging the slider handle left/down, the handle would
snap to lower value with the slightest move of the mouse. When dragging
to the right/up however, it would take a lot more movement to cause
a change in value. This asymmetry made it feel really awkward to drag
the slider. It was caused by always rounding down using a cast to int.
By rounding to the nearest integer first, we ensure symmetric behavior.
Andreas Oppebøen 2 年之前
父節點
當前提交
c8547124e2
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1 1
      Userland/Libraries/LibGUI/Slider.cpp

+ 1 - 1
Userland/Libraries/LibGUI/Slider.cpp

@@ -133,7 +133,7 @@ void Slider::mousemove_event(MouseEvent& event)
         float scrubbable_range = inner_rect().primary_size_for_orientation(orientation());
         float scrubbable_range = inner_rect().primary_size_for_orientation(orientation());
         float value_steps_per_scrubbed_pixel = (max() - min()) / scrubbable_range;
         float value_steps_per_scrubbed_pixel = (max() - min()) / scrubbable_range;
         float new_value = m_drag_origin_value + (value_steps_per_scrubbed_pixel * delta);
         float new_value = m_drag_origin_value + (value_steps_per_scrubbed_pixel * delta);
-        set_value((int)new_value);
+        set_value((int)roundf(new_value));
         return;
         return;
     }
     }
     return Widget::mousemove_event(event);
     return Widget::mousemove_event(event);