Skip to content

Conversation

@liyuqian
Copy link
Contributor

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

@liyuqian
Copy link
Contributor Author

@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.

Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, writing now.

Copy link
Contributor

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,

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert clip != null

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@Hixie
Copy link
Contributor

Hixie commented Jun 22, 2018

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 clip property as with Material. Similarly, most widgets that today use a Material should expose a clip that they pass through (e.g. Card, Dialog, etc).

@liyuqian liyuqian force-pushed the clip_option branch 2 times, most recently from 8bf5fa1 to 89ecae4 Compare June 27, 2018 21:44
@liyuqian

This comment has been minimized.

@liyuqian liyuqian changed the title Add ClipOption so we default to not clip Add Clip enum to material Jun 27, 2018
@liyuqian

This comment has been minimized.

@liyuqian liyuqian changed the title Add Clip enum to material Add Clip enum to material and related widgets, and default it to none Jun 27, 2018
@liyuqian liyuqian changed the title Add Clip enum to material and related widgets, and default it to none Add Clip enum (default to none) to material and related widgets Jun 27, 2018
@liyuqian liyuqian changed the title Add Clip enum (default to none) to material and related widgets Add Clip enum (default to none) to Material and related widgets Jun 27, 2018
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extraneous blank line

Copy link
Contributor

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

Copy link
Contributor

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

@Hixie
Copy link
Contributor

Hixie commented Jun 27, 2018

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 new Material, by the way. We want to look for anywhere that is using any of the clipping widgets, physical models, material, saveLayer, etc. Clean them all out at once.

@liyuqian liyuqian changed the title Add Clip enum (default to none) to Material and related widgets Add Clip enum to Material and related widgets Jun 27, 2018
Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

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).

Copy link
Contributor Author

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 😅 )

Copy link
Contributor

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;
  }

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@liyuqian
Copy link
Contributor Author

@Hixie : updated. I just learned that Dart can implement non-abstract class and there's a noSuchMethod 😃

@Hixie
Copy link
Contributor

Hixie commented Aug 2, 2018

LGTM modulo comments

we should put ClipContext in the painting layer, not rendering, since it's just about painting. I probably would have just made the ClipContext methods public global functions that took a Canvas as an argument actually (that'd be more like other things in the painting layer), but this is probably fine too. Might need rearranging at some point especially if we add more things to it.

liyuqian added 18 commits August 2, 2018 15:08
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
@liyuqian liyuqian merged commit 9ffa1c5 into flutter:master Aug 3, 2018
@liyuqian liyuqian deleted the clip_option branch August 27, 2018 23:18
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants