Commit 306a364f authored by Ian Hickson's avatar Ian Hickson

Merge pull request #1158 from Hixie/padding-debug

Add more debugPaintSizeEnabled construction lines.
parents fb66bf11 20a01b42
...@@ -693,50 +693,62 @@ abstract class RenderBox extends RenderObject { ...@@ -693,50 +693,62 @@ abstract class RenderBox extends RenderObject {
} }
void debugPaint(PaintingContext context, Offset offset) { void debugPaint(PaintingContext context, Offset offset) {
if (debugPaintSizeEnabled) assert(() {
debugPaintSize(context, offset); if (debugPaintSizeEnabled)
if (debugPaintBaselinesEnabled) debugPaintSize(context, offset);
debugPaintBaselines(context, offset); if (debugPaintBaselinesEnabled)
if (debugPaintPointersEnabled) debugPaintBaselines(context, offset);
debugPaintPointers(context, offset); if (debugPaintPointersEnabled)
debugPaintPointers(context, offset);
return true;
});
} }
void debugPaintSize(PaintingContext context, Offset offset) { void debugPaintSize(PaintingContext context, Offset offset) {
Paint paint = new Paint() assert(() {
..style = ui.PaintingStyle.stroke Paint paint = new Paint()
..strokeWidth = 1.0 ..style = ui.PaintingStyle.stroke
..color = debugPaintSizeColor; ..strokeWidth = 1.0
context.canvas.drawRect(offset & size, paint); ..color = debugPaintSizeColor;
context.canvas.drawRect((offset & size).deflate(0.5), paint);
return true;
});
} }
void debugPaintBaselines(PaintingContext context, Offset offset) { void debugPaintBaselines(PaintingContext context, Offset offset) {
Paint paint = new Paint() assert(() {
..style = ui.PaintingStyle.stroke Paint paint = new Paint()
..strokeWidth = 0.25; ..style = ui.PaintingStyle.stroke
Path path; ..strokeWidth = 0.25;
// ideographic baseline Path path;
double baselineI = getDistanceToBaseline(TextBaseline.ideographic, onlyReal: true); // ideographic baseline
if (baselineI != null) { double baselineI = getDistanceToBaseline(TextBaseline.ideographic, onlyReal: true);
paint.color = debugPaintIdeographicBaselineColor; if (baselineI != null) {
path = new Path(); paint.color = debugPaintIdeographicBaselineColor;
path.moveTo(offset.dx, offset.dy + baselineI); path = new Path();
path.lineTo(offset.dx + size.width, offset.dy + baselineI); path.moveTo(offset.dx, offset.dy + baselineI);
context.canvas.drawPath(path, paint); path.lineTo(offset.dx + size.width, offset.dy + baselineI);
} context.canvas.drawPath(path, paint);
// alphabetic baseline }
double baselineA = getDistanceToBaseline(TextBaseline.alphabetic, onlyReal: true); // alphabetic baseline
if (baselineA != null) { double baselineA = getDistanceToBaseline(TextBaseline.alphabetic, onlyReal: true);
paint.color = debugPaintAlphabeticBaselineColor; if (baselineA != null) {
path = new Path(); paint.color = debugPaintAlphabeticBaselineColor;
path.moveTo(offset.dx, offset.dy + baselineA); path = new Path();
path.lineTo(offset.dx + size.width, offset.dy + baselineA); path.moveTo(offset.dx, offset.dy + baselineA);
context.canvas.drawPath(path, paint); path.lineTo(offset.dx + size.width, offset.dy + baselineA);
} context.canvas.drawPath(path, paint);
}
return true;
});
} }
void debugPaintPointers(PaintingContext context, Offset offset) { void debugPaintPointers(PaintingContext context, Offset offset) {
if (_debugActivePointers > 0) { assert(() {
Paint paint = new Paint() if (_debugActivePointers > 0) {
..color = new Color(debugPaintPointersColorValue | ((0x04000000 * depth) & 0xFF000000)); Paint paint = new Paint()
context.canvas.drawRect(offset & size, paint); ..color = new Color(debugPaintPointersColorValue | ((0x04000000 * depth) & 0xFF000000));
} context.canvas.drawRect(offset & size, paint);
}
return true;
});
} }
void debugDescribeSettings(List<String> settings) { void debugDescribeSettings(List<String> settings) {
......
...@@ -13,12 +13,26 @@ import 'package:flutter/scheduler.dart'; ...@@ -13,12 +13,26 @@ import 'package:flutter/scheduler.dart';
export 'package:flutter/services.dart' show debugPrint; export 'package:flutter/services.dart' show debugPrint;
/// Causes each RenderBox to paint a box around its bounds. /// Causes each RenderBox to paint a box around its bounds, and some extra
/// boxes, such as RenderPadding, to draw construction lines.
bool debugPaintSizeEnabled = false; bool debugPaintSizeEnabled = false;
/// The color to use when painting RenderObject bounds. /// The color to use when painting RenderObject bounds.
ui.Color debugPaintSizeColor = const ui.Color(0xFF00FFFF); ui.Color debugPaintSizeColor = const ui.Color(0xFF00FFFF);
/// The color to use when painting some boxes that just add space (e.g. an empty
/// RenderConstrainedBox or RenderPadding).
ui.Color debugPaintSpacingColor = const ui.Color(0x90909090);
/// The color to use when painting RenderPadding edges.
ui.Color debugPaintPaddingColor = const ui.Color(0x900090FF);
/// The color to use when painting RenderPadding edges.
ui.Color debugPaintPaddingInnerEdgeColor = const ui.Color(0xFF0090FF);
/// The color to use when painting the arrows used to show RenderPositionedBox alignment.
ui.Color debugPaintArrowColor = const ui.Color(0xFFFFFF00);
/// Causes each RenderBox to paint a line at each of its baselines. /// Causes each RenderBox to paint a line at each of its baselines.
bool debugPaintBaselinesEnabled = false; bool debugPaintBaselinesEnabled = false;
......
...@@ -158,6 +158,19 @@ class RenderConstrainedBox extends RenderProxyBox { ...@@ -158,6 +158,19 @@ class RenderConstrainedBox extends RenderProxyBox {
} }
} }
void debugPaintSize(PaintingContext context, Offset offset) {
super.debugPaintSize(context, offset);
assert(() {
Paint paint;
if (child == null || child.size.isEmpty) {
paint = new Paint()
..color = debugPaintSpacingColor;
context.canvas.drawRect(offset & size, paint);
}
return true;
});
}
void debugDescribeSettings(List<String> settings) { void debugDescribeSettings(List<String> settings) {
super.debugDescribeSettings(settings); super.debugDescribeSettings(settings);
settings.add('additionalConstraints: $additionalConstraints'); settings.add('additionalConstraints: $additionalConstraints');
......
...@@ -2,9 +2,13 @@ ...@@ -2,9 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:math' as math;
import 'dart:ui' as ui;
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
import 'box.dart'; import 'box.dart';
import 'debug.dart';
import 'object.dart'; import 'object.dart';
/// Abstract class for one-child-layout render boxes that provide control over /// Abstract class for one-child-layout render boxes that provide control over
...@@ -153,6 +157,50 @@ class RenderPadding extends RenderShiftedBox { ...@@ -153,6 +157,50 @@ class RenderPadding extends RenderShiftedBox {
)); ));
} }
void debugPaintSize(PaintingContext context, Offset offset) {
super.debugPaintSize(context, offset);
assert(() {
Paint paint;
if (child != null && !child.size.isEmpty) {
Path path;
paint = new Paint()
..color = debugPaintPaddingColor;
path = new Path()
..moveTo(offset.dx, offset.dy)
..lineTo(offset.dx + size.width, offset.dy)
..lineTo(offset.dx + size.width, offset.dy + size.height)
..lineTo(offset.dx, offset.dy + size.height)
..close()
..moveTo(offset.dx + padding.left, offset.dy + padding.top)
..lineTo(offset.dx + padding.left, offset.dy + size.height - padding.bottom)
..lineTo(offset.dx + size.width - padding.right, offset.dy + size.height - padding.bottom)
..lineTo(offset.dx + size.width - padding.right, offset.dy + padding.top)
..close();
context.canvas.drawPath(path, paint);
paint = new Paint()
..color = debugPaintPaddingInnerEdgeColor;
const kOutline = 2.0;
path = new Path()
..moveTo(offset.dx + math.max(padding.left - kOutline, 0.0), offset.dy + math.max(padding.top - kOutline, 0.0))
..lineTo(offset.dx + math.min(size.width - padding.right + kOutline, size.width), offset.dy + math.max(padding.top - kOutline, 0.0))
..lineTo(offset.dx + math.min(size.width - padding.right + kOutline, size.width), offset.dy + math.min(size.height - padding.bottom + kOutline, size.height))
..lineTo(offset.dx + math.max(padding.left - kOutline, 0.0), offset.dy + math.min(size.height - padding.bottom + kOutline, size.height))
..close()
..moveTo(offset.dx + padding.left, offset.dy + padding.top)
..lineTo(offset.dx + padding.left, offset.dy + size.height - padding.bottom)
..lineTo(offset.dx + size.width - padding.right, offset.dy + size.height - padding.bottom)
..lineTo(offset.dx + size.width - padding.right, offset.dy + padding.top)
..close();
context.canvas.drawPath(path, paint);
} else {
paint = new Paint()
..color = debugPaintSpacingColor;
context.canvas.drawRect(offset & size, paint);
}
return true;
});
}
void debugDescribeSettings(List<String> settings) { void debugDescribeSettings(List<String> settings) {
super.debugDescribeSettings(settings); super.debugDescribeSettings(settings);
settings.add('padding: $padding'); settings.add('padding: $padding');
...@@ -245,6 +293,63 @@ class RenderPositionedBox extends RenderShiftedBox { ...@@ -245,6 +293,63 @@ class RenderPositionedBox extends RenderShiftedBox {
} }
} }
void debugPaintSize(PaintingContext context, Offset offset) {
super.debugPaintSize(context, offset);
assert(() {
Paint paint;
if (child != null && !child.size.isEmpty) {
Path path;
paint = new Paint()
..style = ui.PaintingStyle.stroke
..strokeWidth = 1.0
..color = debugPaintArrowColor;
path = new Path();
final BoxParentData childParentData = child.parentData;
if (childParentData.offset.dy > 0.0) {
// vertical alignment arrows
double headSize = math.min(childParentData.offset.dy * 0.2, 10.0);
path
..moveTo(offset.dx + size.width / 2.0, offset.dy)
..relativeLineTo(0.0, childParentData.offset.dy - headSize)
..relativeLineTo(headSize, 0.0)
..relativeLineTo(-headSize, headSize)
..relativeLineTo(-headSize, -headSize)
..relativeLineTo(headSize, 0.0)
..moveTo(offset.dx + size.width / 2.0, offset.dy + size.height)
..relativeLineTo(0.0, -childParentData.offset.dy + headSize)
..relativeLineTo(headSize, 0.0)
..relativeLineTo(-headSize, -headSize)
..relativeLineTo(-headSize, headSize)
..relativeLineTo(headSize, 0.0);
context.canvas.drawPath(path, paint);
}
if (childParentData.offset.dx > 0.0) {
// horizontal alignment arrows
double headSize = math.min(childParentData.offset.dx * 0.2, 10.0);
path
..moveTo(offset.dx, offset.dy + size.height / 2.0)
..relativeLineTo(childParentData.offset.dx - headSize, 0.0)
..relativeLineTo(0.0, headSize)
..relativeLineTo(headSize, -headSize)
..relativeLineTo(-headSize, -headSize)
..relativeLineTo(0.0, headSize)
..moveTo(offset.dx + size.width, offset.dy + size.height / 2.0)
..relativeLineTo(-childParentData.offset.dx + headSize, 0.0)
..relativeLineTo(0.0, headSize)
..relativeLineTo(-headSize, -headSize)
..relativeLineTo(headSize, -headSize)
..relativeLineTo(0.0, headSize);
context.canvas.drawPath(path, paint);
}
} else {
paint = new Paint()
..color = debugPaintSpacingColor;
context.canvas.drawRect(offset & size, paint);
}
return true;
});
}
void debugDescribeSettings(List<String> settings) { void debugDescribeSettings(List<String> settings) {
super.debugDescribeSettings(settings); super.debugDescribeSettings(settings);
settings.add('alignment: $alignment'); settings.add('alignment: $alignment');
......
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