Don't decrease the number of digits implicitly

wxSpinCtrlDouble::SetIncrement() should increase the number of digits if
necessary because not doing it would be inconsistent with the initial
determination of the number of digits in the ctor and would actually
lose the digits displayed, but it seems unnecessary to decrease the
number of digits and it might be surprising, so don't do it.

Add a test for this behaviour and document it.
This commit is contained in:
Vadim Zeitlin
2021-04-25 19:54:27 +01:00
parent 6938d91942
commit 0153a6673e
4 changed files with 32 additions and 14 deletions

View File

@@ -753,9 +753,17 @@ void wxSpinCtrlDouble::SetIncrement(double inc)
DoSetIncrement(inc);
DetermineDigits(inc);
const unsigned digits = DetermineDigits(inc);
UpdateAfterDigitsChange();
// We don't decrease the number of digits here, as this is unnecessary and
// could be undesirable, but we do increase it if the current number is not
// high enough to show the numbers without losing precision.
if ( digits > m_digits )
{
DoSetDigits(digits);
UpdateAfterDigitsChange();
}
}
void wxSpinCtrlDouble::SetDigits(unsigned digits)
@@ -794,21 +802,18 @@ void wxSpinCtrlDouble::ResetTextValidator()
#endif // wxUSE_VALIDATORS
}
void wxSpinCtrlDouble::DetermineDigits(double inc)
/* static */
unsigned wxSpinCtrlDouble::DetermineDigits(double inc)
{
unsigned digits;
inc = fabs(inc);
if ( inc > 0.0 && inc < 1.0 )
{
digits = wxMin(SPINCTRLDBL_MAX_DIGITS, -static_cast<int>(floor(log10(inc))));
return wxMin(SPINCTRLDBL_MAX_DIGITS, -static_cast<int>(floor(log10(inc))));
}
else
{
digits = 0;
return 0;
}
DoSetDigits(digits);
}
#endif // wxUSE_SPINBTN