Skip to content

Commit 92aa308

Browse files
committed
Improve CTabFolder highlight appearance on higher zooms
The highlight of CTabFolders implemented in CTabRendering does not properly deal with higher zooms on Windows. The outline of the tabs is drawn with a width of one pixel whereas the highlight has an offset of one point, producing a gap at higher zooms. In addition, the highlight for rounded tabs exceeds the intended bounds. This change adapts the rendering as follows: - When the highlight is drawn rounded at the top, the shape of the outline is taken and adapted to the intended highlight height to draw the highlight. - In all other cases the highlight is drawn as a simple line of according width with an offset of half the line width with respect to its bounds. To compensate for the 1px border that is drawn on top of the highlight when it is placed at the top of a tab, another line of according size is drawn next to the highlight to make its height fit again.
1 parent e81ba1c commit 92aa308

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

  • bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.eclipse.e4.ui.workbench.renderers.swt;
1919

2020
import java.lang.reflect.Field;
21+
import java.util.Arrays;
2122
import java.util.Objects;
2223
import org.eclipse.core.runtime.Platform;
2324
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
@@ -621,17 +622,41 @@ void drawSelectedTab(int itemIndex, GC gc, Rectangle bounds) {
621622
}
622623

623624
if (selectedTabHighlightColor != null) {
625+
gc.setForeground(selectedTabHighlightColor);
624626
gc.setBackground(selectedTabHighlightColor);
625-
boolean highlightOnTop = drawTabHighlightOnTop;
626-
if (onBottom) {
627-
highlightOnTop = !highlightOnTop;
628-
}
629627
int highlightHeight = 2;
630-
int verticalOffset = highlightOnTop ? 0 : bounds.height - (highlightHeight - 1);
631-
int horizontalOffset = itemIndex == 0 || cornerSize == SQUARE_CORNER ? 0 : 1;
632-
int widthAdjustment = cornerSize == SQUARE_CORNER ? 0 : 1;
633-
gc.fillRectangle(bounds.x + horizontalOffset, bounds.y + verticalOffset, bounds.width - widthAdjustment,
634-
highlightHeight);
628+
int originalLineWidth = gc.getLineWidth();
629+
if (drawTabHighlightOnTop && cornerSize != SQUARE_CORNER) {
630+
// When using round tabs, extract the part of the outline that covers the
631+
// highlight and draw it with adapted height
632+
int[] highlightShape = Arrays.copyOfRange(tabOutlinePoints, 14, tabOutlinePoints.length - 14);
633+
int yEnd = onBottom ? outlineBoundsForOutline.y + outlineBoundsForOutline.height - highlightHeight + 1
634+
: highlightHeight;
635+
highlightShape[1] = highlightShape[highlightShape.length - 1] = yEnd;
636+
boolean gcAdvanced = gc.getAdvanced();
637+
gc.setAdvanced(false);
638+
gc.fillPolygon(highlightShape);
639+
gc.setAdvanced(gcAdvanced);
640+
} else {
641+
// When using square tab or drawing the highlight at the bottom, simply draw
642+
// a line
643+
int xStart = tabOutlinePoints[2];
644+
int xEnd = tabOutlinePoints[tabOutlinePoints.length - 4];
645+
int yTop = drawTabHighlightOnTop ? tabOutlinePoints[5] : tabOutlinePoints[3];
646+
if (onBottom == drawTabHighlightOnTop) {
647+
yTop -= highlightHeight;
648+
}
649+
gc.setLineWidth(highlightHeight);
650+
gc.drawLine(xStart, yTop + highlightHeight / 2, xEnd, yTop + highlightHeight / 2);
651+
if (drawTabHighlightOnTop) {
652+
// Compensate for the outline being draw on top of the filled region by
653+
// extending the highlight with an equally wide line next to the filled region
654+
gc.setLineWidth(0);
655+
int yAdditionalLine = onBottom ? yTop : yTop + highlightHeight;
656+
gc.drawLine(xStart, yAdditionalLine, xEnd, yAdditionalLine);
657+
}
658+
}
659+
gc.setLineWidth(originalLineWidth);
635660
}
636661

637662
if (backgroundPattern != null) {

0 commit comments

Comments
 (0)