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.
This commit is contained in:
thankyouverycool 2021-03-07 14:51:14 -05:00 committed by Andreas Kling
parent f318ab6bed
commit bd34cdbbb3
Notes: sideshowbarker 2024-07-18 21:30:10 +09:00
2 changed files with 10 additions and 4 deletions

View file

@ -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);
}

View file

@ -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)