Skip to content

Commit

Permalink
LibGUI: Fix {Value,Opacity}Slider value changes for values less than 0
Browse files Browse the repository at this point in the history
This patch fixes a value glitch when changing the slider value via
dragging the knob with the mouse and having a min value smaller than 0.
Before this patch it was not possible to drag the value below 0 and it
just snapped to the configured min value if the mouse was at the most
left position. Now the value is calculated from the value range and
mouse position within the widget.
  • Loading branch information
Torstennator authored and linusg committed May 8, 2022
1 parent ee6fb51 commit f9ec3b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Userland/Libraries/LibGUI/OpacitySlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ int OpacitySlider::value_at(Gfx::IntPoint const& position) const
if (position.x() > inner_rect.right())
return max();
float relative_offset = (float)(position.x() - inner_rect.x()) / (float)inner_rect.width();
return relative_offset * (float)max();

int range = max() - min();
return min() + (int)(relative_offset * (float)range);
}

void OpacitySlider::mousedown_event(MouseEvent& event)
Expand Down
4 changes: 3 additions & 1 deletion Userland/Libraries/LibGUI/ValueSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ int ValueSlider::value_at(Gfx::IntPoint const& position) const
if (position.x() > bar_rect().right())
return max();
float relative_offset = (float)(position.x() - bar_rect().left()) / (float)bar_rect().width();
return (int)(relative_offset * (float)max());

int range = max() - min();
return min() + (int)(relative_offset * (float)range);
}

void ValueSlider::set_value(int value, AllowCallback allow_callback, DoClamp do_clamp)
Expand Down

0 comments on commit f9ec3b9

Please sign in to comment.