void LLSpinCtrl::updateEditor() { LLLocale locale(LLLocale::USER_LOCALE); // Don't display very small negative values as -0.000 F32 displayed_value = clamp_precision((F32)getValue().asReal(), mPrecision); // if( S32( displayed_value * pow( 10, mPrecision ) ) == 0 ) // { // displayed_value = 0.f; // } std::string format = llformat("%%.%df", mPrecision); std::string text = llformat(format.c_str(), displayed_value); mEditor->setText( text ); }
void LLSpinCtrl::onUpBtn( const LLSD& data ) { if( getEnabled() ) { std::string text = mEditor->getText(); if( LLLineEditor::postvalidateFloat( text ) ) { LLLocale locale(LLLocale::USER_LOCALE); F32 cur_val = (F32) atof(text.c_str()); // use getValue()/setValue() to force reload from/to control //alt/ctrl/shift keys modify increment F32 inc = mIncrement; if(gKeyboard->getKeyDown(KEY_ALT)) inc *= 10.f; else if(gKeyboard->getKeyDown(KEY_CONTROL)) inc *= 0.1f; else if(gKeyboard->getKeyDown(KEY_SHIFT)) inc *= 0.01f; F32 val = cur_val + inc; val = clamp_precision(val, mPrecision); val = llmin( val, mMaxValue ); if (val < mMinValue) val = mMinValue; if (val > mMaxValue) val = mMaxValue; F32 saved_val = (F32)getValue().asReal(); setValue(val); if( mValidateSignal && !(*mValidateSignal)( this, val ) ) { setValue( saved_val ); reportInvalidData(); updateEditor(); return; } updateEditor(); onCommit(); } } }