Skip to content

Commit 8c060fe

Browse files
committed
Allow light/dark font to be dynamically used
based on user selected theme colors More CSS refactoring is required for certain edge cases such as tables Fix #46 Signed-off-by: andrew obuchowicz <[email protected]>
1 parent e7c10b9 commit 8c060fe

File tree

5 files changed

+55
-27
lines changed

5 files changed

+55
-27
lines changed

com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public void updateColors() {
5252
backgroundColor = colorRegistry.get(BACKGROUND_COLOR_ID);
5353
if (engine.getActiveTheme().getId().equals(THEME_ID)) {
5454
updateGitColors();
55+
updateThemeFontColors();
5556
savePreferences();
5657
}
5758
}
@@ -137,7 +138,23 @@ private void updateGitColors() {
137138
setColorPreference("org.eclipse.egit.ui.UncommittedChangeForegroundColor", uncommittedChangeForeground);
138139
setColorPreference("org.eclipse.egit.ui.UncommittedChangeBackgroundColor",
139140
uncommittedChangeBackground.getColor());
140-
uncommittedChangeBackground.dispose();
141+
});
142+
}
143+
144+
private void updateThemeFontColors() {
145+
display.asyncExec(() -> {
146+
Color primaryFontColor = ColorUtils.useReadableForegroundColor(
147+
backgroundColor, display.getSystemColor(SWT.COLOR_WHITE),
148+
display.getSystemColor(SWT.COLOR_BLACK));
149+
Color activeFontColor = ColorUtils.useReadableForegroundColor(
150+
accentColor, display.getSystemColor(SWT.COLOR_WHITE),
151+
display.getSystemColor(SWT.COLOR_BLACK));
152+
Color inactiveFontColor = ColorUtils.useReadableForegroundColor(
153+
baseColor, display.getSystemColor(SWT.COLOR_WHITE),
154+
display.getSystemColor(SWT.COLOR_BLACK));
155+
setColorPreference("com.aobuchow.themes.spectrum.PRIMARY_FONT_COLOR", primaryFontColor);
156+
setColorPreference("com.aobuchow.themes.spectrum.ACTIVE_FONT_COLOR", activeFontColor);
157+
setColorPreference("com.aobuchow.themes.spectrum.INACTIVE_FONT_COLOR", inactiveFontColor);
141158
});
142159
}
143160

com.aobuchow.themes.spectrum/css/color_definitions.css

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,9 @@
1212

1313
ThemesExtension {
1414
color-definition:
15-
'#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR',
1615
'#org-eclipse-ui-workbench-LINK_COLOR';
1716
}
1817

19-
ColorDefinition#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR {
20-
color: white;
21-
category: '#org-eclipse-ui-presentation-default';
22-
label: url('platform:/plugin/org.eclipse.ui.themes?message=ACTIVE_TAB_SELECTED_TEXT_COLOR');
23-
}
24-
2518
ColorDefinition#org-eclipse-ui-workbench-LINK_COLOR {
2619
color: #28ebc3;
2720
category: '#org-eclipse-ui-presentation-default';

