mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
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.
This commit is contained in:
parent
c8547124e2
commit
a30b341a2c
1 changed files with 1 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue