Skip to content

Commit d02437c

Browse files
Adjust selection bounds for CTabRenderring
Selected tabs highlight look slightly off and more noticeable when zoom is not 100%. These adjusted value shows no gaps from top and better aligned highlights for tabs (Theme is enabled)
1 parent 34049dd commit d02437c

1 file changed

Lines changed: 33 additions & 7 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: 33 additions & 7 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;
@@ -619,19 +620,44 @@ void drawSelectedTab(int itemIndex, GC gc, Rectangle bounds) {
619620
} else if (!onBottom) {
620621
gc.drawLine(startX, 0, endX, 0);
621622
}
622-
623+
onBottom = true;
623624
if (selectedTabHighlightColor != null) {
625+
gc.setForeground(selectedTabHighlightColor);
624626
gc.setBackground(selectedTabHighlightColor);
627+
int originalLineWidth = gc.getLineWidth();
628+
int highlightHeight = 2;
625629
boolean highlightOnTop = drawTabHighlightOnTop;
626630
if (onBottom) {
627631
highlightOnTop = !highlightOnTop;
628632
}
629-
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);
633+
634+
if (highlightOnTop && cornerSize != SQUARE_CORNER) {
635+
// When using round tabs, extract the part of the outline that covers the
636+
// highlight and draw it with adapted height
637+
int[] highlightShape = Arrays.copyOfRange(tabOutlinePoints, 12, tabOutlinePoints.length - 12);
638+
int yEnd = !highlightOnTop
639+
? outlineBoundsForOutline.y + outlineBoundsForOutline.height - highlightHeight + 1
640+
: highlightHeight;
641+
highlightShape[1] = highlightShape[highlightShape.length - 1] = yEnd;
642+
boolean gcAdvanced = gc.getAdvanced();
643+
gc.setAdvanced(false);
644+
gc.fillPolygon(highlightShape);
645+
gc.setAdvanced(gcAdvanced);
646+
} else {
647+
// When using square tab or drawing the highlight at the bottom, simply draw a
648+
// line
649+
int highlightY = highlightOnTop ? outlineBoundsForOutline.y
650+
: bounds.y + bounds.height - highlightHeight + 1;
651+
gc.fillRectangle(outlineBoundsForOutline.x, highlightY, outlineBoundsForOutline.width, highlightHeight);
652+
if (highlightOnTop) {
653+
// Compensate for the outline being draw on top of the filled region by
654+
// extending the highlight with an equally wide line next to the filled region
655+
gc.setLineWidth(1);
656+
gc.drawLine(outlineBoundsForOutline.x, highlightY + highlightHeight,
657+
outlineBoundsForOutline.x + outlineBoundsForOutline.width, highlightY + highlightHeight);
658+
}
659+
}
660+
gc.setLineWidth(originalLineWidth);
635661
}
636662

637663
if (backgroundPattern != null) {

0 commit comments

Comments
 (0)