com.aobuchow.themes.spectrum/css/default_overrides.css

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
Tree,
2121
Table {
22-
color: white;
23-
swt-header-color: white;
22+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
23+
swt-header-color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
2424
swt-header-background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR';
2525
swt-selection-background-color: '#com-aobuchow-themes-spectrum-ACCENT_COLOR';
2626
swt-selection-foreground-color: black;
@@ -41,11 +41,11 @@ Composite#org-eclipse-ui-navigator-ProjectExplorer * {
4141

4242
.MPartStack.active Table {
4343
background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR';
44-
color: #ccc;
44+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
4545
}
4646
.View {
4747
background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR';
48-
color: #f5f5f5;
48+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
4949
}
5050

5151
/* ###################### Hyperlink ########################## */
@@ -77,7 +77,7 @@ Composite#org-eclipse-ui-navigator-ProjectExplorer * {
7777
/* Color in between text editors */
7878
.MPartSashContainer {
7979
background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR';
80-
color: #eeeeee;
80+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
8181
}
8282

8383
/* ###################### Form Editors ########################## */
@@ -176,7 +176,7 @@ Section {
176176

177177
.MPart Section > Label {
178178
background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR';
179-
color: white;
179+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
180180
}
181181

182182
ExpandableComposite {
@@ -204,7 +204,7 @@ Shell > Composite > Composite > Composite > Composite > Composite > List,
204204
Shell[style~='SWT.RADIO'][style~='SWT.CASCADE'][style~='SWT.SHADOW_ETCHED_IN'][style~='SWT.SHADOW_ETCHED_OUT'][style~='SWT.RESIZE'][style~='SWT.MENU'][style~='SWT.FULL_SELECTION'][style~='SWT.DATE'] > Composite > List,
205205
Shell[style~='SWT.RADIO'][style~='SWT.CASCADE'][style~='SWT.SHADOW_ETCHED_IN'][style~='SWT.SHADOW_ETCHED_OUT'][style~='SWT.RESIZE'][style~='SWT.MENU'][style~='SWT.FULL_SELECTION'][style~='SWT.DATE'] > Composite > * > List {
206206
background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR'; /* TODO: This should be SECONDARY_COLOR_DULL */
207-
color: white;
207+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
208208
}
209209

210210
#org-eclipse-ui-main-toolbar,
@@ -213,7 +213,7 @@ Shell[style~='SWT.RADIO'][style~='SWT.CASCADE'][style~='SWT.SHADOW_ETCHED_IN'][s
213213
background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR'
214214
'#com-aobuchow-themes-spectrum-BACKGROUND_COLOR' 100%;
215215
handle-image: none;
216-
color: #ebe8e4;
216+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
217217
}
218218

219219
/* ############################## Console View ############################## */
@@ -222,7 +222,7 @@ Shell[style~='SWT.RADIO'][style~='SWT.CASCADE'][style~='SWT.SHADOW_ETCHED_IN'][s
222222
#org-eclipse-ui-console-ConsoleView .MPart StyledText,
223223
#org-eclipse-ui-console-ConsoleView .MPart PageBook Label {
224224
background-color: black;
225-
color: white;
225+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
226226
}
227227

228228
/* ############################## Global Styles ############################## */
@@ -254,7 +254,7 @@ Shell[style~='SWT.RADIO'][style~='SWT.CASCADE'][style~='SWT.SHADOW_ETCHED_IN'][s
254254
.MPart DependenciesComposite > SashForm > Section > * {
255255
/* Section > DependenciesComposite$... */
256256
background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR';
257-
color: #eeeeee;
257+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
258258
}
259259

260260
Shell,
@@ -302,15 +302,15 @@ Composite > *,
302302
Composite > * > *,
303303
Group > StyledText {
304304
background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR';
305-
color: #eeeeee;
305+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
306306
}
307307

308308
Composite > StyledText,
309309
Shell [style~='SWT.DROP_DOWN'] > StyledText, /* for eg. folded code popup (but it's ignored) */
310310
SashForm > StyledText {
311311
/* Fix StyledText inside a SashForm */
312312
background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR';
313-
color: #eeeeee;
313+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
314314
}
315315

316316
.MPart Table,
@@ -321,7 +321,7 @@ SashForm > StyledText {
321321
.MPart PageBook > Label,
322322
.MPart PageBook > SashForm {
323323
background-color: #161616; /* hard coded since color definitions dont seem to work here? */
324-
color: #ccc;
324+
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
325325
}
326326

327327
/* Toolbar should inherit the colors of its container to avoid drawing artifacts*/

com.aobuchow.themes.spectrum/css/tabstyle.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ CTabFolder[style~='SWT.DOWN'][style~='SWT.BOTTOM'] {
6060
.MPartStack.active > CTabItem,
6161
.MPartStack.active > CTabItem CLabel {
6262
background-color: '#com-aobuchow-themes-spectrum-ACCENT_COLOR'; /* HACK for background of CTabFolder inner Toolbars */
63-
color: '#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR';
63+
color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR';
6464
}
6565

6666
.MPartStack.active > CTabItem:selected,
6767
.MPartStack.active > CTabItem:selected CLabel {
68-
color: '#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR';
68+
color: '#com-aobuchow-themes-spectrum-ACTIVE_FONT_COLOR';
6969
}
7070

7171
CTabFolder > Composite#ToolbarComposite {
@@ -88,23 +88,23 @@ CTabFolder Scale {
8888
CTabItem,
8989
CTabItem CLabel {
9090
background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR'; /* HACK for background of CTabFolder inner Toolbars */
91-
color: '#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR';
91+
color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR';
9292
}
9393

9494
/* ###################### Below used to be in default overrides ########################## */
9595

9696
/* TODO: Maybe inactive tabs should have a darker color? */
9797
CTabItem:selected,
9898
CTabItem:selected CLabel {
99-
color: white;
99+
color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR';
100100
}
101101

102102
.MPartStack.active > CTabItem,
103103
.MPartStack.active > CTabItem CLabel {
104104
/* background-color: '#com-aobuchow-themes-spectrum-ACCENT_COLOR'; HACK for background of CTabFolder inner Toolbars */
105-
color: white;
105+
color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR';
106106
}
107107

108108
.MPartStack.active.noFocus > CTabItem:selected {
109-
color: white;
109+
color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR';
110110
}

com.aobuchow.themes.spectrum/plugin.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@
6767
The color used when an hovering on a tab in Spectrum theme.
6868
</description>
6969
</colorDefinition>
70+
<colorDefinition
71+
id="com.aobuchow.themes.spectrum.PRIMARY_FONT_COLOR"
72+
isEditable="false"
73+
label="Primary Font Color"
74+
value="255,255,255">
75+
</colorDefinition>
76+
<colorDefinition
77+
id="com.aobuchow.themes.spectrum.ACTIVE_FONT_COLOR"
78+
isEditable="false"
79+
label="Active Font Color"
80+
value="255,255,255">
81+
</colorDefinition>
82+
<colorDefinition
83+
id="com.aobuchow.themes.spectrum.INACTIVE_FONT_COLOR"
84+
isEditable="false"
85+
label="Inactive Font Color"
86+
value="255,255,255">
87+
</colorDefinition>
7088
</extension>
7189

7290
</plugin>

0 commit comments

Comments
 (0)