Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-ui-dev] Question regarding theming

Hello,

On 06/21/2017 11:24 AM, Becker, Matthias wrote:
Dear all,

if I see it correct colors you obtain via Display.getCurrent().getSystemColor( ) (e.g. SWT.COLOR_WIDGET_BACKGROUND) are not adapted via the CSS theming.

So all usages of Display.getCurrent().getSystemColor( ) are potential causes for theming errors. Is there a clear guidance on the usage of Display.getCurrent().getSystemColor( ) and possible alternatives?

Is there an API to obtain e.g. the background color an SWT text widget would get based on the current theme? I know I can call Control.getBackground() to get the current background color of a given

control but what to do if don’t have an instance of SWT.Text at hand?

Display.getSystemColor() returns a color that is native to the operating system. These are the same colors you see for default OS widgets. On Linux this means parsing the currently running GTK theme and extracting certain color values from it.

If an SWT widget is unstyled (it has no background and/or foreground colors set), then it should adhere to the colors found in Display.getSystemColors(). For example:

Text/Table/Tree based widgets: COLOR_LIST_* (sometimes COLOR_TITLE_*)
Buttons, Toolbars, other common widgets: COLOR_WIDGET_*
Tooltips: COLOR_INFO_*
Links: COLOR_LINK_*

If a widget is indeed unstyled, then calling getBack/Foreground() on it should return the system color appropriate for that widget. If a widget is styled, calling setBack/Foreground(null) and then getBack/Foreground() will have the same effect.

If you have no widget at hand, using the system colors will give you an idea of what that widget should look like by default. Using Text as an example, its background should be COLOR_LIST_BACKGROUND and the foreground should be COLOR_LIST_FOREGROUND. Selections/highlighting should be COLOR_LIST_SELECTION as the background and COLOR_LIST_SELECTION_TEXT as the foreground.


--
Eric Williams
Associate Software Engineer - Eclipse Team
Red Hat


Back to the top