-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Color-Provider to theme custom controls #130
base: master
Are you sure you want to change the base?
Conversation
2c92510
to
d65adae
Compare
dc0eaee
to
73a24dc
Compare
a9f24e5
to
d2109d6
Compare
baf5c63
to
90ef5c8
Compare
90ef5c8
to
4935aba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, this looks good to me. I only have two comments/thoughts on this.
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Button.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
Outdated
Show resolved
Hide resolved
4935aba
to
55c5182
Compare
c49e0c0
to
232f25a
Compare
Now also includes (parts of) ToolBar. |
bbe6a94
to
07d02a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comment in the code.
When i tested this, i noticed that the toolBar background is a lot darker then on the master branch. Don't know why.
I general is the following pros of this approach:
- All colors defined in a central place
- All colors can be easily switch out
The cons:
- It is not very friendly for implementing custom widget or a custom renderer. A custom widget would have to either have to define its own colors (like before) or use the color provider with a color-key that is unrelated to their situation.
- If a new key is added, a custom color provider would not know about it and would not return a proper color.
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/DefaultColorProvider.java
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/DefaultColorProvider.java
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
public Color getBackground() { | ||
return background != null ? background : getColorProvider().getColor(ToolBarRenderer.COLOR_BACKGROUND); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToolBar should not have a dependency to a specific renderer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the generic ToolBarRenderer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not this is the actual Implementation. ToolBarRenderer is not abstract and no other renderer extends from it.
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/ToolBar.java
Show resolved
Hide resolved
07d02a1
to
6e688ba
Compare
Thanks for reviewing.
I'd say, because the background of composites comes from Windows while the background from controls like
What do you suggest? I also had the idea of directly creating getters for certain colors instead of using a map (which is quite fast, but field access is faster). Independent of your review, I have the idea of renaming the |
Instead of color constants, the custom controls ask the color provider to give them a color by name. This allows easier theming.
6e688ba
to
b11d41c
Compare
But why is it different between master and PR? adding the ColorProvider should not change the rendering (in Light mode).
I think we are in an early state of development so that we are able to try different things. But how i see it this should not be the final solution for color.
I think the main problem is that the DefaultColorProvider has dependencies to every renderer. Maybe this could be fixed by moving the color keys into the DefaultColorProvider or maybe separate class. I'm also wondering why you decided to go against the earlier suggested material design concept of a color scheme [2] [1] I know the primary goal of I31 is to have less implementations, but a secondary goal i would say is to switch to different renderings [2] https://developer.android.com/develop/ui/compose/designsystems/material3 |
So in other words you suggest to use the Windows 11 default background color as default background for the custom drawn widgets?
They should rather be public. Maybe for some classes without clear renderer hierarchies this is not correctly implemented now.
What do you suggest as alternative?
Which IMHO is correct, because only the specific color provider knows which colors are required. If you want to use a different renderer (which uses completely different colors), you will need to create an own color provider, too.
Then there needs to be a different LinuxScaleRenderer and a different LinuxRendererFactory and a different LinuxColorFactory (or LinuxRendererConfig as I suggested). If you have a better suggestion how to implement it, you are welcome to provide a code suggestion.
I think, I've didn't. The light and dark default implementations derive from a base color. If you mean something else, again, please feel free to provide a different implementation. |
I'm waiting for #171 to be accepted before this one needs to be modified to fix some of @DieterMai's feedback. |
No, i am confused why the ToolBar has a different background then before.
Have more generic color keys.
This is not how i imagen it to be used.
I'm hesitant to do so. ATM I'm focused on reaching feature parity with the native implementation.
I would have imaged something like |
IMHO it did not draw any background at all, but used the Windows default. This will not work for a themed application, e.g. with a forced dark theme on a light windows (or visa versa). But it might be useful to also be able to get nullable colors (with the meaning of don't draw a background, for example).
For example?
IMHO different renderers may need different colors. Example: one (Push)ButtonRenderer mit use 5 colors (background, background-disabled, foreground, foreground-disabled, focus/default-highlight) while another one could use much more colors because it also draws a border with different colors. Maybe each Renderer needs a special belonging Config containing colors?
Yes, me too, but I don't know how I should implement that, e.g. for a button. Hence I've asked for an implementation example. IMHO, the current approach is more generic - it allows any arbitrary number of colors. A MaterialColorProvider could set all these colors (from my PR) from a its material colors. |
@@ -169,7 +169,7 @@ private static int checkStyle(int style) { | |||
} | |||
int mask = SWT.SHADOW_IN | SWT.SHADOW_OUT | SWT.SHADOW_NONE | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; | |||
style = style & mask; | |||
style |= SWT.NO_FOCUS | SWT.DOUBLE_BUFFERED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why get rid of SWT.DOUBLE_BUFFERED
? How is that related to the PR?
@Override | ||
public void setBackground(Color color) { | ||
super.setBackground(color); | ||
renderer.setBackground(color); | ||
redraw(); | ||
} | ||
|
||
@Override | ||
public Color getForeground() { | ||
return foreground != null ? foreground : getColorProvider().getColor(LabelRenderer.COLOR_FOREGROUND); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the renderer hold this information, like it holds the background color?
@@ -5250,4 +5250,7 @@ static double luma (double[] rgbColor) { | |||
return 0.2126f * rgbColor[0] + 0.7152f * rgbColor[1] + 0.0722f * rgbColor[2]; | |||
} | |||
|
|||
protected ColorProvider getColorProvider() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make sense to make it final
so no one gets the idea of overriding it and start instantiating/holding color providers someplace else. WDYT?
|
||
private final Map<String, Color> map = new HashMap<>(); | ||
|
||
public DefaultColorProvider() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public DefaultColorProvider() { | |
private DefaultColorProvider() { | |
// prevent instantiation from outside |
@@ -6875,4 +6875,7 @@ Point getSurfaceOrigin () { | |||
return success ? new Point((int)originX[0], (int)originY[0]) : new Point(0, 0); | |||
} | |||
|
|||
protected ColorProvider getColorProvider() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected ColorProvider getColorProvider() { | |
protected final ColorProvider getColorProvider() { |
* Sets the color provider used for custom-drawn controls. | ||
* @param colorProvider a non-null color provider | ||
*/ | ||
public void setColorProvider(ColorProvider colorProvider) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void setColorProvider(ColorProvider colorProvider) { | |
public final void setColorProvider(ColorProvider colorProvider) { |
* Returns the color provider used for custom-drawn controls. | ||
* @return a non-null instance of the color provider | ||
*/ | ||
public ColorProvider getColorProvider() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public ColorProvider getColorProvider() { | |
public final ColorProvider getColorProvider() { |
* Sets the color provider used for custom-drawn controls. | ||
* @param colorProvider a non-null color provider | ||
*/ | ||
public void setColorProvider(ColorProvider colorProvider) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void setColorProvider(ColorProvider colorProvider) { | |
public final void setColorProvider(ColorProvider colorProvider) { |
import org.eclipse.swt.layout.*; | ||
import org.eclipse.swt.widgets.*; | ||
|
||
public class ColorProviderTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: since this isn't an automatic test class and since we have this kind of showcases already (ControlExample
/ CustomControlExample
), how about calling it:
public class ColorProviderTest { | |
public class ColorProviderTExample { |
?
Also, would it be possible to add the ´darkChkBx´ to the ControlExample
and CustomControlExample
? Those 2 classes already showcase all of the controls so it should keep up-to-date while we keep implementing the widgets
protected Color background; | ||
protected Color foreground; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume in the future (once all controls have their corresponding renderers) these 2 should also go into the corresponding renderer, right? Otherwise the information about coloring is scattered between the controls and their renderers.
Please start
ColorProviderTest
to test.Note, that the color provider, the color constants and the renderer are closely linked. In the future there will be exchangeable renderers which then need an own color provider (e.g. because a different renderer needs more/less colors).
Feedback is welcome.