Update number of digits in wxSpinCtrlDouble::SetIncrement()
This is consistent with using the value of the increment specified in
the ctor for setting the initial number of digits, it was surprising
that creating the control with some value of the increment (e.g. 0.1)
and calling SetIncrement(0.1) later resulted in very different outcomes,
as in the former case the value was shown with a digit after the period
while in the latter case only the integer part was shown.
This also makes the behaviour compatible with that of the previous
versions of the generic wxSpinCtrlDouble, which used "%g" to format the
number before the changes of edc553870f (Fix displaying wxSpinCtrlDouble
values with default precision, 2020-05-18), as they did show the
fractional part even in the latter case.
Add a test checking that this works as expected: before this commit, the
test failed with "1 == 1.2" and "1 == 1.23" errors.
This commit is contained in:
@@ -746,6 +746,18 @@ wxString wxSpinCtrlDouble::DoValueToText(double val)
|
||||
return wxString::Format(m_format, val);
|
||||
}
|
||||
|
||||
void wxSpinCtrlDouble::SetIncrement(double inc)
|
||||
{
|
||||
if ( inc == m_increment )
|
||||
return;
|
||||
|
||||
DoSetIncrement(inc);
|
||||
|
||||
DetermineDigits(inc);
|
||||
|
||||
UpdateAfterDigitsChange();
|
||||
}
|
||||
|
||||
void wxSpinCtrlDouble::SetDigits(unsigned digits)
|
||||
{
|
||||
wxCHECK_RET( digits <= SPINCTRLDBL_MAX_DIGITS, "too many digits for wxSpinCtrlDouble" );
|
||||
@@ -755,6 +767,11 @@ void wxSpinCtrlDouble::SetDigits(unsigned digits)
|
||||
|
||||
DoSetDigits(digits);
|
||||
|
||||
UpdateAfterDigitsChange();
|
||||
}
|
||||
|
||||
void wxSpinCtrlDouble::UpdateAfterDigitsChange()
|
||||
{
|
||||
ResetTextValidator();
|
||||
m_textCtrl->InvalidateBestSize();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user