Determine initial wxSpinCtrlDouble precision
For native wxGTK implementation default spin control precision is derived from the precision of the increment value. Fot the sake of consistency the same should be done in the generic implementation. Closes #18764.
This commit is contained in:
@@ -380,6 +380,7 @@ public:
|
||||
double inc = 1,
|
||||
const wxString& name = wxT("wxSpinCtrlDouble"))
|
||||
{
|
||||
DetermineDigits(inc);
|
||||
return wxSpinCtrlGenericBase::Create(parent, id, value, pos, size,
|
||||
style, min, max, initial,
|
||||
inc, name);
|
||||
@@ -410,6 +411,7 @@ protected:
|
||||
|
||||
virtual bool DoTextToValue(const wxString& text, double *val) wxOVERRIDE;
|
||||
virtual wxString DoValueToText(double val) wxOVERRIDE;
|
||||
void DetermineDigits(double inc);
|
||||
|
||||
unsigned m_digits;
|
||||
|
||||
|
@@ -673,6 +673,8 @@ wxString wxSpinCtrl::DoValueToText(double val)
|
||||
// wxSpinCtrlDouble
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define SPINCTRLDBL_MAX_DIGITS 20
|
||||
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(wxSpinCtrlDouble, wxSpinCtrlGenericBase);
|
||||
|
||||
void wxSpinCtrlDouble::DoSendEvent()
|
||||
@@ -696,7 +698,7 @@ wxString wxSpinCtrlDouble::DoValueToText(double val)
|
||||
|
||||
void wxSpinCtrlDouble::SetDigits(unsigned digits)
|
||||
{
|
||||
wxCHECK_RET( digits <= 20, "too many digits for wxSpinCtrlDouble" );
|
||||
wxCHECK_RET( digits <= SPINCTRLDBL_MAX_DIGITS, "too many digits for wxSpinCtrlDouble" );
|
||||
|
||||
if ( digits == m_digits )
|
||||
return;
|
||||
@@ -708,6 +710,16 @@ void wxSpinCtrlDouble::SetDigits(unsigned digits)
|
||||
DoSetValue(m_value, SendEvent_None);
|
||||
}
|
||||
|
||||
void wxSpinCtrlDouble::DetermineDigits(double inc)
|
||||
{
|
||||
inc = fabs(inc);
|
||||
if ( inc > 0.0 && inc < 1.0 )
|
||||
{
|
||||
m_digits = wxMin(SPINCTRLDBL_MAX_DIGITS, -static_cast<int>(floor(log10(inc))));
|
||||
m_format.Printf("%%0.%ulf", m_digits);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // wxUSE_SPINBTN
|
||||
|
||||
#endif // !wxPort-with-native-spinctrl
|
||||
|
Reference in New Issue
Block a user