summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2020-12-29 18:09:58 +0200
committerAndreas Kling <kling@serenityos.org>2020-12-29 23:37:38 +0100
commitb05f048c05dfe55421abd9fb465d0b94209b230a (patch)
tree2f81ffadd54aee0b6e7d3a987ced841ab7b87c41
parent356f11bc769aac4c3cb2e6ce8abcbf7a38d53b88 (diff)
downloadserenity-b05f048c05dfe55421abd9fb465d0b94209b230a.zip
LibGUI: offset value by minimum to ensure proper rendering of sliders
This subtracts the minimum from the value when rendering so that the knob doesnt go off screen for a non-zero minimum.
-rw-r--r--Libraries/LibGUI/Slider.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/Libraries/LibGUI/Slider.cpp b/Libraries/LibGUI/Slider.cpp
index 89673ed033..bd85a0b05a 100644
--- a/Libraries/LibGUI/Slider.cpp
+++ b/Libraries/LibGUI/Slider.cpp
@@ -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