mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 01:37:39 +03:00
LibGUI: Fix slightly wrong value slider knob position
When clicking the value slider bar, the knob was not positioned as close to the mouse as expected. When moving the mouse right, the knob would lag a bit behind, and the cursor would eventually be outside the knob. The bug was due to knob_rect() taking knob_thickness into account to prevent the knob from protruding outside the bar. The value_at(pos) calculated the relative position based on the entire width of the bar. This discrepancy is fixed by taking knob_thickness into account in value_at(position).
This commit is contained in:
parent
a30b341a2c
commit
0e4586dd3e
Notes:
sideshowbarker
2024-07-17 01:46:43 +09:00
Author: https://github.com/andreao Commit: https://github.com/SerenityOS/serenity/commit/0e4586dd3e Pull-request: https://github.com/SerenityOS/serenity/pull/17689 Reviewed-by: https://github.com/awesomekling
@ -139,11 +139,14 @@ Gfx::IntRect ValueSlider::knob_rect() const
|
||||
|
||||
int ValueSlider::value_at(Gfx::IntPoint position) const
|
||||
{
|
||||
if (position.x() < bar_rect().left())
|
||||
int knob_thickness = knob_length();
|
||||
float leftmost_knob_center = (float)bar_rect().left() + (float)knob_thickness / 2;
|
||||
if (position.x() < leftmost_knob_center)
|
||||
return min();
|
||||
if (position.x() > bar_rect().right())
|
||||
float rightmost_knob_center = (float)bar_rect().right() - (float)knob_thickness / 2;
|
||||
if (position.x() > rightmost_knob_center)
|
||||
return max();
|
||||
float relative_offset = (float)(position.x() - bar_rect().left()) / (float)bar_rect().width();
|
||||
float relative_offset = (float)(position.x() - leftmost_knob_center) / (rightmost_knob_center - leftmost_knob_center);
|
||||
|
||||
int range = max() - min();
|
||||
return min() + (int)roundf(relative_offset * (float)range);
|
||||
|
Loading…
Reference in New Issue
Block a user