Skip to content

Commit

Permalink
Allow light/dark font to be dynamically used
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
AObuchow committed Sep 10, 2020
1 parent e7c10b9 commit 8c060fe
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void updateColors() {
backgroundColor = colorRegistry.get(BACKGROUND_COLOR_ID);
if (engine.getActiveTheme().getId().equals(THEME_ID)) {
updateGitColors();
updateThemeFontColors();
savePreferences();
}
}
Expand Down Expand Up @@ -137,7 +138,23 @@ private void updateGitColors() {
setColorPreference("org.eclipse.egit.ui.UncommittedChangeForegroundColor", uncommittedChangeForeground);
setColorPreference("org.eclipse.egit.ui.UncommittedChangeBackgroundColor",
uncommittedChangeBackground.getColor());
uncommittedChangeBackground.dispose();
});
}

private void updateThemeFontColors() {
display.asyncExec(() -> {
Color primaryFontColor = ColorUtils.useReadableForegroundColor(
backgroundColor, display.getSystemColor(SWT.COLOR_WHITE),
display.getSystemColor(SWT.COLOR_BLACK));
Color activeFontColor = ColorUtils.useReadableForegroundColor(
accentColor, display.getSystemColor(SWT.COLOR_WHITE),
display.getSystemColor(SWT.COLOR_BLACK));
Color inactiveFontColor = ColorUtils.useReadableForegroundColor(
baseColor, display.getSystemColor(SWT.COLOR_WHITE),
display.getSystemColor(SWT.COLOR_BLACK));
setColorPreference("com.aobuchow.themes.spectrum.PRIMARY_FONT_COLOR", primaryFontColor);
setColorPreference("com.aobuchow.themes.spectrum.ACTIVE_FONT_COLOR", activeFontColor);
setColorPreference("com.aobuchow.themes.spectrum.INACTIVE_FONT_COLOR", inactiveFontColor);
});
}

Expand Down
7 changes: 0 additions & 7 deletions com.aobuchow.themes.spectrum/css/color_definitions.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,9 @@

ThemesExtension {
color-definition:
'#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR',
'#org-eclipse-ui-workbench-LINK_COLOR';
}

ColorDefinition#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR {
color: white;
category: '#org-eclipse-ui-presentation-default';
label: url('platform:/plugin/org.eclipse.ui.themes?message=ACTIVE_TAB_SELECTED_TEXT_COLOR');
}

ColorDefinition#org-eclipse-ui-workbench-LINK_COLOR {
color: #28ebc3;
category: '#org-eclipse-ui-presentation-default';
Expand Down
26 changes: 13 additions & 13 deletions com.aobuchow.themes.spectrum/css/default_overrides.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

Tree,
Table {
color: white;
swt-header-color: white;
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
swt-header-color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
swt-header-background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR';
swt-selection-background-color: '#com-aobuchow-themes-spectrum-ACCENT_COLOR';
swt-selection-foreground-color: black;
Expand All @@ -41,11 +41,11 @@ Composite#org-eclipse-ui-navigator-ProjectExplorer * {

.MPartStack.active Table {
background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR';
color: #ccc;
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
}
.View {
background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR';
color: #f5f5f5;
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
}

/* ###################### Hyperlink ########################## */
Expand Down Expand Up @@ -77,7 +77,7 @@ Composite#org-eclipse-ui-navigator-ProjectExplorer * {
/* Color in between text editors */
.MPartSashContainer {
background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR';
color: #eeeeee;
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
}

/* ###################### Form Editors ########################## */
Expand Down Expand Up @@ -176,7 +176,7 @@ Section {

.MPart Section > Label {
background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR';
color: white;
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
}

ExpandableComposite {
Expand Down Expand Up @@ -204,7 +204,7 @@ Shell > Composite > Composite > Composite > Composite > Composite > List,
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,
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 {
background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR'; /* TODO: This should be SECONDARY_COLOR_DULL */
color: white;
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
}

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

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

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

Shell,
Expand Down Expand Up @@ -302,15 +302,15 @@ Composite > *,
Composite > * > *,
Group > StyledText {
background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR';
color: #eeeeee;
color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR';
}

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

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

/* Toolbar should inherit the colors of its container to avoid drawing artifacts*/
Expand Down
12 changes: 6 additions & 6 deletions com.aobuchow.themes.spectrum/css/tabstyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ CTabFolder[style~='SWT.DOWN'][style~='SWT.BOTTOM'] {
.MPartStack.active > CTabItem,
.MPartStack.active > CTabItem CLabel {
background-color: '#com-aobuchow-themes-spectrum-ACCENT_COLOR'; /* HACK for background of CTabFolder inner Toolbars */
color: '#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR';
color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR';
}

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

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

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

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

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

.MPartStack.active.noFocus > CTabItem:selected {
color: white;
color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR';
}
18 changes: 18 additions & 0 deletions com.aobuchow.themes.spectrum/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@
The color used when an hovering on a tab in Spectrum theme.
</description>
</colorDefinition>
<colorDefinition
id="com.aobuchow.themes.spectrum.PRIMARY_FONT_COLOR"
isEditable="false"
label="Primary Font Color"
value="255,255,255">
</colorDefinition>
<colorDefinition
id="com.aobuchow.themes.spectrum.ACTIVE_FONT_COLOR"
isEditable="false"
label="Active Font Color"
value="255,255,255">
</colorDefinition>
<colorDefinition
id="com.aobuchow.themes.spectrum.INACTIVE_FONT_COLOR"
isEditable="false"
label="Inactive Font Color"
value="255,255,255">
</colorDefinition>
</extension>

</plugin>

0 comments on commit 8c060fe

Please sign in to comment.