Skip to content

Commit 21c32b7

Browse files
vogellaclaude
authored andcommitted
Fix dirty indicator pixel offset, add theme-switching snippet, fix test EOF
- Remove spurious y+1/-1 offset in drawDirtyIndicator; the oval is already centered from closeRect bounds, unlike the X drawing which needs the nudge due to its Math.max(1,...) coordinate logic - Extend Snippet393 with a dark/light theme toggle button to demonstrate that the dirty bullet color adapts to the tab foreground color - Add missing newline at end of Test_org_eclipse_swt_custom_CTabItem.java Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 05a1bfb commit 21c32b7

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,6 @@ private void drawDirtyIndicator(GC gc, Rectangle closeRect) {
938938
int diameter = 8;
939939
int x = closeRect.x + (closeRect.width - diameter) / 2;
940940
int y = closeRect.y + (closeRect.height - diameter) / 2;
941-
y += parent.onBottom ? -1 : 1;
942941
Color originalBackground = gc.getBackground();
943942
gc.setBackground(gc.getForeground());
944943
gc.fillOval(x, y, diameter, diameter);

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet393.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
package org.eclipse.swt.snippets;
1212

1313
/*
14-
* CTabFolder example: dirty indicator using bullet dot on close button
14+
* CTabFolder example: dirty indicator using bullet dot on close button,
15+
* with runtime dark/light theme switching to show color adaptation.
1516
*
1617
* For a list of all SWT example snippets see
1718
* http://www.eclipse.org/swt/snippets/
1819
*/
1920
import org.eclipse.swt.*;
2021
import org.eclipse.swt.custom.*;
22+
import org.eclipse.swt.graphics.*;
2123
import org.eclipse.swt.layout.*;
2224
import org.eclipse.swt.widgets.*;
2325

@@ -55,6 +57,45 @@ public static void main(String[] args) {
5557
}
5658
});
5759

60+
boolean[] isDark = {false};
61+
Button toggleThemeButton = new Button(shell, SWT.PUSH);
62+
toggleThemeButton.setText("Switch to Dark Theme");
63+
toggleThemeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
64+
toggleThemeButton.addListener(SWT.Selection, e -> {
65+
isDark[0] = !isDark[0];
66+
if (isDark[0]) {
67+
Color tabBg = new Color(display, 43, 43, 43);
68+
Color selBg = new Color(display, 60, 63, 65);
69+
Color contentBg = new Color(display, 30, 30, 30);
70+
Color fg = new Color(display, 187, 187, 187);
71+
folder.setBackground(tabBg);
72+
folder.setForeground(fg);
73+
folder.setSelectionBackground(selBg);
74+
folder.setSelectionForeground(fg);
75+
for (int i = 0; i < folder.getItemCount(); i++) {
76+
Control ctrl = folder.getItem(i).getControl();
77+
if (ctrl != null) {
78+
ctrl.setBackground(contentBg);
79+
ctrl.setForeground(fg);
80+
}
81+
}
82+
toggleThemeButton.setText("Switch to Light Theme");
83+
} else {
84+
folder.setBackground(null);
85+
folder.setForeground(null);
86+
folder.setSelectionBackground((Color) null);
87+
folder.setSelectionForeground(null);
88+
for (int i = 0; i < folder.getItemCount(); i++) {
89+
Control ctrl = folder.getItem(i).getControl();
90+
if (ctrl != null) {
91+
ctrl.setBackground(null);
92+
ctrl.setForeground(null);
93+
}
94+
}
95+
toggleThemeButton.setText("Switch to Dark Theme");
96+
}
97+
});
98+
5899
shell.setSize(400, 300);
59100
shell.open();
60101
while (!shell.isDisposed()) {

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ public void test_dirtyIndicatorCloseStyle() {
9696
cTabFolder.setDirtyIndicatorCloseStyle(false);
9797
assertFalse(cTabFolder.getDirtyIndicatorCloseStyle());
9898
}
99-
}
99+
}

0 commit comments

Comments
 (0)