Commit 53e410d
committed
[Cocoa] Use NSBezelStyleFlexiblePush for buttons with custom font size
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 #30851 parent d820f7e commit 53e410d
File tree
3 files changed
+42
-3
lines changed- bundles/org.eclipse.swt
- Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa
- Eclipse SWT/cocoa/org/eclipse/swt/widgets
- tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit
3 files changed
+42
-3
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2179 | 2179 | | |
2180 | 2180 | | |
2181 | 2181 | | |
| 2182 | + | |
2182 | 2183 | | |
2183 | 2184 | | |
2184 | 2185 | | |
| |||
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
829 | 829 | | |
830 | 830 | | |
831 | 831 | | |
832 | | - | |
833 | | - | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
834 | 837 | | |
835 | 838 | | |
836 | 839 | | |
| |||
845 | 848 | | |
846 | 849 | | |
847 | 850 | | |
848 | | - | |
| 851 | + | |
849 | 852 | | |
850 | 853 | | |
851 | 854 | | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
852 | 860 | | |
853 | 861 | | |
854 | 862 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
584 | 587 | | |
585 | 588 | | |
586 | 589 | | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
587 | 617 | | |
588 | 618 | | |
589 | 619 | | |
| |||
0 commit comments