Skip to content

Commit 6d374d9

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
Calculate chevron size in CTabFolderRenderer without Device#getDPI()
The chevron font size is currently determined using Device#getDPI(). This value is static across the application lifecyle, always returns the DPI for the primary monitor at application startup. The font does thus not adapt properly to other zoom values. This change replaces the logic to calculate the chevron font size to use a scaled version of the font used for CTabItem. It also adds a listener for the zoom change event to trigger redraw.
1 parent 88d5b53 commit 6d374d9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ void init(int style) {
341341
case SWT.Selection: onSelection(event); break;
342342
case SWT.Activate: onActivate(event); break;
343343
case SWT.Deactivate: onDeactivate(event); break;
344+
case SWT.ZoomChanged: onZoomChange(event); break;
344345
}
345346
};
346347

@@ -362,14 +363,20 @@ void init(int style) {
362363
SWT.Resize,
363364
SWT.Traverse,
364365
SWT.Activate,
365-
SWT.Deactivate
366+
SWT.Deactivate,
367+
SWT.ZoomChanged
366368
};
367369
for (int folderEvent : folderEvents) {
368370
addListener(folderEvent, listener);
369371
}
370372

371373
initAccessible();
372374
}
375+
376+
private void onZoomChange(Event event) {
377+
update();
378+
}
379+
373380
void onDeactivate(Event event) {
374381
if (!highlightEnabled) {
375382
return;

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderRenderer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public class CTabFolderRenderer {
102102
static final int FLAGS = SWT.DRAW_TRANSPARENT | SWT.DRAW_MNEMONIC | SWT.DRAW_DELIMITER;
103103
static final String ELLIPSIS = "..."; //$NON-NLS-1$
104104
private static final String CHEVRON_ELLIPSIS = "99+"; //$NON-NLS-1$
105-
private static final int CHEVRON_FONT_HEIGHT = 10;
105+
private static final float CHEVRON_FONT_SIZE_FACTOR = 0.7f;
106+
private static final int CHEVRON_BOTTOM_INDENT = 4;
106107

107108
//Part constants
108109
/**
@@ -926,7 +927,7 @@ void drawChevron(GC gc, Rectangle chevronRect, int chevronImageState) {
926927
Display display = parent.getDisplay();
927928
Font font = getChevronFont(display);
928929
int fontHeight = font.getFontData()[0].getHeight();
929-
int indent = Math.max(2, (chevronRect.height - fontHeight - 4) /2);
930+
int indent = Math.max(2, (chevronRect.height - fontHeight - CHEVRON_BOTTOM_INDENT) /2);
930931
int x = chevronRect.x + 2;
931932
int y = chevronRect.y + indent;
932933
int count = parent.getChevronCount();
@@ -1696,9 +1697,8 @@ Color getFillColor() {
16961697

16971698
private Font getChevronFont(Display display) {
16981699
if (chevronFont == null) {
1699-
Point dpi = display.getDPI();
1700-
int fontHeight = 72 * CHEVRON_FONT_HEIGHT / dpi.y;
17011700
FontData fd = parent.getFont().getFontData()[0];
1701+
int fontHeight = (int) (fd.height * CHEVRON_FONT_SIZE_FACTOR);
17021702
fd.setHeight(fontHeight);
17031703
chevronFont = new Font(display, fd);
17041704
}

0 commit comments

Comments
 (0)