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.
This commit is contained in:
Vadim Zeitlin 2016-04-03 18:02:43 +02:00
parent 25c9b032a8
commit 7465237353
2 changed files with 11 additions and 1 deletions

View File

@ -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:

View File

@ -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<int>(DoGetMin());
const int lenMin = wxString::Format("%d", minVal).length();
const int maxVal = static_cast<int>(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