mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
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:
parent
f318ab6bed
commit
bd34cdbbb3
Notes:
sideshowbarker
2024-07-18 21:30:10 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/bd34cdbbb39 Pull-request: https://github.com/SerenityOS/serenity/pull/5741 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/emanuele6
2 changed files with 10 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue