Further improve best size of wxDatePickerCtrl with wxDP_ALLOWNONE
Compute the best size more precisely to be exactly compatible with the
control appearance when not using wxDP_ALLOWNONE. This unfortunately
requires hardcoding an arbitrary constant in DoGetBestSize().
Patch used for testing this code for future reference:
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 470e765423..a1d5fb9938 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -26,6 +26,8 @@
#include "wx/wx.h"
#endif
+#include "wx/datectrl.h"
+
// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------
@@ -175,6 +177,28 @@ bool MyApp::OnInit()
CreateStatusBar(2);
SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR
+
+ auto sz = new wxBoxSizer(wxVERTICAL);
+ auto addDPC = [this, sz](int style)
+ {
+ sz->Add(new wxDatePickerCtrl(this, wxID_ANY, wxDefaultDateTime,
+ wxDefaultPosition, wxDefaultSize, style),
+ wxSizerFlags().Right());
+ };
+
+ addDPC(wxDP_DROPDOWN | wxDP_ALLOWNONE | wxDP_SHOWCENTURY);
+ addDPC(wxDP_DROPDOWN | wxDP_SHOWCENTURY);
+ addDPC(wxDP_DROPDOWN | wxDP_ALLOWNONE);
+ addDPC(wxDP_DROPDOWN);
+
+ sz->AddSpacer(10);
+
+ addDPC(wxDP_SPIN | wxDP_ALLOWNONE | wxDP_SHOWCENTURY);
+ addDPC(wxDP_SPIN | wxDP_SHOWCENTURY);
+ addDPC(wxDP_SPIN | wxDP_ALLOWNONE);
+ addDPC(wxDP_SPIN);
+
+ SetSizerAndFit(sz);
}
This commit is contained in:
@@ -207,7 +207,12 @@ wxSize wxDateTimePickerCtrl::DoGetBestSize() const
|
|||||||
// size when using DTS_SHOWNONE than when not using it, which doesn't make
|
// size when using DTS_SHOWNONE than when not using it, which doesn't make
|
||||||
// any sense at all).
|
// any sense at all).
|
||||||
if ( MSWAllowsNone() )
|
if ( MSWAllowsNone() )
|
||||||
size.x += 3 * GetCharWidth();
|
{
|
||||||
|
// The extra 10px here was determined heuristically as the value which
|
||||||
|
// results in the same layout with and without DTS_SHOWNONE under
|
||||||
|
// Windows 7 and Windows 10 with 100%, 150% and 200% scaling.
|
||||||
|
size.x += wxGetSystemMetrics(SM_CXMENUCHECK, m_parent) + 10;
|
||||||
|
}
|
||||||
|
|
||||||
int scrollY = wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_Y, m_parent);
|
int scrollY = wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_Y, m_parent);
|
||||||
size.y = wxMax(size.y, scrollY);
|
size.y = wxMax(size.y, scrollY);
|
||||||
|
|||||||
Reference in New Issue
Block a user