Skip to content

Conversation

ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented Aug 22, 2025

The Tree.GRID_WIDTH constant specifies the extra width added to a tree item when lines between columns are visible (lineVisible = true). This compensates for the space taken by the grid line. Previously, this was defined as a fixed pixel value, which appeared too small on high-DPI monitors.

This change redefines GRID_WIDTH in points and converts it to pixels based on the current zoom level, ensuring consistent column spacing across different display scales.

How To Test

  • Run the following snippet in 200% zoom
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class LinesVisibleTreeExample {

public static void main (String [] args) {
	System.setProperty("swt.autoScale", "quarter");
	System.setProperty("swt.autoScale.updateOnRuntime", "true");
	Display display = new Display ();
	Shell shell = new Shell (display);
	shell.setText("Snippet 15");
	shell.setLayout(new FillLayout());
	final Tree tree = new Tree (shell, SWT.BORDER);
	tree.setLinesVisible(true);
	TreeColumn treeColumn = new TreeColumn(tree, SWT.NONE);
	treeColumn.setText("TreeColumn");
	for (int i=0; i<4; i++) {
		TreeItem iItem = new TreeItem (tree, 0);
		iItem.setText ("TreeItem (0) -" + i);
		for (int j=0; j<4; j++) {
			TreeItem jItem = new TreeItem (iItem, 0);
			jItem.setText ("TreeItem (1) -" + j);
			for (int k=0; k<4; k++) {
				TreeItem kItem = new TreeItem (jItem, 0);
				kItem.setText ("TreeItem (2) -" + k);
				for (int l=0; l<4; l++) {
					TreeItem lItem = new TreeItem (kItem, 0);
					lItem.setText ("TreeItem (3) -" + l);
				}
			}
		}
	}
	treeColumn.pack();
	shell.setSize (200, 200);
	shell.open ();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}
image

Currently, since lines are visible, we add 1 point to the item width by default. With this change, the value is now defined in points and scaled to pixels, resulting in 2px at 200% zoom. Although the visual difference is negligible, this ensures consistency by keeping all such constants defined in points and scaled according to the zoom level.

Copy link
Contributor

github-actions bot commented Aug 22, 2025

Test Results

   546 files  + 7     546 suites  +7   29m 15s ⏱️ - 6m 1s
 4 426 tests +54   4 409 ✅ +70   17 💤 +3  0 ❌  - 6 
16 750 runs  +54  16 623 ✅ +70  127 💤 +3  0 ❌  - 6 

Results for commit 9d8eb7c. ± Comparison against base commit 3444886.

♻️ This comment has been updated with latest results.

@akoch-yatta
Copy link
Contributor

@ShahzaibIbrahim While reviewing, I noticed that here Table.GRID_WIDTH is used in Tree for some reason. Can you adapt this place in this PR as well, please

Copy link
Contributor

@akoch-yatta akoch-yatta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated in the PR, the visual difference is neglectable it still makes sense to treat this magic number properly as point instead of pixel. Changes look sound and I didn't find any problems when testing the changes.

The Tree.GRID_WIDTH constant specifies the extra width added to a tree item when lines between columns are visible (`lineVisible = true`). This compensates for the space taken by the grid line. Previously, this was defined as a fixed pixel value, which appeared too small on high-DPI monitors.

This change redefines GRID_WIDTH in points and converts it to pixels based on the current zoom level, ensuring consistent column spacing across different display scales.
@akoch-yatta akoch-yatta force-pushed the master-404-GRID_WIDTH branch from 1113c9a to 9d8eb7c Compare September 4, 2025 06:56
@akoch-yatta akoch-yatta merged commit 9bf4caf into eclipse-platform:master Sep 4, 2025
17 checks passed
@akoch-yatta akoch-yatta deleted the master-404-GRID_WIDTH branch September 4, 2025 07:20
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 this pull request may close these issues.

Scale Tree.GRID_WIDTH by zoom level instead of using fixed pixels
2 participants