|
|
Re: Conditional Style Based on Theme - Light vs Dark Mode [message #1850361 is a reply to message #1850360] |
Sat, 26 February 2022 20:57 |
Brandon Lewis Messages: 268 Registered: May 2012 |
Senior Member |
|
|
There's probably a more clever way, but this sort of works. Suffers from users having to re-start Eclipse, but it seems like Dark/Light modes really require that anyway.
Key concept is declaring a Computed Color in your odesign files.
Then I put these methods in my Services so I could grab information from the Theme about coloring and calculate RGB on the fly.
It was not easy to find a key string in the ColorRegistry that worked, but you can inspect the keys (left in commented code)
An obvious key of ""org.eclipse.ui.editors.foregroundColor" did not work - frustratingly. Even after restarting Eclipse. Not sure why - all the editors clearly have a way of toggling their colors.
Getting the current theme did not work well. currentTheme.getId() seems like it would obviously say something like "Dark" or "Light" but instead it said something useless for this - it said "default" no matter what Dark/Light was set to.
public class Services {
Color labelColor = null;
<snip>
public int getRedForLabelColor(EObject self) {
return getForegroundColor().getRed();
}
public int getGreenForLabelColor(EObject self) {
return getForegroundColor().getGreen();
}
public int getBlueForLabelColor(EObject self) {
return getForegroundColor().getBlue();
}
public Color getForegroundColor() {
if (labelColor == null) {
ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
//currentTheme.getColorRegistry().getKeySet(); // for debugging what string keys we have available
labelColor = currentTheme.getColorRegistry().get("org.eclipse.ui.workbench.HOVER_FOREGROUND");
}
return labelColor;
}
[Updated on: Sat, 26 February 2022 21:00] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03635 seconds