Prevent setting slider ranges with min > max (fix #4191)

This commit is contained in:
Martín Capello 2023-12-21 10:48:42 -03:00 committed by David Capello
parent da7f51ee43
commit d10f0cc054
2 changed files with 13 additions and 5 deletions

View File

@ -30,23 +30,30 @@ static bool slider_press_left;
Slider::Slider(int min, int max, int value, SliderDelegate* delegate)
: Widget(kSliderWidget)
, m_min(min)
, m_max(max)
, m_value(std::clamp(value, min, max))
, m_value(value)
, m_readOnly(false)
, m_delegate(delegate)
{
enforceValidRange(min, max);
setFocusStop(true);
initTheme();
}
void Slider::setRange(int min, int max)
{
enforceValidRange(min, max);
invalidate();
}
void Slider::enforceValidRange(int min, int max)
{
// Do not allow min > max
if (min > max)
max = min;
m_min = min;
m_max = max;
m_value = std::clamp(m_value, min, max);
invalidate();
}
void Slider::setValue(int value)

View File

@ -55,6 +55,7 @@ namespace ui {
private:
void setupSliderCursor();
void enforceValidRange(int min, int max);
int m_min;
int m_max;