-
Notifications
You must be signed in to change notification settings - Fork 162
Add getGcStyle() method to accommodate styling #1948
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
Conversation
222d9d8
to
fe3537b
Compare
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageGcDrawer.java
Outdated
Show resolved
Hide resolved
c923c71
to
c3c7c18
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.
The change looks basically fine. Can you please:
- correct the formatting and
- add a consumer that demonstrates necessity for the extension?
e5a14a3
to
0cb871c
Compare
Add getGcStyle() having a default implementation returning SWT.None
@ShahzaibIbrahim Is there a PR with an implementation that is overriding this method to utilize it? |
|
Sorry for commenting after the fact, but I think we could avoid the extra method, if we introduce a static factory that besides and ImageDrawer accepts the style and returns a special implementation. In the public interface ImageGcDrawer {
...
public static ImageGcDrawer withGCStyle(int style, ImageGcDrawer drawer) {
return new ExtendedImageDrawer(drawer, style);
}
} This way one can still use a lambda if a style is to be set and we avoid an extra method on the interface itself (of course we get the factory for it). If you think this would be better, I can create a follow-up PR for it. |
@HannesWell thank you for the suggestion!
Is there any downside with the current approach or is it a matter of using newer coding practices? (Disclaimer: I would have even gone with a builder pattern combined with lambdas so one could extend the returned instance by chaining calls together and providing new functionalities (in form of lambdas). But as I was writing this, the word "overkill" kept popping up in my head 😅) |
I generally like the idea. What I currently don't see is how we could realize the idea without type switches. The |
It's just that this pattern remembers me about the existing typed Event interfaces, their adapter classes with empty implementation for easier sub-classing and the static And with the current approach we somehow have the Adapter directly in the interface, while (at least from my understanding and experience) the As a picture (or code) speaks more than a thousands words I have now added these ideas in #1985 (comment).
If I understand you right, that's exactly how this is solved. Within the image class it's checked if the special (SWT internal) type is passed. But lets discuss that in #1985 :) |
GC can be initialize with
GC(drawable)
orGC(drawable, style)
. CurrentlyImage(Device, ImageGcDrawer, height, width)
doesn't considerstyle
attribute while initializingGC
. We need to create a new constructor forImage
e.g.Image(Device, ImageGcDrawer, height, width, style)
for which laterGC
insideImageGcDrawer
is initialized considering the style provided to it.Now from implementation side, you can override
getGcStyle()
to provide styling inGC
e.g.LEFT_TO_RIGHT
, etcConsumer usage
Before this change, there was no way for consumer to provide styling using
ImageGcDrawer
.Now with this change. Consumer can define the styling with which
GC
will be initialized later inImageGCDrawerWrapper
.Required by