Skip to content

Commit

Permalink
Calculate chevron size in CTabFolderRenderer without Device#getDPI()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ShahzaibIbrahim authored and HeikoKlare committed Jan 25, 2025
1 parent 88d5b53 commit 6d374d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ void init(int style) {
case SWT.Selection: onSelection(event); break;
case SWT.Activate: onActivate(event); break;
case SWT.Deactivate: onDeactivate(event); break;
case SWT.ZoomChanged: onZoomChange(event); break;
}
};

Expand All @@ -362,14 +363,20 @@ void init(int style) {
SWT.Resize,
SWT.Traverse,
SWT.Activate,
SWT.Deactivate
SWT.Deactivate,
SWT.ZoomChanged
};
for (int folderEvent : folderEvents) {
addListener(folderEvent, listener);
}

initAccessible();
}

private void onZoomChange(Event event) {
update();
}

void onDeactivate(Event event) {
if (!highlightEnabled) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public class CTabFolderRenderer {
static final int FLAGS = SWT.DRAW_TRANSPARENT | SWT.DRAW_MNEMONIC | SWT.DRAW_DELIMITER;
static final String ELLIPSIS = "..."; //$NON-NLS-1$
private static final String CHEVRON_ELLIPSIS = "99+"; //$NON-NLS-1$
private static final int CHEVRON_FONT_HEIGHT = 10;
private static final float CHEVRON_FONT_SIZE_FACTOR = 0.7f;
private static final int CHEVRON_BOTTOM_INDENT = 4;

//Part constants
/**
Expand Down Expand Up @@ -926,7 +927,7 @@ void drawChevron(GC gc, Rectangle chevronRect, int chevronImageState) {
Display display = parent.getDisplay();
Font font = getChevronFont(display);
int fontHeight = font.getFontData()[0].getHeight();
int indent = Math.max(2, (chevronRect.height - fontHeight - 4) /2);
int indent = Math.max(2, (chevronRect.height - fontHeight - CHEVRON_BOTTOM_INDENT) /2);
int x = chevronRect.x + 2;
int y = chevronRect.y + indent;
int count = parent.getChevronCount();
Expand Down Expand Up @@ -1696,9 +1697,8 @@ Color getFillColor() {

private Font getChevronFont(Display display) {
if (chevronFont == null) {
Point dpi = display.getDPI();
int fontHeight = 72 * CHEVRON_FONT_HEIGHT / dpi.y;
FontData fd = parent.getFont().getFontData()[0];
int fontHeight = (int) (fd.height * CHEVRON_FONT_SIZE_FACTOR);
fd.setHeight(fontHeight);
chevronFont = new Font(display, fd);
}
Expand Down

0 comments on commit 6d374d9

Please sign in to comment.