Add wxFloatingPointValidator::SetFactor()

This allows displaying values in percents (or also currency units and
subunits, for example) without changing the actually stored value.
This commit is contained in:
Vadim Zeitlin
2018-01-25 19:30:39 +01:00
parent f836d430e9
commit b1e59a6d60
6 changed files with 75 additions and 11 deletions

View File

@@ -251,14 +251,21 @@ wxIntegerValidatorBase::IsCharOk(const wxString& val, int pos, wxChar ch) const
wxString wxFloatingPointValidatorBase::ToString(LongestValueType value) const
{
return wxNumberFormatter::ToString(value, m_precision, GetFormatFlags());
return wxNumberFormatter::ToString(value*m_factor,
m_precision,
GetFormatFlags());
}
bool
wxFloatingPointValidatorBase::FromString(const wxString& s,
LongestValueType *value)
LongestValueType *value) const
{
return wxNumberFormatter::FromString(s, value);
if ( !wxNumberFormatter::FromString(s, value) )
return false;
*value /= m_factor;
return true;
}
bool