summaryrefslogtreecommitdiff
path: root/indra/llui/llspinctrl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui/llspinctrl.cpp')
-rw-r--r--indra/llui/llspinctrl.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/indra/llui/llspinctrl.cpp b/indra/llui/llspinctrl.cpp
index fbd8335e6c..34363eb506 100644
--- a/indra/llui/llspinctrl.cpp
+++ b/indra/llui/llspinctrl.cpp
@@ -123,6 +123,23 @@ LLSpinCtrl::~LLSpinCtrl()
}
+F32 clamp_precision(F32 value, S32 decimal_precision)
+{
+ // pow() isn't perfect
+
+ F64 clamped_value = value;
+ for (S32 i = 0; i < decimal_precision; i++)
+ clamped_value *= 10.0;
+
+ clamped_value = llround((F32)clamped_value);
+
+ for (S32 i = 0; i < decimal_precision; i++)
+ clamped_value /= 10.0;
+
+ return (F32)clamped_value;
+}
+
+
// static
void LLSpinCtrl::onUpBtn( void *userdata )
{
@@ -131,6 +148,7 @@ void LLSpinCtrl::onUpBtn( void *userdata )
{
// use getValue()/setValue() to force reload from/to control
F32 val = (F32)self->getValue().asReal() + self->mIncrement;
+ val = clamp_precision(val, self->mPrecision);
val = llmin( val, self->mMaxValue );
if( self->mValidateCallback )
@@ -163,6 +181,7 @@ void LLSpinCtrl::onDownBtn( void *userdata )
if( self->getEnabled() )
{
F32 val = (F32)self->getValue().asReal() - self->mIncrement;
+ val = clamp_precision(val, self->mPrecision);
val = llmax( val, self->mMinValue );
if( self->mValidateCallback )
@@ -224,12 +243,13 @@ void LLSpinCtrl::clear()
}
+
void LLSpinCtrl::updateEditor()
{
LLLocale locale(LLLocale::USER_LOCALE);
// Don't display very small negative values as -0.000
- F32 displayed_value = (F32)floor(getValue().asReal() * pow(10.0, (F64)mPrecision) + 0.5) / (F32)pow(10.0, (F64)mPrecision);
+ F32 displayed_value = clamp_precision((F32)getValue().asReal(), mPrecision);
// if( S32( displayed_value * pow( 10, mPrecision ) ) == 0 )
// {
@@ -301,7 +321,7 @@ void LLSpinCtrl::setFocus(BOOL b)
void LLSpinCtrl::setEnabled(BOOL b)
{
- LLUICtrl::setEnabled( b );
+ LLView::setEnabled( b );
mEditor->setEnabled( b );
}