Skip to content

Conversation

@ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented Aug 21, 2025

The Tree.SORT_WIDTH constant defines the width reserved for the sort indicator in tree headers. Previously, this was a fixed pixel value, which appeared too small on high-DPI displays.

This change redefines SORT_WIDTH in points and converts it to pixels according to the current zoom level, ensuring consistent sort indicator spacing across different display scales.

Example

  • Run the following snippet with 250% zoom
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class TreeColumnSortWidthExample {


public static void main(String [] args) {
	final Display display = new Display();
	System.setProperty("swt.autoScale", "quarter");
	System.setProperty("swt.autoScale.updateOnRuntime", "true");
	Shell shell = new Shell(display);
	shell.setText("Custom gradient selection for Tree");
	shell.setLayout(new FillLayout());
	final Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION);
	tree.setHeaderVisible(true);
	tree.setLinesVisible(true);
	int columnCount = 4;
	for (int i=0; i<columnCount; i++) {
		TreeColumn column = new TreeColumn(tree, SWT.NONE);
		column.setText("Column " + i);
	}
	int itemCount = 3;
	for (int i=0; i<itemCount; i++) {
		TreeItem item1 = new TreeItem(tree, SWT.NONE);
		item1.setText("item "+i);
		for (int c=1; c < columnCount; c++) {
			item1.setText(c, "item ["+i+"-"+c+"]");
		}
		for (int j=0; j<itemCount; j++) {
			TreeItem item2 = new TreeItem(item1, SWT.NONE);
			item2.setText("item ["+i+" "+j+"]");
			for (int c=1; c<columnCount; c++) {
				item2.setText(c, "item ["+i+" "+j+"-"+c+"]");
			}
			for (int k=0; k<itemCount; k++) {
				TreeItem item3 = new TreeItem(item2, SWT.NONE);
				item3.setText("item ["+i+" "+j+" "+k+"]");
				for (int c=1; c<columnCount; c++) {
					item3.setText(c, "item ["+i+" "+j+" "+k+"-"+c+"]");
				}
			}
		}
	}
	tree.addListener(SWT.EraseItem, event -> {
		event.detail &= ~SWT.HOT;
		if ((event.detail & SWT.SELECTED) != 0) {
			GC gc = event.gc;
			Rectangle area = tree.getClientArea();
			/*
			 * If you wish to paint the selection beyond the end of
			 * last column, you must change the clipping region.
			 */
			int columnCount1 = tree.getColumnCount();
			if (event.index == columnCount1 - 1 || columnCount1 == 0) {
				int width = area.x + area.width - event.x;
				if (width > 0) {
					Region region = new Region();
					gc.getClipping(region);
					region.add(event.x, event.y, width, event.height);
					gc.setClipping(region);
					region.dispose();
				}
			}
			gc.setAdvanced(true);
			if (gc.getAdvanced()) gc.setAlpha(127);
			Rectangle rect = event.getBounds();
			Color foreground = gc.getForeground();
			Color background = gc.getBackground();
			gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
			gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
			gc.fillGradientRectangle(0, rect.y, 500, rect.height, false);
			// restore colors for subsequent drawing
			gc.setForeground(foreground);
			gc.setBackground(background);
			event.detail &= ~SWT.SELECTED;
		}
	});
	tree.setSortColumn(tree.getColumn(0));
	tree.setSortDirection(SWT.UP);
	for (int i=0; i<columnCount; i++) {
		tree.getColumn(i).pack();
	}
	tree.setSelection(tree.getItem(0));
	shell.setSize(500, 200);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
	}
	display.dispose();
}
}
  • Note that the first window is before change and second window is after this change. The first column (sort column) has extra pixels as the SORT_WIDTH value is stored in points and scaled up to pixels as per zoom level.
image

@github-actions
Copy link
Contributor

github-actions bot commented Aug 21, 2025

Test Results

   546 files  ±0     546 suites  ±0   30m 44s ⏱️ - 4m 5s
 4 426 tests ±0   4 409 ✅ ±0   17 💤 ±0  0 ❌ ±0 
16 750 runs  ±0  16 623 ✅ ±0  127 💤 ±0  0 ❌ ±0 

Results for commit 01a365f. ± Comparison against base commit 8ea0ac8.

♻️ This comment has been updated with latest results.

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.

In itself the change makes sense and does what it should do. So we can merge this from my side.

Only thing I want to mention, that the overall logic doesn't seem to make sense anymore. Looks like (latest) since Windows 7 the sort indicator is above the column, but with Windows XP the indicator was next to the line, where the logic probably originated from.
image

@HeikoKlare WDYT?

@HeikoKlare
Copy link
Contributor

If we are sure that at least starting with Windows 10 the sort marker is always at the top of the column header and not at the right side anymore, it would make sense to get rid of the code. I cannot imagine that there is a way to configure that, but I would expect that it was a general UI/UX change in some Windows version and that this cannot be configured, but I do not know either and from a quick search I did not find out anything about such a change to Windows (but if it was changed for Vista or 7, it's already quite long ago).
So if that code was not touched since then anyway, I would be in favor of removing it. @ShahzaibIbrahim @akoch-yatta can you create a ticket for us to remove that code?

@ShahzaibIbrahim
Copy link
Contributor Author

ShahzaibIbrahim commented Aug 30, 2025

If we are sure that at least starting with Windows 10 the sort marker is always at the top of the column header and not at the right side anymore, it would make sense to get rid of the code. I cannot imagine that there is a way to configure that, but I would expect that it was a general UI/UX change in some Windows version and that this cannot be configured, but I do not know either and from a quick search I did not find out anything about such a change to Windows (but if it was changed for Vista or 7, it's already quite long ago). So if that code was not touched since then anyway, I would be in favor of removing it. @ShahzaibIbrahim @akoch-yatta can you create a ticket for us to remove that code?

I can create a new ticket for this.

Here, vi-eclipse/Eclipse-Platform#429

@akoch-yatta akoch-yatta force-pushed the master-404-SORT_WIDTH branch from 60ac4d7 to 01a365f Compare September 3, 2025 11:47
@akoch-yatta akoch-yatta merged commit 1bad9a2 into eclipse-platform:master Sep 3, 2025
20 of 22 checks passed
@akoch-yatta akoch-yatta deleted the master-404-SORT_WIDTH branch September 3, 2025 12:22
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.

Fix the values of SORT_WIDTH in points

3 participants