diff options
Diffstat (limited to 'src/gui/inttextfield.cpp')
-rw-r--r-- | src/gui/inttextfield.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/gui/inttextfield.cpp b/src/gui/inttextfield.cpp index fcbe938d..9f633965 100644 --- a/src/gui/inttextfield.cpp +++ b/src/gui/inttextfield.cpp @@ -57,6 +57,16 @@ void IntTextField::setRange(int min, int max) { mMin = min; mMax = max; + + if (mValue < mMin) + mValue = mMin; + else if (mValue > mMax) + mValue = mMax; + + if (mDefault < mMin) + mDefault = mMin; + else if (mDefault > mMax) + mDefault = mMax; } int IntTextField::getValue() @@ -66,18 +76,28 @@ int IntTextField::getValue() void IntTextField::setValue(int i) { - if (i >= mMin && i <= mMax) - mValue = i; - else if (i < mMin) + if (i < mMin) mValue = mMin; else if (i > mMax) mValue = mMax; + else + mValue = i; const std::string valStr = toString(mValue); setText(valStr); setCaretPosition(valStr.length() + 1); } +void IntTextField::setDefaultValue(int value) +{ + if (value < mMin) + mDefault = mMin; + else if (value > mMax) + mDefault = mMax; + else + mDefault = value; +} + void IntTextField::reset() { setValue(mDefault); |