Commit 3dd1a05a authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Better debugPaintSize logic for clip renderers (#11725)

parent 1ee94001
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui show ImageFilter;
import 'dart:ui' as ui show ImageFilter, Gradient;
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
......@@ -1014,6 +1014,35 @@ abstract class _RenderCustomClip<T> extends RenderProxyBox {
Rect describeApproximatePaintClip(RenderObject child) {
return _clipper?.getApproximateClipRect(size) ?? Offset.zero & size;
}
Paint _debugPaint;
TextPainter _debugText;
@override
void debugPaintSize(PaintingContext context, Offset offset) {
assert(() {
_debugPaint ??= new Paint()
..shader = new ui.Gradient.linear(
const Offset(0.0, 0.0),
const Offset(10.0, 10.0),
<Color>[const Color(0x00000000), const Color(0xFFFF00FF), const Color(0xFFFF00FF), const Color(0x00000000)],
<double>[0.25, 0.25, 0.75, 0.75],
TileMode.repeated,
)
..strokeWidth = 2.0
..style = PaintingStyle.stroke;
_debugText ??= new TextPainter(
text: const TextSpan(
text: '✂',
style: const TextStyle(
color: const Color(0xFFFF00FF),
fontSize: 14.0,
),
),
)
..layout();
return true;
});
}
}
/// Clips its child using a rectangle.
......@@ -1052,6 +1081,18 @@ class RenderClipRect extends _RenderCustomClip<Rect> {
context.pushClipRect(needsCompositing, offset, _clip, super.paint);
}
}
@override
void debugPaintSize(PaintingContext context, Offset offset) {
assert(() {
if (child != null) {
super.debugPaintSize(context, offset);
context.canvas.drawRect(_clip.shift(offset), _debugPaint);
_debugText.paint(context.canvas, offset + new Offset(_clip.width / 8.0, -_debugText.text.style.fontSize * 1.1));
}
return true;
});
}
}
/// Clips its child using a rounded rectangle.
......@@ -1111,6 +1152,18 @@ class RenderClipRRect extends _RenderCustomClip<RRect> {
context.pushClipRRect(needsCompositing, offset, _clip.outerRect, _clip, super.paint);
}
}
@override
void debugPaintSize(PaintingContext context, Offset offset) {
assert(() {
if (child != null) {
super.debugPaintSize(context, offset);
context.canvas.drawRRect(_clip.shift(offset), _debugPaint);
_debugText.paint(context.canvas, offset + new Offset(_clip.tlRadiusX, -_debugText.text.style.fontSize * 1.1));
}
return true;
});
}
}
/// Clips its child using an oval.
......@@ -1163,6 +1216,18 @@ class RenderClipOval extends _RenderCustomClip<Rect> {
context.pushClipPath(needsCompositing, offset, _clip, _getClipPath(_clip), super.paint);
}
}
@override
void debugPaintSize(PaintingContext context, Offset offset) {
assert(() {
if (child != null) {
super.debugPaintSize(context, offset);
context.canvas.drawPath(_getClipPath(_clip).shift(offset), _debugPaint);
_debugText.paint(context.canvas, offset + new Offset((_clip.width - _debugText.width) / 2.0, -_debugText.text.style.fontSize * 1.1));
}
return true;
});
}
}
/// Clips its child using a path.
......@@ -1209,6 +1274,18 @@ class RenderClipPath extends _RenderCustomClip<Path> {
context.pushClipPath(needsCompositing, offset, Offset.zero & size, _clip, super.paint);
}
}
@override
void debugPaintSize(PaintingContext context, Offset offset) {
assert(() {
if (child != null) {
super.debugPaintSize(context, offset);
context.canvas.drawPath(_clip.shift(offset), _debugPaint);
_debugText.paint(context.canvas, offset);
}
return true;
});
}
}
/// Creates a physical model layer that clips its children to a rounded
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment