From c6d2f6d9fefb981d86ca5e87d8554c00dc99e2b8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 19 Oct 2019 21:39:04 +0200 Subject: [PATCH] Really fix the standard button size in high DPI under MSW Use "relative pixels" (known as DIPs in wx) instead of dialog units, as the latter ones don't scale correctly due to rounding errors when using high DPI. Also take into account the fact that the 1px invisible border around the visible part of the buttons is not scaled by the standard control, so don't apply scaling to this part when determining the best size neither. Closes #18528. --- src/msw/anybutton.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/msw/anybutton.cpp b/src/msw/anybutton.cpp index b5b19f2d49..7fc9ab5a40 100644 --- a/src/msw/anybutton.cpp +++ b/src/msw/anybutton.cpp @@ -425,20 +425,16 @@ wxSize wxMSWButton::IncreaseToStdSizeAndCache(wxControl *btn, const wxSize& size // By default all buttons have at least the standard size. if ( !btn->HasFlag(wxBU_EXACTFIT) ) { - // The 50x14 button size is documented in the "Recommended sizing and - // spacing" section of MSDN layout article. + // The "Recommended sizing and spacing" section of MSDN layout article + // documents the default button size as being 50*14 dialog units or + // 75*23 relative pixels (what we call DIPs). As dialog units don't + // scale well in high DPI because of rounding errors, just DIPs here. // - // Note that we intentionally don't use GetDefaultSize() here, because - // it's inexact -- dialog units depend on this dialog's font. - wxSize sizeDef = btn->ConvertDialogToPixels(wxSize(50, 14)); - if ( btn->GetContentScaleFactor() > 1.0 ) - { - // At higher DPI, the returned height is too big compared to - // standard Windows buttons (like Save, Open, OK). FromDIP(25) - // matches the size of the buttons in standard Windows dialogs, see - // https://trac.wxwidgets.org/ticket/18528 for the discussion. - sizeDef.y = btn->FromDIP(25); - } + // Moreover, it looks like the extra 2px borders around the visible + // part of the button are not scaled correctly in higher than normal + // DPI, so add them without scaling. + const wxSize sizeDef = btn->FromDIP(wxSize(73, 21)) + wxSize(2, 2); + sizeBtn.IncTo(sizeDef); } else // wxBU_EXACTFIT case