From 9d8eb7c399fb5fe33e3deb62181fe83c1e3814a1 Mon Sep 17 00:00:00 2001 From: Shahzaib Ibrahim Date: Fri, 22 Aug 2025 10:56:54 +0200 Subject: [PATCH] Scale Tree.GRID_WIDTH by zoom level instead of using fixed pixels 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. --- .../Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java | 8 ++++---- .../win32/org/eclipse/swt/widgets/TreeColumn.java | 2 +- .../win32/org/eclipse/swt/widgets/TreeItem.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java index cae89339049..73f45dffa13 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java @@ -2964,11 +2964,11 @@ TreeItem getFocusItem () { */ public int getGridLineWidth () { checkWidget (); - return DPIUtil.pixelToPoint(getGridLineWidthInPixels (), getZoom()); + return GRID_WIDTH; } int getGridLineWidthInPixels () { - return GRID_WIDTH; + return Win32DPIUtils.pointToPixel(GRID_WIDTH, getZoom()); } /** @@ -8060,7 +8060,7 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) { int deltaX = newItem.cxy - oldItem.cxy; RECT headerRect = new RECT (); OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, phdn.iItem, headerRect); - int gridWidth = linesVisible ? GRID_WIDTH : 0; + int gridWidth = linesVisible ? getGridLineWidthInPixels() : 0; rect.left = headerRect.right - gridWidth; int newX = rect.left + deltaX; rect.right = Math.max (rect.right, rect.left + Math.abs (deltaX)); @@ -8239,7 +8239,7 @@ LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, long lParam) { } if (drawForeground) { int nSavedDC = OS.SaveDC (nmcd.hdc); - int gridWidth = getLinesVisible () ? Table.GRID_WIDTH : 0; + int gridWidth = getLinesVisible () ? getGridLineWidthInPixels() : 0; RECT insetRect = toolTipInset (cellRect [0]); OS.SetWindowOrgEx (nmcd.hdc, insetRect.left, insetRect.top, null); GCData data = new GCData (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java index 6c7c4c2d79c..844eac0c29b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java @@ -398,7 +398,7 @@ public void pack () { } if (newFont != 0) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (hwnd, hDC); - int gridWidth = parent.linesVisible ? Tree.GRID_WIDTH : 0; + int gridWidth = parent.linesVisible ? parent.getGridLineWidthInPixels() : 0; setWidthInPixels (Math.max (headerWidth, columnWidth + gridWidth)); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java index 36158c18041..426c9ee35ac 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java @@ -530,7 +530,7 @@ RECT getBounds (int index, boolean getText, boolean getImage, boolean fullText, } } } - int gridWidth = parent.linesVisible && columnCount != 0 ? Tree.GRID_WIDTH : 0; + int gridWidth = parent.linesVisible && columnCount != 0 ? parent.getGridLineWidthInPixels() : 0; if (getText || !getImage) { rect.right = Math.max (rect.left, rect.right - gridWidth); }