From 3481598cc6a2cd74652dea00eb57d1ea8ea57c4a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 25 Apr 2021 21:17:31 +0200 Subject: [PATCH] Make wxSpinCtrlDouble::SetIncrement() update digits in wxGTK too Follow the generic version and increase the number of digits if necessary. --- include/wx/gtk/spinctrl.h | 2 +- src/gtk/spinctrl.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/wx/gtk/spinctrl.h b/include/wx/gtk/spinctrl.h index 267bd94de5..5fb19b4162 100644 --- a/include/wx/gtk/spinctrl.h +++ b/include/wx/gtk/spinctrl.h @@ -243,7 +243,7 @@ public: void SetValue(const wxString& value) wxOVERRIDE { wxSpinCtrlGTKBase::SetValue(value); } // visibility problem w/ gcc void SetValue(double value) { DoSetValue(value); } void SetRange(double minVal, double maxVal) { DoSetRange(minVal, maxVal); } - void SetIncrement(double inc) { DoSetIncrement(inc); } + void SetIncrement(double inc); void SetDigits(unsigned digits); virtual int GetBase() const wxOVERRIDE { return 10; } diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index 637fb60592..c327734e8a 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -643,6 +643,18 @@ void wxSpinCtrlDouble::GtkSetEntryWidth() gtk_entry_set_width_chars(GTK_ENTRY(m_widget), wxMax(lenMin, lenMax)); } +void wxSpinCtrlDouble::SetIncrement(double inc) +{ + DoSetIncrement(inc); + + const unsigned digits = wxSpinCtrlImpl::DetermineDigits(inc); + + // Increase the number of digits, if necessary, to show all numbers that + // can be obtained by using the new increment without loss of precision. + if ( digits > GetDigits() ) + SetDigits(digits); +} + unsigned wxSpinCtrlDouble::GetDigits() const { wxCHECK_MSG( m_widget, 0, "invalid spin button" );