From ece851d5cd301a4967cf15ec710373f7941c80da Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Mon, 14 Nov 2016 11:18:46 -0800 Subject: [PATCH] Minor improvements to the render tree dump. (#6831) Also fixes https://github.com/flutter/flutter/issues/6510 --- .../flutter/lib/src/painting/box_painter.dart | 13 +++++++--- .../flutter/lib/src/painting/decoration.dart | 10 ++++++- .../lib/src/painting/flutter_logo.dart | 2 +- .../flutter/lib/src/rendering/object.dart | 5 +++- .../flutter/lib/src/rendering/proxy_box.dart | 2 +- .../flutter/lib/src/widgets/framework.dart | 26 +++++++++++++++++-- 6 files changed, 49 insertions(+), 9 deletions(-) diff --git a/packages/flutter/lib/src/painting/box_painter.dart b/packages/flutter/lib/src/painting/box_painter.dart index 1c1b936db94..8cdb2e1c01f 100644 --- a/packages/flutter/lib/src/painting/box_painter.dart +++ b/packages/flutter/lib/src/painting/box_painter.dart @@ -1191,7 +1191,7 @@ class BoxDecoration extends Decoration { /// If the method is passed a non-empty string argument, then the output will /// span multiple lines, each prefixed by that argument. @override - String toString([String prefix = '']) { + String toString([String prefix = '', String indentPrefix]) { List result = []; if (backgroundColor != null) result.add('${prefix}backgroundColor: $backgroundColor'); @@ -1201,8 +1201,15 @@ class BoxDecoration extends Decoration { result.add('${prefix}border: $border'); if (borderRadius != null) result.add('${prefix}borderRadius: $borderRadius'); - if (boxShadow != null) - result.add('${prefix}boxShadow: ${boxShadow.map((BoxShadow shadow) => shadow.toString())}'); + if (boxShadow != null) { + if (indentPrefix != null && boxShadow.length > 1) { + result.add('${prefix}boxShadow:'); + for (BoxShadow shadow in boxShadow) + result.add('$indentPrefix$shadow'); + } else { + result.add('${prefix}boxShadow: ${boxShadow.map((BoxShadow shadow) => shadow.toString()).join(", ")}'); + } + } if (gradient != null) result.add('${prefix}gradient: $gradient'); if (shape != BoxShape.rectangle) diff --git a/packages/flutter/lib/src/painting/decoration.dart b/packages/flutter/lib/src/painting/decoration.dart index 8e99575a613..270ebc49c0c 100644 --- a/packages/flutter/lib/src/painting/decoration.dart +++ b/packages/flutter/lib/src/painting/decoration.dart @@ -79,8 +79,16 @@ abstract class Decoration { /// if it is a [BoxDecoration] with definitely no [BackgroundImage]). BoxPainter createBoxPainter([VoidCallback onChanged]); + /// Returns a string representation of this object. + /// + /// Every line of the output should be prefixed by `prefix`. + /// + /// If `indentPrefix` is non-null, then the description can be further split + /// into sublines, and each subline should be prefixed with `indentPrefix` + /// (rather that `prefix`). This is used, for example, by [BoxDecoration] for + /// the otherwise quite verbose [BoxShadow] descriptions. @override - String toString([String prefix = '']) => '$prefix$runtimeType'; + String toString([String prefix = '', String indentPrefix ]) => '$prefix$runtimeType'; } /// A stateful class that can paint a particular [Decoration]. diff --git a/packages/flutter/lib/src/painting/flutter_logo.dart b/packages/flutter/lib/src/painting/flutter_logo.dart index a9c99bc4dbd..25330457a71 100644 --- a/packages/flutter/lib/src/painting/flutter_logo.dart +++ b/packages/flutter/lib/src/painting/flutter_logo.dart @@ -220,7 +220,7 @@ class FlutterLogoDecoration extends Decoration { } @override - String toString([String prefix = '']) { + String toString([String prefix = '', String prefixIndent ]) { final String extra = _inTransition ? ', transition $_position:$_opacity' : ''; if (swatch == null) return '$prefix$runtimeType(null, $style$extra)'; diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart index 3c8ab2ef316..ae46cdd4245 100644 --- a/packages/flutter/lib/src/rendering/object.dart +++ b/packages/flutter/lib/src/rendering/object.dart @@ -2409,7 +2409,10 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { final String descriptionPrefix = childrenDescription != '' ? '$prefixOtherLines \u2502 ' : '$prefixOtherLines '; List description = []; debugFillDescription(description); - result += description.map((String description) => "$descriptionPrefix$description\n").join(); + result += description + .expand((String description) => description.split('\n')) + .map/**/((String line) => "$descriptionPrefix$line\n") + .join(); if (childrenDescription == '') result += '$prefixOtherLines\n'; result += childrenDescription; diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index cb9d1021c72..dc07adbb374 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -1298,7 +1298,7 @@ class RenderDecoratedBox extends RenderProxyBox { void debugFillDescription(List description) { super.debugFillDescription(description); description.add('decoration:'); - description.addAll(_decoration.toString(" ").split('\n')); + description.addAll(_decoration.toString(' ', ' ').split('\n')); description.add('configuration: $configuration'); } } diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 06824f7e3b1..7fc887d5f15 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -2560,7 +2560,19 @@ abstract class Element implements BuildContext { } if (node != null) chain.add('\u22EF'); - return chain.join(' \u2190 '); + String result = ''; + String line = ''; + for (String link in chain) { + if (line != '') + line += ' \u2190 '; + if (link.length > 3 && line.length + link.length > 65) { + result += '$line\n'; + line = ' '; + } + line += link; + } + result += line; + return result; } /// A short, textual description of this element. @@ -3462,7 +3474,10 @@ abstract class RenderObjectElement extends BuildableElement { } void _debugUpdateRenderObjectOwner() { - _renderObject.debugCreator = debugGetCreatorChain(10); + assert(() { + _renderObject.debugCreator = new _DebugCreator(this); + return true; + }); } @override @@ -3922,6 +3937,13 @@ class MultiChildRenderObjectElement extends RenderObjectElement { } } +class _DebugCreator { + _DebugCreator(this.element); + final RenderObjectElement element; + @override + String toString() => element.debugGetCreatorChain(12); +} + void _debugReportException(String context, dynamic exception, StackTrace stack, { InformationCollector informationCollector }) {