summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2021-03-07 14:51:14 -0500
committerAndreas Kling <kling@serenityos.org>2021-03-12 09:59:03 +0100
commitbd34cdbbb39fd63e4048c6d2c9d64a1f4f846a34 (patch)
tree7ac2fc5cb7197ba30dc3c75382730e298ec3ba41
parentf318ab6bed4603a18198b36da682b6fd36a68f91 (diff)
downloadserenity-bd34cdbbb39fd63e4048c6d2c9d64a1f4f846a34.zip
LibGUI: Ignore scroll length multiplier in SpinBoxes & Sliders
Prevents discrete values from being skipped when using the mouse wheel on SpinBoxes and proportional Sliders. Wheel delta can be accelerated by holding Ctrl.
-rw-r--r--Userland/Libraries/LibGUI/Slider.cpp9
-rw-r--r--Userland/Libraries/LibGUI/SpinBox.cpp5
2 files changed, 10 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGUI/Slider.cpp b/Userland/Libraries/LibGUI/Slider.cpp
index 9aac47ee11..5689a36868 100644
--- a/Userland/Libraries/LibGUI/Slider.cpp
+++ b/Userland/Libraries/LibGUI/Slider.cpp
@@ -144,14 +144,17 @@ void Slider::mouseup_event(MouseEvent& event)
void Slider::mousewheel_event(MouseEvent& event)
{
auto acceleration_modifier = step();
+ auto wheel_delta = event.wheel_delta();
- if (event.modifiers() == KeyModifier::Mod_Ctrl && knob_size_mode() == KnobSizeMode::Fixed)
+ if (event.modifiers() == KeyModifier::Mod_Ctrl)
acceleration_modifier *= 6;
+ if (knob_size_mode() == KnobSizeMode::Proportional)
+ wheel_delta /= abs(wheel_delta);
if (orientation() == Orientation::Horizontal)
- set_value(value() - event.wheel_delta() * acceleration_modifier);
+ set_value(value() - wheel_delta * acceleration_modifier);
else
- set_value(value() + event.wheel_delta() * acceleration_modifier);
+ set_value(value() + wheel_delta * acceleration_modifier);
Widget::mousewheel_event(event);
}
diff --git a/Userland/Libraries/LibGUI/SpinBox.cpp b/Userland/Libraries/LibGUI/SpinBox.cpp
index 35967afab5..f0c82b935e 100644
--- a/Userland/Libraries/LibGUI/SpinBox.cpp
+++ b/Userland/Libraries/LibGUI/SpinBox.cpp
@@ -105,7 +105,10 @@ void SpinBox::set_range(int min, int max)
void SpinBox::mousewheel_event(MouseEvent& event)
{
- set_value(m_value - event.wheel_delta());
+ auto wheel_delta = event.wheel_delta() / abs(event.wheel_delta());
+ if (event.modifiers() == KeyModifier::Mod_Ctrl)
+ wheel_delta *= 6;
+ set_value(m_value - wheel_delta);
}
void SpinBox::resize_event(ResizeEvent& event)