From a3526b19413ae88232b73f173fe8eaa41d287eb6 Mon Sep 17 00:00:00 2001 From: Shahzaib Ibrahim Date: Tue, 26 Aug 2025 12:40:37 +0200 Subject: [PATCH] Scale Table.GRID_WIDTH by zoom level instead of using fixed pixels The Table.GRID_WIDTH constant specifies the extra width added to a table item when lines between columns are visible (`lineVisible = true`). This accounts for the space taken by the grid line. Previously, it was defined as a fixed pixel value, which appeared too small on high-DPI monitors. This change redefines GRID_WIDTH in points and scales it to pixels based on the current zoom level. At 100% zoom this results in 2px instead of 1px, which is visually negligible but ensures consistency by keeping all constants defined in points and scaled according to zoom level. --- .../win32/org/eclipse/swt/widgets/Table.java | 14 +++++++------- .../win32/org/eclipse/swt/widgets/TableItem.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java index d72fe48a7b5..37b24dd4d67 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java @@ -2334,11 +2334,11 @@ int getFocusIndex () { */ public int getGridLineWidth () { checkWidget (); - return DPIUtil.pixelToPoint(getGridLineWidthInPixels(), getZoom()); + return GRID_WIDTH; } int getGridLineWidthInPixels () { - return GRID_WIDTH; + return Win32DPIUtils.pointToPixel(GRID_WIDTH, getZoom()); } /** @@ -5308,7 +5308,7 @@ public void showColumn (TableColumn column) { OS.GetScrollInfo (handle, OS.SB_HORZ, info); int newPos = info.nPos; if (newPos < oldPos) { - rect.right = oldPos - newPos + GRID_WIDTH; + rect.right = oldPos - newPos + getGridLineWidthInPixels(); OS.InvalidateRect (handle, rect, true); } } @@ -6353,7 +6353,7 @@ LRESULT WM_HSCROLL (long wParam, long lParam) { if (newPos < oldPos) { RECT rect = new RECT (); OS.GetClientRect (handle, rect); - rect.right = oldPos - newPos + GRID_WIDTH; + rect.right = oldPos - newPos + getGridLineWidthInPixels(); OS.InvalidateRect (handle, rect, true); } } @@ -6462,9 +6462,9 @@ LRESULT WM_VSCROLL (long wParam, long lParam) { long oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0); int itemHeight = OS.HIWORD (oneItem) - OS.HIWORD (empty); if (code == OS.SB_LINEDOWN) { - clientRect.top = clientRect.bottom - itemHeight - GRID_WIDTH; + clientRect.top = clientRect.bottom - itemHeight - getGridLineWidthInPixels(); } else { - clientRect.bottom = clientRect.top + itemHeight + GRID_WIDTH; + clientRect.bottom = clientRect.top + itemHeight + getGridLineWidthInPixels(); } OS.InvalidateRect (handle, clientRect, true); break; @@ -7283,7 +7283,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); 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/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java index 2d2f01686d1..f5bf83db6c9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java @@ -415,7 +415,7 @@ RECT getBounds (int row, int column, boolean getText, boolean getImage, boolean * the grid width when the grid is visible. The fix is to * move the top of the rectangle up by the grid width. */ - int gridWidth = parent.getLinesVisible () ? Table.GRID_WIDTH : 0; + int gridWidth = parent.getLinesVisible () ? parent.getGridLineWidthInPixels() : 0; rect.top -= gridWidth; if (column != 0) rect.left += gridWidth; rect.right = Math.max (rect.right, rect.left);