From 0941b25a973fc4ef15e2ef7365c16f67d8406448 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sat, 6 Jun 2020 22:36:45 +0100 Subject: [PATCH] Improve wxBitmapButton best size for small bitmaps in wxOSX The correct condition for adding the extra border to the buttons that would be clipped without it due to the bezel style used for them is to check that their height is < 20, as SetBezelStyleFromBorderFlags(), which determines the bezel to use, does, and not if their width is 16, as this is not the same thing, especially for non-square buttons. Closes https://github.com/wxWidgets/wxWidgets/pull/1887 --- src/osx/bmpbuttn_osx.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/osx/bmpbuttn_osx.cpp b/src/osx/bmpbuttn_osx.cpp index 5f26d49e71..1dea31518f 100644 --- a/src/osx/bmpbuttn_osx.cpp +++ b/src/osx/bmpbuttn_osx.cpp @@ -58,11 +58,17 @@ wxSize wxBitmapButton::DoGetBestSize() const if ( GetBitmapLabel().IsOk() ) { - // Hack to stop 16x16 bitmap being clipped - if (GetBitmapLabel().GetScaledSize().x == 16) + const wxSize bitmapSize = GetBitmapLabel().GetScaledSize(); + best += bitmapSize; + + // The NSRoundedBezelStyle and NSTexturedRoundedBezelStyle used when + // the image is less than 20px tall have a small horizontal border, + // account for it here to prevent part of the image from being cut off. + // + // Note that the magic 20px comes from SetBezelStyleFromBorderFlags() + // defined in src/osx/cocoa/button.mm. + if ( bitmapSize.y < 20 ) best += wxSize(4,0); - - best += GetBitmapLabel().GetScaledSize(); } return best;