Skip to content

Commit 40a49e0

Browse files
Getting rid of getDPI to calculate chevron size
getDPI always returns the points for primary monitor and can produce faulty behavior. Replacing the logic to calculate the chevron font size. Visibly 70% size of the font used for CTabItem is now used. Also adjusting the indent and adding the ZoomChange event to trigger redraw during DPI change
1 parent 60ef7e9 commit 40a49e0

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

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

Lines changed: 8 additions & 1 deletion
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+
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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,8 @@ void drawChevron(GC gc, Rectangle chevronRect, int chevronImageState) {
926926
Display display = parent.getDisplay();
927927
Font font = getChevronFont(display);
928928
int fontHeight = font.getFontData()[0].getHeight();
929-
int indent = Math.max(2, (chevronRect.height - fontHeight - 4) /2);
929+
int indent = Math.max(2, (chevronRect.height - fontHeight - 8) /2);
930+
System.out.println("chevronRect.height - fontHeight " + chevronRect.height + " . " + fontHeight);
930931
int x = chevronRect.x + 2;
931932
int y = chevronRect.y + indent;
932933
int count = parent.getChevronCount();
@@ -1696,11 +1697,12 @@ 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;
1701-
FontData fd = parent.getFont().getFontData()[0];
1702-
fd.setHeight(fontHeight);
1703-
chevronFont = new Font(display, fd);
1700+
if (chevronFont == null) {
1701+
FontData fd = parent.getFont().getFontData()[0];
1702+
int fontHeight = (int) (parent.getFont().getFontData()[0].height * 0.7);
1703+
fd.setHeight(fontHeight);
1704+
chevronFont = new Font(display, fd);
1705+
}
17041706
}
17051707
return chevronFont;
17061708
}

0 commit comments

Comments
 (0)