eclipse.platform.swt icon indicating copy to clipboard operation
eclipse.platform.swt copied to clipboard

GTK4: Layout issue on GTK4 in the presense of group widget.

Open raghucssit opened this issue 4 months ago • 3 comments

Environment: RHEL-10 GTK: 4.16

It seems like if there is a Group widget on shell it calculates wrong size/missing some widget in children list.

Please use the below example. Run this on GTK3 and GTK4 and observe the difference.. On GTK3 everything works fine a group with a label inside is rendered by default. But when enable GTK4 only group is shown with label inside and by default Button is hidden.

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.gtk.GTK;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class SWTLabelShowcase {

	public static void main(String[] args) {
		System.out.println("Is GTK4 ? " + GTK.GTK4);
		System.out.println("GTK major: " + GTK.gtk_get_major_version());
		System.out.println("GTK minor: " + GTK.gtk_get_minor_version());

		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("SWT Label API Showcase");
		shell.setLayout(new GridLayout(1, true));

		// ==== Simple Label ====
		//If you remove this group definition and add labels onto shell directly it works fine.
		Group gSimple = group(shell, "Simple Labels");
		gSimple.setLayout(new GridLayout(1, false));

		Label label1 = new Label(gSimple, SWT.NONE);
		label1.setText("Simple label (default)");

		// ==== Toggle visibility ====
		Button btnToggle = new Button(shell, SWT.PUSH);
		btnToggle.setText("Toggle image label visibility");
		GridData gdToggle = new GridData(SWT.FILL, SWT.CENTER, true, false);
		btnToggle.setLayoutData(gdToggle);

		// If you uncomment below code. Above button will be visible and this button will be
		// hidden by default
//        Button dummy = new Button(shell, SWT.PUSH);
//        dummy.setText("Dumy");
//        dummy.setLayoutData(gdToggle);

		// ==== Open shell ====
		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

	private static Group group(Composite parent, String title) {
		Group g = new Group(parent, SWT.SHADOW_ETCHED_IN);
		g.setText(title);
		g.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		return g;
	}
}

raghucssit avatar Sep 02 '25 13:09 raghucssit

https://github.com/user-attachments/assets/ec8a0dfb-cceb-41c5-a2f2-6a9853d71ded

raghucssit avatar Sep 02 '25 13:09 raghucssit

I have trimmed the snippet down to :


import org.eclipse.swt.*;
import org.eclipse.swt.internal.gtk.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class SWTLabelShowcase {

	public static void main(String[] args) {
		System.out.println("Is GTK4 ? " + GTK.GTK4);
		System.out.println("GTK major: " + GTK.gtk_get_major_version());
		System.out.println("GTK minor: " + GTK.gtk_get_minor_version());

		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new GridLayout(1, true));

		Group gSimple = group(shell, "Simple Labels");
		gSimple.setLayout(new GridLayout(1, false));

		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

	private static Group group(Composite parent, String title) {
		Group g = new Group(parent, SWT.NONE);
		g.setText(title);
		g.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		return g;
	}
}

With this snippet Group is not visible at all until one resizes.

akurtakov avatar Sep 15 '25 15:09 akurtakov

I am fairly confident issue comes from SwtFixed thus I have restored manual test app in https://github.com/eclipse-platform/eclipse.platform.swt/pull/2522

akurtakov avatar Sep 18 '25 06:09 akurtakov