Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,7 @@ public static Selector getSelector (long value) {
public static final int NSBackspaceCharacter = 8;
public static final int NSBevelLineJoinStyle = 2;
public static final int NSBezelBorder = 2;
public static final int NSBezelStyleFlexiblePush = 2;
public static final int NSBoldFontMask = 2;
public static final int NSBorderlessWindowMask = 0;
public static final int NSBottomTabsBezelBorder = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,11 @@ void setBounds (int x, int y, int width, int height, boolean move, boolean resiz
}

NSButton button = (NSButton)view;
if (height > heightThreshold) {
button.setBezelStyle(OS.NSRegularSquareBezelStyle);
// Use NSBezelStyleFlexiblePush when a custom font is set or when the height
// exceeds the standard button height. NSRoundedBezelStyle assumes the macOS
// default font size (13pt) and clips text at larger sizes.
if (height > heightThreshold || font != null) {
button.setBezelStyle(OS.NSBezelStyleFlexiblePush);
} else {
button.setBezelStyle(OS.NSRoundedBezelStyle);
}
Expand All @@ -845,10 +848,15 @@ void setBounds (int x, int y, int width, int height, boolean move, boolean resiz
}

@Override
void setFont (NSFont font) {
void setFont (NSFont nsFont) {
if (text != null) {
((NSButton)view).setAttributedTitle(createString());
}
if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0 && (style & (SWT.FLAT | SWT.WRAP)) == 0) {
// Use NSBezelStyleFlexiblePush when a custom font is set. NSRoundedBezelStyle
// assumes the macOS default font size (13pt) and clips text at larger sizes.
((NSButton)view).setBezelStyle(font != null ? OS.NSBezelStyleFlexiblePush : OS.NSRoundedBezelStyle);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageGcDrawer;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
Expand Down Expand Up @@ -584,6 +587,34 @@ public void test_consistency_DragDetect () {
consistencyEvent(5, 5, 15, 15, ConsistencyUtility.MOUSE_DRAG);
}

/**
* Test that a push button reports a greater preferred height after its font
* size is increased. A button whose font grows larger must compute a
* proportionally taller preferred size so that layout managers allocate
* sufficient space and the text is not clipped.
*
* @see <a href="https://github.com/eclipse-platform/eclipse.platform.swt/issues/3085">issue #3085</a>
*/
@Test
public void test_computeSize_largerWithLargeCustomFont() {
button.setText("OK");
shell.open();

Point defaultSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);

FontData[] fontData = button.getFont().getFontData();
Font largeFont = new Font(button.getDisplay(), fontData[0].getName(), 50, fontData[0].getStyle());
try {
button.setFont(largeFont);
SwtTestUtil.processEvents();
Point largeSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
assertTrue(largeSize.y > defaultSize.y,
"Button with 50 pt font should be taller than button with default font");
} finally {
largeFont.dispose();
}
}

/** Test for Bug 381668 - NPE when disposing radio buttons right before they should gain focus */
@Disabled(value = "Test works fine locally but fails to get correct focus on automated builds.")
@Test
Expand Down
Loading