Skip to content

Commit 0d2c14c

Browse files
ShahzaibIbrahimakoch-yatta
authored andcommitted
Scale Table.INSET by zoom level instead of using fixed pixels
The Table.INSET constant defines the spacing in the width of a table cell. Previously, this was a fixed value of 3px, which looks correct at 100% zoom but causes the image and text to appear cramped on higher-DPI displays. This change defines INSET in points and converts it to pixels based on the current zoom level (e.g. 6px at 200%), ensuring consistent spacing across different monitor scale.
1 parent 1ae0e18 commit 0d2c14c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4860,7 +4860,7 @@ boolean setScrollWidth (TableItem item, boolean force) {
48604860
if (hStateList != 0) {
48614861
int [] cx = new int [1], cy = new int [1];
48624862
OS.ImageList_GetIconSize (hStateList, cx, cy);
4863-
newWidth += cx [0] + INSET;
4863+
newWidth += cx [0] + Win32DPIUtils.pointToPixel(INSET, getZoom());
48644864
}
48654865
long hImageList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);
48664866
if (hImageList != 0) {
@@ -4880,7 +4880,7 @@ boolean setScrollWidth (TableItem item, boolean force) {
48804880
*/
48814881
newWidth++;
48824882
}
4883-
newWidth += INSET * 2 + VISTA_EXTRA;
4883+
newWidth += Win32DPIUtils.pointToPixel(INSET * 2, getZoom()) + VISTA_EXTRA;
48844884
int oldWidth = (int)OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
48854885
if (newWidth > oldWidth) {
48864886
setScrollWidth (newWidth);
@@ -6962,7 +6962,7 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) {
69626962
}
69636963
}
69646964

6965-
int x = rects[i].left + INSET + 2;
6965+
int x = rects[i].left + Win32DPIUtils.pointToPixel(INSET + 2, getZoom());
69666966
if (columns[i].image != null) {
69676967
GCData data = new GCData();
69686968
data.device = display;
@@ -7303,9 +7303,9 @@ LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, long lParam) {
73037303
int zoom = getZoom();
73047304
rect = Win32DPIUtils.pixelToPoint(rect, zoom);
73057305
gc.drawImage (image, rect.x, rect.y, rect.width, rect.height, DPIUtil.pixelToPoint(x, zoom), DPIUtil.pixelToPoint(y, zoom), DPIUtil.pixelToPoint(size.x, zoom), DPIUtil.pixelToPoint(size.y, zoom));
7306-
x += size.x + INSET + (pinfo.iSubItem == 0 ? -2 : 4);
7306+
x += size.x + Win32DPIUtils.pointToPixel(INSET + (pinfo.iSubItem == 0 ? -2 : 4), zoom);
73077307
} else {
7308-
x += INSET + 2;
7308+
x += Win32DPIUtils.pointToPixel(INSET + 2, getZoom());
73097309
}
73107310
String string = item.getText (pinfo.iSubItem);
73117311
if (string != null) {

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ RECT getBounds (int row, int column, boolean getText, boolean getImage, boolean
300300
}
301301
}
302302
if (!getImage) rect.left = rect.right;
303-
rect.right += width + Table.INSET * 2;
303+
rect.right += width + Win32DPIUtils.pointToPixel(Table.INSET * 2, getZoom());
304304
}
305305
} else {
306306
if (getText) {
@@ -377,7 +377,7 @@ RECT getBounds (int row, int column, boolean getText, boolean getImage, boolean
377377
iconRect.top = column;
378378
iconRect.left = OS.LVIR_ICON;
379379
if (OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, row, iconRect) != 0) {
380-
rect.left = iconRect.right + Table.INSET / 2;
380+
rect.left = iconRect.right + Win32DPIUtils.pointToPixel(Table.INSET / 2, getZoom());
381381
}
382382
}
383383
} else {
@@ -404,7 +404,7 @@ RECT getBounds (int row, int column, boolean getText, boolean getImage, boolean
404404
char [] buffer = string.toCharArray ();
405405
int flags = OS.DT_NOPREFIX | OS.DT_SINGLELINE | OS.DT_CALCRECT;
406406
OS.DrawText (hDC, buffer, buffer.length, textRect, flags);
407-
rect.right += textRect.right - textRect.left + Table.INSET * 3 + 2;
407+
rect.right += textRect.right - textRect.left + Win32DPIUtils.pointToPixel(Table.INSET * 3 + 2, getZoom());
408408
}
409409
}
410410
}
@@ -700,9 +700,9 @@ Rectangle getTextBoundsInPixels (int index) {
700700
if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
701701
RECT rect = getBounds (itemIndex, index, true, false, true);
702702
rect.left += 2;
703-
if (index != 0) rect.left += Table.INSET;
703+
if (index != 0) rect.left += Win32DPIUtils.pointToPixel(Table.INSET, getZoom());
704704
rect.left = Math.min (rect.left, rect.right);
705-
rect.right = rect.right - Table.INSET;
705+
rect.right = rect.right - Win32DPIUtils.pointToPixel(Table.INSET, getZoom());
706706
int width = Math.max (0, rect.right - rect.left);
707707
int height = Math.max (0, rect.bottom - rect.top);
708708
return new Rectangle (rect.left, rect.top, width, height);

0 commit comments

Comments
 (0)