Fix Logarithmic Model Dragging Behavior #7647
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Problem
Currently, logarithmic knobs and sliders act very weirdly when dragging them. Instead of visually moving at the same rate as the mouse while internally moving logarithmically, the internal value changes linearly with the mouse movement, while only the visual was displayed logarithmically.
This makes log knobs *literally* pointless, as they don't change the sensitivity for values of different magnitudes. They just display their current value logarithmically. In addition, this also causes the knobs to jump at the start and become sluggish relative to the mouse movement, which feels weird.
Might fix #3871
The Solution
This PR addresses this issue by correctly scaling the mouse movement for all knobs.
Changes
model()->scaledValue(model()->inverseScaledValue(m_lastModelValue) - valueOffset)
And adding that on to the current model value, we get
m_lastModelValue - model()->scaledValue(model()->inverseScaledValue(m_lastModelValue) - valueOffset);
Also, these changes make the knobs more generalizable, since it does not depend on how the knob scaling is implemented, and it does not require any derivatives. If we wanted to add more interesting knob scalings in the future, this would make it easier.