diff options
author | Andreas Oppebøen <andreas.oppeboen@gmail.com> | 2023-03-01 21:19:45 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-24 10:33:22 +0100 |
commit | a30b341a2ca6cb13d88886dfe7c19a7fabd598b8 (patch) | |
tree | 2f8cdf54fd2cbf66da575b9c8da64d2771a2871f | |
parent | c8547124e2ee4c2efb7421675ff38e209630044e (diff) | |
download | serenity-a30b341a2ca6cb13d88886dfe7c19a7fabd598b8.zip |
LibGUI: Fix value slider so dragging left and right feels similar
When dragging value slider left, the handle would snap to lower value
with the slightest move of the mouse. When dragging to the right
however, it would take a lot more movement to cause a change in value.
This asymmetry made it feel awkward to drag the mouse around. It was
caused by always rounding down using a cast to int. By rounding to the
nearest integer first, we ensure symmetric behavior.
-rw-r--r-- | Userland/Libraries/LibGUI/ValueSlider.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/ValueSlider.cpp b/Userland/Libraries/LibGUI/ValueSlider.cpp index e7e7de95e2..3d868913dd 100644 --- a/Userland/Libraries/LibGUI/ValueSlider.cpp +++ b/Userland/Libraries/LibGUI/ValueSlider.cpp @@ -146,7 +146,7 @@ int ValueSlider::value_at(Gfx::IntPoint position) const float relative_offset = (float)(position.x() - bar_rect().left()) / (float)bar_rect().width(); int range = max() - min(); - return min() + (int)(relative_offset * (float)range); + return min() + (int)roundf(relative_offset * (float)range); } void ValueSlider::set_value(int value, AllowCallback allow_callback, DoClamp do_clamp) |