summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-01-20 13:16:58 +0100
committerAndreas Kling <kling@serenityos.org>2020-01-20 13:17:16 +0100
commitb25210ee1b04bf3a317cbca7e8ba7acaaf8ad54a (patch)
tree0311181200e2466d3747fc6999e3b56910951be0 /Libraries
parentb52d0afecf024f967319dc9ec73421c9f638e5f4 (diff)
downloadserenity-b25210ee1b04bf3a317cbca7e8ba7acaaf8ad54a.zip
LibGUI: Use clamp() is various places
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/GProgressBar.cpp5
-rw-r--r--Libraries/LibGUI/GScrollBar.cpp10
-rw-r--r--Libraries/LibGUI/GSlider.cpp11
-rw-r--r--Libraries/LibGUI/GSpinBox.cpp10
4 files changed, 7 insertions, 29 deletions
diff --git a/Libraries/LibGUI/GProgressBar.cpp b/Libraries/LibGUI/GProgressBar.cpp
index ba8b8116ec..e0c1076c31 100644
--- a/Libraries/LibGUI/GProgressBar.cpp
+++ b/Libraries/LibGUI/GProgressBar.cpp
@@ -53,10 +53,7 @@ void GProgressBar::set_range(int min, int max)
ASSERT(min < max);
m_min = min;
m_max = max;
- if (m_value > m_max)
- m_value = m_max;
- if (m_value < m_min)
- m_value = m_min;
+ m_value = clamp(m_value, m_min, m_max);
}
void GProgressBar::paint_event(GPaintEvent& event)
diff --git a/Libraries/LibGUI/GScrollBar.cpp b/Libraries/LibGUI/GScrollBar.cpp
index 191fd7a855..b278b8331e 100644
--- a/Libraries/LibGUI/GScrollBar.cpp
+++ b/Libraries/LibGUI/GScrollBar.cpp
@@ -129,10 +129,7 @@ void GScrollBar::set_range(int min, int max)
m_max = max;
int old_value = m_value;
- if (m_value < m_min)
- m_value = m_min;
- if (m_value > m_max)
- m_value = m_max;
+ m_value = clamp(m_value, m_min, m_max);
if (on_change && m_value != old_value)
on_change(m_value);
@@ -141,10 +138,7 @@ void GScrollBar::set_range(int min, int max)
void GScrollBar::set_value(int value)
{
- if (value < m_min)
- value = m_min;
- if (value > m_max)
- value = m_max;
+ value = clamp(value, m_min, m_max);
if (value == m_value)
return;
m_value = value;
diff --git a/Libraries/LibGUI/GSlider.cpp b/Libraries/LibGUI/GSlider.cpp
index 5fb81524a6..8f07095dfb 100644
--- a/Libraries/LibGUI/GSlider.cpp
+++ b/Libraries/LibGUI/GSlider.cpp
@@ -50,20 +50,13 @@ void GSlider::set_range(int min, int max)
return;
m_min = min;
m_max = max;
-
- if (m_value > max)
- m_value = max;
- if (m_value < min)
- m_value = min;
+ m_value = clamp(m_value, m_min, m_max);
update();
}
void GSlider::set_value(int value)
{
- if (value > m_max)
- value = m_max;
- if (value < m_min)
- value = m_min;
+ value = clamp(value, m_min, m_max);
if (m_value == value)
return;
m_value = value;
diff --git a/Libraries/LibGUI/GSpinBox.cpp b/Libraries/LibGUI/GSpinBox.cpp
index fe33a3e3dd..9482ee6341 100644
--- a/Libraries/LibGUI/GSpinBox.cpp
+++ b/Libraries/LibGUI/GSpinBox.cpp
@@ -59,10 +59,7 @@ GSpinBox::~GSpinBox()
void GSpinBox::set_value(int value)
{
- if (value < m_min)
- value = m_min;
- if (value > m_max)
- value = m_max;
+ value = clamp(value, m_min, m_max);
if (m_value == value)
return;
m_value = value;
@@ -82,10 +79,7 @@ void GSpinBox::set_range(int min, int max)
m_max = max;
int old_value = m_value;
- if (m_value < m_min)
- m_value = m_min;
- if (m_value > m_max)
- m_value = m_max;
+ m_value = clamp(m_value, m_min, m_max);
if (on_change && m_value != old_value)
on_change(m_value);