From 7465237353f795bb9872aca688e9c19000a7a16d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 Apr 2016 18:02:43 +0200 Subject: [PATCH] Improve wxSpinCtrl best size computation in wxGTK Don't hardcode completely arbitrary width of 95px for the text part, but compute it from the values this control is actually used for. --- docs/changes.txt | 1 + src/gtk/spinctrl.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 3b04f6a60c..8bf63bcef4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -76,6 +76,7 @@ wxGTK: - Implement setting link colours in wxHyperlinkCtrl for GTK+3 (Hanmac). - Support background colour in wxDataViewCtrl attributes. +- Improve wxSpinCtrl best size calculation. wxMSW: diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index c7067fdf57..b33593cf59 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -355,7 +355,16 @@ GdkWindow *wxSpinCtrlGTKBase::GTKGetWindow(wxArrayGdkWindows& windows) const wxSize wxSpinCtrlGTKBase::DoGetBestSize() const { - return DoGetSizeFromTextSize(95); // TODO: 95 is completely arbitrary + const int minVal = static_cast(DoGetMin()); + const int lenMin = wxString::Format("%d", minVal).length(); + + const int maxVal = static_cast(DoGetMax()); + const int lenMax = wxString::Format("%d", maxVal).length(); + + wxString longestText(wxMax(lenMin, lenMax), '9'); + if ( minVal < 0 ) + longestText.insert(0, "-"); + return DoGetSizeFromTextSize(GetTextExtent(longestText).x, -1); } wxSize wxSpinCtrlGTKBase::DoGetSizeFromTextSize(int xlen, int ylen) const