Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimeon Andreev2018-04-30 12:21:13 +0000
committerSimeon Andreev2018-04-30 14:48:07 +0000
commitfaeeb9254a8dea23c4285ac820bf2d4023a13272 (patch)
tree8c86c8b409bf837acb266a0948b53ba35bb3d4dc
parentd9f5632d5ad407acb871d32f4f2af1099f6c9bf9 (diff)
downloadeclipse.platform.swt-faeeb9254a8dea23c4285ac820bf2d4023a13272.tar.gz
eclipse.platform.swt-faeeb9254a8dea23c4285ac820bf2d4023a13272.tar.xz
eclipse.platform.swt-faeeb9254a8dea23c4285ac820bf2d4023a13272.zip
Bug 534204 - [GTK3] Scale with GridLayout height hint has no line
An SWT Scale for which a low height hint is specified via GridData does not show its line on GTK 3.22. It only shows its trough. This is also observed when the parent of the Scale has a GridLayout and has a small enough size (e.g. due to resizing). This change ensures the scale is never reduced to below 26px. Resizing of the scale is not impacted, since the GTK scale resides in an SWT fixed which can still be resized at will. When resized below 26px, parts of the scale start to become not visible. Change-Id: I5d0b18783b5f126ca2fee6918b885480cbcb977e Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java20
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug534204_Scale_has_no_line.java63
2 files changed, 83 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java
index edacb4f8bf..f9bed26d71 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java
@@ -380,4 +380,24 @@ long /*int*/ gtk_scale_new (int orientation, long /*int*/ adjustment) {
}
return scale;
}
+
+@Override
+Point resizeCalculationsGTK3(long /*int*/ widget, int width, int height) {
+ Point size = super.resizeCalculationsGTK3(widget, width, height);
+ /*
+ * Bug 534204: (GTK 3.22) Scale with GridLayout height hint has no line
+ *
+ * Specifying a too low height hint for a scale, or shrinking the scale too much
+ * can result in a missing line for the scale. We specify a minimum height to avoid this.
+ * Due to the parent SwtFixed, the scale widget can still be resized below this minimum size.
+ * Instead of shrinking to comply with the too-small size, parts of it are hidden.
+ */
+ if (widget == handle && GTK.GTK_VERSION >= OS.VERSION(3, 20, 0)) {
+ GtkRequisition naturalSize = new GtkRequisition();
+ GtkRequisition minimumSize = new GtkRequisition();
+ GTK.gtk_widget_get_preferred_size(handle, minimumSize, naturalSize);
+ size.y = Math.max(size.y, minimumSize.height);
+ }
+ return size;
+}
}
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug534204_Scale_has_no_line.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug534204_Scale_has_no_line.java
new file mode 100644
index 0000000000..913a182d96
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug534204_Scale_has_no_line.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Simeon Andreev and others. All rights reserved.
+ * The contents of this file are made available under the terms
+ * of the GNU Lesser General Public License (LGPL) Version 2.1 that
+ * accompanies this distribution (lgpl-v21.txt). The LGPL is also
+ * available at http://www.gnu.org/licenses/lgpl.html. If the version
+ * of the LGPL at http://www.gnu.org is different to the version of
+ * the LGPL accompanying this distribution and there is any conflict
+ * between the two license versions, the terms of the LGPL accompanying
+ * this distribution shall govern.
+ *
+ * Contributors:
+ * Simeon Andreev - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Scale;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Description: Specifying a small height hint via {@link GridData} for a {@link Scale},
+ * or shrinking the parent of a {@link Scale} too much can result
+ * in a missing line of the scale.
+ * Steps to reproduce:
+ * <ol>
+ * <li>Run the snippet.</li>
+ * </ol>
+ * Expected results: The shell contains a scale with a line and a trough.
+ * Actual results: The shell contains a scale with a tough but without a line.
+ */
+public class Bug534204_Scale_has_no_line {
+
+ public static void main(String[] args) {
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setSize(300, 100);
+ shell.setText("Bug 534204 scale has only trough and no line");
+ shell.setLayout(new FillLayout(SWT.VERTICAL));
+
+ Composite main = new Composite(shell, SWT.NONE);
+ GridLayout gridLayout = new GridLayout(1, false);
+ main.setLayout(gridLayout);
+
+ Scale scale = new Scale(main, SWT.NONE);
+ GridData gd = new GridData();
+ gd.widthHint = 200;
+ gd.heightHint = 18;
+ scale.setLayoutData(gd);
+
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+}

Back to the top