Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Conditional Style Based on Theme - Light vs Dark Mode
Conditional Style Based on Theme - Light vs Dark Mode [message #1850338] Fri, 25 February 2022 13:42 Go to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
How can I alter the color of my diagram labels based on if the user is in light or dark mode?

I can choose colors for drawn objects that are compatible with both modes, but labels are invisible if they are external to a drawn object.
Re: Conditional Style Based on Theme - Light vs Dark Mode [message #1850360 is a reply to message #1850338] Sat, 26 February 2022 19:12 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
The Sirius preferences for font color don't take any effect on my diagrams. I suspect they are only for the EMF diagram tools.
Re: Conditional Style Based on Theme - Light vs Dark Mode [message #1850361 is a reply to message #1850360] Sat, 26 February 2022 20:57 Go to previous message
Brandon Lewis is currently offline Brandon LewisFriend
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

Previous Topic:Browser for Single Object Link Really Hard to Use
Next Topic:Provide custom DAnalysisSessionImpl
Goto Forum:
  


Current Time: Fri Apr 26 22:17:53 GMT 2024

Powered by FUDForum. Page generated in 0.03594 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top