MCPcopy Create free account
hub / github.com/TankOs/SFGUI / UpdateAdjustmentFromText

Method UpdateAdjustmentFromText

src/SFGUI/SpinButton.cpp:302–329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300}
301
302void SpinButton::UpdateAdjustmentFromText() {
303 if( !GetText().getSize() ) {
304 m_adjustment->SetValue( m_adjustment->GetLower() );
305 return;
306 }
307
308 std::istringstream text( GetText().toAnsiString() );
309
310 float value;
311
312 if( !( text >> value ) || !text.eof() ) {
313 m_adjustment->SetValue( m_adjustment->GetLower() );
314 return;
315 }
316
317 auto offset = value - m_adjustment->GetLower();
318 auto multiple = ( m_adjustment->GetMinorStep() != 0.f ) ? ( offset / m_adjustment->GetMinorStep() ) : 0.f;
319 auto step_offset = offset - std::floor( multiple ) * m_adjustment->GetMinorStep();
320
321 if( step_offset >= m_adjustment->GetMinorStep() / 2.f ) {
322 value = m_adjustment->GetLower() + std::ceil( multiple ) * m_adjustment->GetMinorStep();
323 }
324 else {
325 value = m_adjustment->GetLower() + std::floor( multiple ) * m_adjustment->GetMinorStep();
326 }
327
328 m_adjustment->SetValue( value );
329}
330
331}

Callers

nothing calls this directly

Calls 3

GetLowerMethod · 0.80
GetMinorStepMethod · 0.80
SetValueMethod · 0.45

Tested by

no test coverage detected