-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Add Clip enum to Material and related widgets #18576
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
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'm not sure whether I should default to ClipOption.none here. It seems ironical to have no clip as default for a clipper. Currently, only ShapeBorderClipper default to ClipOption.none.
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.
yeah the clipping widgets should probably default to Clip.antiAlias
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.
Ack.
|
@Hixie @goderbauer @gspencergoog : one week has passed since we posted the breaking API change proposal so I'm starting to implement the change. This is an incomplete PR but I'd like to get some feedback before I go too far. Please let me know if I'm heading the right direction in dart. |
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.
We should definitely have more documentation than this. Also, all documentation (here and elsewhere) should be fully grammatical sentences (e.g. end with a period).
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.
Sure, writing now.
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.
for these, we should follow the following convention (used elsewhere in the docs):
/// Brief sentence fragment that says what it does.
///
/// This is a longer sentence that describes the semantics of the value in detail,
/// including edge cases. There might be more sentences here.
///
/// Then, have a sentence or more than talks about the current performance
/// implications.
///
/// Finally, a brief comment if the feature is unlikely to be used.
///
/// See also:
///
/// * [SomethingElse], which is something relevant.
The "see also" block would be omitted if not useful. But e.g. antiAlias might point to Canvas.antiAlias.
So for example:
/// Clip, but do not apply anti-aliasing.
///
/// This mode enables clipping, but curves and non-axis-aligned straight lines will be
/// jagged as no effort is made to anti-alias.
///
/// Faster than other clipping modes, but slower than [none].
///
/// This is a reasonable choice when clipping is needed, if the container is an axis-
/// aligned rectangle or an axis-aligned rounded rectangle with very small corner radii.
///
/// See also:
///
/// * [antiAlias], which is more reasonable when clipping is needed and the shape is not
/// an axis-aligned rectangle.
hardEdge,
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.
Thank you @Hixie for the sample writing! However, I couldn't find Canvas.antiAlias. It seems that we don't offer non-anti-aliased draw in Canvas?
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.
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.
assert clip != null
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.
by the way if you come up with detailed docs for these and want to avoid copying-and-pasting them all over the place, and if they do in fact apply equally everywhere, then consider using a dartdoc macro/template to avoid duplication. See the child macro (used for the child property of most widgets) as an example.
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.
Done.
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 word "option" here doesn't seem to add much. Is Clip ok?
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.
Yeah, that's Ok. Renaming now.
|
ideally this PR would remove most if not all uses of ClipRect, ClipRRect, and ClipPath from the framework too, or at least make them configurable with a |
8bf5fa1 to
89ecae4
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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: extraneous blank line
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: end sentences with a period
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.
put a blank line between the two paragraphs
|
It might make sense to separate it into two PRs, I don't feel strongly one way or the other. But if we do split it, we should make sure that the first PR doesn't actually change any behaviour, so that we have a single PR that does the breaking change across everything. We want to look for more than just |
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.
put the sentence starting with [Clip.none] in a separate paragraph.
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 first sentence is in its own paragraph because it's used in more places)
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.
Done.
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 says it's not allowed to be Clip.none, which seems reasonable, but you don't assert it above (which you do in other constructors) and you do support it in addToScene (which you don't in the others), which seems confusing. I think they should all be consistent (and probably not support none).
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.
Thanks for spotting this! That's my intention and somehow I forgot to add assert to ClipRRectLayer, and enabled = clipBehavior != Clip.none to ClipRectLayer. (I guess that I somehow saw ClipRRectLayer as the same class as ClipRectLayer 😅 )
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 seems weird that you support it in addToScene and indeed have a mutable field that can be set to none but don't allow it in the constructor. I hadn't realized it was a mutable field before (it makes sense that it is). Maybe the field should have a setter that asserts it's valid?
as in:
Clip get clipBehavior => _clipBehavior;
Clip _clipBehavior;
set clipBehavior(Clip value) {
assert(value != null);
assert(value != Clip.none);
_clipBehavior = value;
}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.
if you did that you could remove the behaviour in addToScene that cares about none.
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 are these on Layer? Seems like an odd place for them. Since they don't do anything with layers, i'd put them in the painting layer of our system.
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.
Oops, misunderstood #18576 (comment) by only seeing layer at the end withot painting... Now fixed.
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.
all identifiers of members in docs should be in [] every time (and all identifiers of arguments in docs should be in `` every time, but that doesn't apply here)
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.
Done.
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 think we should just expose the _clipBehavior directly, I don't see any reason to have a getter that defers to clipper sometimes.
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.
Done.
|
@Hixie : updated. I just learned that Dart can implement non-abstract class and there's a noSuchMethod 😃 |
|
we should put |
Add Clip enum Propogate Clip for Material in dart The Clip isn't sent to the C++ engine yet, and it currently only works for needsCompositing render objects.
This way, we can implement the breaking change in two steps. In the first step, `defaultClipBehavior = Clip.antiAlias` so nothing should be changed in rendering. In step two, we set `defaultClipBehavior = Clip.none` and update all necessary tests.
We have to rename several fields and methods to avoid the name conflict.
1. add setter for clipBehavior to prevent Clip.none 2. move ClipContext to painting layer
See details in our proposal for this breaking API change and #18057