-
Notifications
You must be signed in to change notification settings - Fork 187
Description
Consider this simplified version of Snippet39:
public class Snippet39 {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Snippet 39");
shell.setLayout(new FillLayout());
CCombo combo = new CCombo(shell, SWT.NONE);
combo.setText("text");
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}The arrow button on the right is two pixels too high and loses the bottom of the button:
In the unmodified snippet, the button is too high too, but it may be harder to see because the grid layout makes the shell bigger to make it visible. But you can see the button goes two pixels lower than the text:
This error happens because Button.computeSize has a small mistake around adding border when the button is default:
eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
Lines 284 to 291 in d884e6b
| if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) { | |
| boolean canDefault = GTK.GTK4 ? GTK4.gtk_widget_get_receives_default(handle) : GTK3.gtk_widget_get_can_default(handle); | |
| if (canDefault) { | |
| GtkBorder border = getBorder(OS.default_border, handle, DEFAULT_BORDER); | |
| if (wHint != SWT.DEFAULT) size.x += border.left + border.right; | |
| if (hHint != SWT.DEFAULT) size.y += border.top + border.bottom; | |
| } | |
| } |
You can see it clearly by applying this diff and seeing that the arrow computeSize returns a height higher than the client area:
$ git diff 'bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java'
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
index c700fd1632..af1efe06ab 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
@@ -1187,6 +1187,7 @@ void internalLayout (boolean changed) {
int width = rect.width;
int height = rect.height;
Point arrowSize = arrow.computeSize (SWT.DEFAULT, height, changed);
+ System.out.println("ClientArea Height: " + rect.height + " Arrow Computed Height: " + arrowSize.y);
text.setBounds (0, 0, width - arrowSize.x, height);
arrow.setBounds (width - arrowSize.x, 0, arrowSize.x, arrowSize.y);
}I will provide a PR that clamps the height of the arrow to the client area, but it doesn't feel like quite the right fix.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status