Skip to content

Commit

Permalink
LibGUI: offset value by minimum to ensure proper rendering of sliders
Browse files Browse the repository at this point in the history
This subtracts the minimum from the value when rendering so that the
knob doesnt go off screen for a non-zero minimum.
  • Loading branch information
IdanHo authored and awesomekling committed Dec 29, 2020
1 parent 356f11b commit b05f048
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Libraries/LibGUI/Slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ Gfx::IntRect Slider::knob_rect() const
if (knob_size_mode() == KnobSizeMode::Fixed) {
if (m_max - m_min) {
float scale = (float)inner_rect.primary_size_for_orientation(orientation()) / (float)(m_max - m_min);
rect.set_primary_offset_for_orientation(orientation(), inner_rect.primary_offset_for_orientation(orientation()) + ((int)(m_value * scale)) - (knob_fixed_primary_size() / 2));
rect.set_primary_offset_for_orientation(orientation(), inner_rect.primary_offset_for_orientation(orientation()) + ((int)((m_value - m_min) * scale)) - (knob_fixed_primary_size() / 2));
} else
rect.set_primary_size_for_orientation(orientation(), 0);
rect.set_primary_size_for_orientation(orientation(), knob_fixed_primary_size());
} else {
float scale = (float)inner_rect.primary_size_for_orientation(orientation()) / (float)(m_max - m_min + 1);
rect.set_primary_offset_for_orientation(orientation(), inner_rect.primary_offset_for_orientation(orientation()) + ((int)(m_value * scale)));
rect.set_primary_offset_for_orientation(orientation(), inner_rect.primary_offset_for_orientation(orientation()) + ((int)((m_value - m_min) * scale)));
if (m_max - m_min)
rect.set_primary_size_for_orientation(orientation(), ::max((int)(scale), knob_fixed_primary_size()));
else
Expand Down

0 comments on commit b05f048

Please sign in to comment.