Skip to content

Commit 6da9e14

Browse files
committed
[Mac] Buttons with font sizes>23pt are not correctly rendered #3085
Fix the issue by handling the case when a button uses a custom font with size > 16pt. In this case adjust the button height in cellSizeForBounds(), similar to the other height adjustment fixes already present. Signed-off-by: Stefan Winkler <stefan@winklerweb.net>
1 parent 588e560 commit 6da9e14

File tree

1 file changed

+10
-0
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets

1 file changed

+10
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ NSSize cellSizeForBounds (long id, long sel, NSRect cellFrame) {
151151
size.height = Math.max(size.height, imageSize.height);
152152
}
153153

154+
// native buttons always return a height of 24.0; a font size higher than 16pt is not reflected.
155+
// Therefore, we adjust the button height manually, if a custom font with a size > 16 is set.
156+
if (font != null && font.handle.pointSize() > 16.0) {
157+
NSCell cell = new NSCell (id);
158+
NSRect titleRect = cell.titleRectForBounds(cellFrame);
159+
// for some reason, the titleRectForBounds() returns too small heights for font sizes > 20
160+
final int FONT_SIZE_HEIGHT_ADJUST = 8;
161+
size.height = Math.max(size.height, titleRect.height + FONT_SIZE_HEIGHT_ADJUST);
162+
}
163+
154164
if (((style & (SWT.PUSH|SWT.TOGGLE)) !=0) && (style & (SWT.FLAT|SWT.WRAP)) == 0) {
155165
if (image != null) {
156166
NSCell cell = new NSCell(id);

0 commit comments

Comments
 (0)