pushClipRSuperellipse method

ClipRSuperellipseLayer? pushClipRSuperellipse(
  1. bool needsCompositing,
  2. Offset offset,
  3. Rect bounds,
  4. RSuperellipse clipRSuperellipse,
  5. PaintingContextCallback painter, {
  6. Clip clipBehavior = Clip.antiAlias,
  7. ClipRSuperellipseLayer? oldLayer,
})

Clip further painting using a rounded superellipse.

The needsCompositing argument specifies whether the child needs compositing. Typically this matches the value of RenderObject.needsCompositing for the caller. If false, this method returns null, indicating that a layer is no longer necessary. If a render object calling this method stores the oldLayer in its RenderObject.layer field, it should set that field to null.

When needsCompositing is false, this method will use a more efficient way to apply the layer effect than actually creating a layer.

The offset argument is the offset from the origin of the canvas' coordinate system to the origin of the caller's coordinate system.

The bounds argument is used to specify the region of the canvas (in the caller's coordinate system) into which painter will paint.

The clipRSuperellipse argument specifies the rounded-superellipse (in the caller's coordinate system) to use to clip the painting done by painter. It should not include the offset.

The painter callback will be called while the clipRSuperellipse is applied. It is called synchronously during the call to pushClipRSuperellipse.

The clipBehavior argument controls how the rounded rectangle is clipped.

Hit tests are performed based on the bounding box of the RSuperellipse.

For the oldLayer argument, specify the layer created in the previous frame. This gives the engine more information for performance optimizations. Typically this is the value of RenderObject.layer that a render object creates once, then reuses for all subsequent frames until a layer is no longer needed (e.g. the render object no longer needs compositing) or until the render object changes the type of the layer (e.g. from opacity layer to a clip rect layer).

Implementation

ClipRSuperellipseLayer? pushClipRSuperellipse(
  bool needsCompositing,
  Offset offset,
  Rect bounds,
  RSuperellipse clipRSuperellipse,
  PaintingContextCallback painter, {
  Clip clipBehavior = Clip.antiAlias,
  ClipRSuperellipseLayer? oldLayer,
}) {
  if (clipBehavior == Clip.none) {
    painter(this, offset);
    return null;
  }
  final Rect offsetBounds = bounds.shift(offset);
  final RSuperellipse offsetShape = clipRSuperellipse.shift(offset);
  if (needsCompositing) {
    final ClipRSuperellipseLayer layer = oldLayer ?? ClipRSuperellipseLayer();
    layer
      ..clipRSuperellipse = offsetShape
      ..clipBehavior = clipBehavior;
    pushLayer(layer, painter, offset, childPaintBounds: offsetBounds);
    return layer;
  } else {
    clipRSuperellipseAndPaint(
      offsetShape,
      clipBehavior,
      offsetBounds,
      () => painter(this, offset),
    );
    return null;
  }
}