Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GTK3] images are cropped and/or not displayed in Tree with SWT.VIRTUAL #1739

Open
zkxvh opened this issue Jan 20, 2025 · 1 comment · May be fixed by #1743
Open

[GTK3] images are cropped and/or not displayed in Tree with SWT.VIRTUAL #1739

zkxvh opened this issue Jan 20, 2025 · 1 comment · May be fixed by #1743

Comments

@zkxvh
Copy link

zkxvh commented Jan 20, 2025

Describe the bug
Images in a tree with SWT.VIRTUAL often displayed as cropped or not shown at all.

Example 1:
Start the snippet below and press the following buttons: [2,1], then [3,2] and finally [1,0].
This is what I get: image for [3,2] is cropped, image for [1,0] isn't shown:
Image

Example 2:
Start the snippet below and do the following:

  1. press button [32,1]
  2. scroll the content of the tree down to show [32,1]
  3. press buttons [33,2] and [31,0]

This is what I get: images for [31,0], [32,1] and [33,2]are cropped:
Image

To Reproduce

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class SetImage_TreeVirtual {

	private Display display;
	private Shell shell;
	private Composite buttonBox;
	private Tree tree;

	private Image[][] images = new Image[50][3];

	public static void main (String[] args) {
		new SetImage_TreeVirtual ().run ();
	}

	void run () {
		display = new Display ();
		shell = new Shell (display);
		shell.setText (getClass ().getSimpleName ());
		shell.setLayout (new GridLayout ());

		buttonBox = new Composite (shell, 0);
		buttonBox.setLayout (new FillLayout ());
		createSetImageButton (1, 0, 20, display.getSystemColor (SWT.COLOR_RED));
		createSetImageButton (2, 1, 40, display.getSystemColor (SWT.COLOR_GREEN));
		createSetImageButton (3, 2, 60, display.getSystemColor (SWT.COLOR_BLUE));

		buttonBox = new Composite (shell, 0);
		buttonBox.setLayout (new FillLayout ());
		createSetImageButton (31, 0, 20, display.getSystemColor (SWT.COLOR_CYAN));
		createSetImageButton (32, 1, 40, display.getSystemColor (SWT.COLOR_BLACK));
		createSetImageButton (33, 2, 60, display.getSystemColor (SWT.COLOR_MAGENTA));

		tree = new Tree (shell, SWT.VIRTUAL);
		tree.setHeaderVisible (true);
		tree.setLayoutData (new GridData (GridData.FILL_BOTH));
		for (int i = 1; i <= 3; i++) {
			var column = new TreeColumn (tree, SWT.LEFT);
			column.setText ("Column " + i);
			column.setWidth (200);
		}

		tree.addListener (SWT.SetData, e -> {
			TreeItem item = (TreeItem) e.item;
			var row = tree.indexOf (item);
			for (var col = 0; col < 3; col++) {
				item.setText (col, "[" + row + "," + col + "]");
				item.setImage (col, images[row][col]);
			}
		});
		tree.setItemCount (50);

		shell.setSize (700, 600);
		shell.open ();

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

	private void createSetImageButton (int row, int col, int imageSize, Color imageColor) {
		var button = new Button (buttonBox, SWT.PUSH);
		var image = createImage (imageSize, imageColor);
		button.setImage (image);
		button.setText ("[" + row + "," + col + "]");
		button.addListener (SWT.Selection, e -> {
			images[row][col] = (images[row][col] == null) ? image : null;
			tree.clear (row, false);
		});
	}

	private Image createImage (int imageSize, Color color) {
		var image = new Image (display, imageSize, imageSize);
		var gc = new GC (image);
		gc.setForeground (color);
		gc.setBackground (display.getSystemColor (SWT.COLOR_WHITE));
		gc.setLineWidth (5);
		gc.fillRectangle (0, 0, imageSize, imageSize);
		gc.drawRectangle (0, 0, imageSize - 1, imageSize - 1);
		gc.dispose ();
		return image;
	}
}

Expected behavior
Images should be shown and should not be cropped.

Screenshots
See above.

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)
    Ubuntu 24.04.1 LTS
    Windowing System x11
    X.Org version: 21.1.11
    XFCE 4.18
    GTK 3.24.41

  2. JRE/JDK version
    OpenJDK 64-Bit Server VM (build 17.0.13+11-Ubuntu-2ubuntu124.04, mixed mode, sharing)

Version since
SWT 4.964

Workaround (or) Additional context
Sometimes the snippet may crash because of #678

zkxvh added a commit to zkxvh/eclipse.platform.swt that referenced this issue Jan 20, 2025
zkxvh added a commit to zkxvh/eclipse.platform.swt that referenced this issue Jan 20, 2025
Fixes image display problems (cropping, not showing) for Tree and Table
(both normal and virtual variants).

Fixes eclipse-platform#1739
zkxvh added a commit to zkxvh/eclipse.platform.swt that referenced this issue Jan 21, 2025
zkxvh added a commit to zkxvh/eclipse.platform.swt that referenced this issue Jan 21, 2025
Fixes image display problems (cropping, not showing) for Tree and Table
(both normal and virtual variants).

Fixes eclipse-platform#1739
This was referenced Jan 21, 2025
@deepika-u
Copy link
Contributor

Hi, I am also seeing the same issue with below environment.

Image

Image

Environment
Description: Ubuntu 24.04 LTS
XDG_SESSION_TYPE=wayland

Eclipse SDK
Version: 2025-03 (4.35)
Build id: I20250108-1800
OS: Linux, v.6.8.0-51-generic, x86_64 / gtk 3.24.41
Java vendor: Oracle Corporation
Java runtime version: 23+36-2368
Java version: 23

Let me try your pr now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants