Skip to content

I20260416-1800

@HeikoKlare HeikoKlare tagged this 16 Apr 17:51
NSRoundedBezelStyle (the default rounded push button style on macOS) has
a
fixed height optimised for the system default font size of 13 pt. When a
larger custom font is set on a push or toggle button, the text overflows
the fixed rendering bounds and is visually clipped.

Apple provides NSBezelStyleFlexiblePush (previously known as the now-
deprecated NSRegularSquareBezelStyle) specifically for this situation:
it
allows the button cell to grow vertically and adapt its appearance to
whatever content height is required.

The fix has two parts:

1. setFont() – when the internal Cocoa font hook fires, check whether a
   custom font has been explicitly set on the widget (Control.font !=
null).
   If so, immediately switch the bezel style to NSBezelStyleFlexiblePush
so
   that a subsequent computeSize() / layout pass sees the correct style
and
   the cell reports the right preferred height. When the custom font is
   cleared (setFont(null)), the style is restored to
NSRoundedBezelStyle.

2. setBounds() – the existing height-threshold guard that switches bezel
   styles during layout is extended with "|| font != null" so that a
layout
   pass following a font change never inadvertently reverts the button
back
   to NSRoundedBezelStyle.

Both guards apply only to PUSH and TOGGLE buttons without the FLAT or
WRAP
style bits, mirroring the existing bezel-style selection logic.

The constant NSBezelStyleFlexiblePush is added to OS.java (value 2,
sourced
from NSButtonCell.h in the macOS 15.4 SDK) in alphabetical order
alongside
the other NSBezelStyle constants, making the intention explicit and
avoiding
reliance on the deprecated NSRegularSquareBezelStyle alias.

A regression test is added to Test_org_eclipse_swt_widgets_Button that
verifies a push button reports a greater preferred height after its font
size is increased to 50 pt. This ensures that layout managers allocate
sufficient space and the button text is not clipped.

Fixes https://github.com/eclipse-platform/eclipse.platform.swt/issues/3085
Assets 2
Loading