debug.dart 6.13 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/painting.dart';
Devon Carew's avatar
Devon Carew committed
6
import 'package:flutter/rendering.dart';
7

8
export 'package:flutter/foundation.dart' show debugPrint;
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// Any changes to this file should be reflected in the debugAssertAllRenderVarsUnset()
// function below.

const Color _kDebugPaintSizeColor = const Color(0xFF00FFFF);
const Color _kDebugPaintSpacingColor = const Color(0x90909090);
const Color _kDebugPaintPaddingColor = const Color(0x900090FF);
const Color _kDebugPaintPaddingInnerEdgeColor = const Color(0xFF0090FF);
const Color _kDebugPaintArrowColor = const Color(0xFFFFFF00);
const Color _kDebugPaintAlphabeticBaselineColor = const Color(0xFF00FF00);
const Color _kDebugPaintIdeographicBaselineColor = const Color(0xFFFFD000);
const Color _kDebugPaintLayerBordersColor = const Color(0xFFFF9800);
const int _kDebugPaintPointersColorValue = 0x00BBBB;
const HSVColor _kDebugCurrentRepaintColor = const HSVColor.fromAHSV(0.4, 60.0, 1.0, 1.0);
const double _kDebugRepaintRainbowHueIncrement = 2.0;

25 26
/// Causes each RenderBox to paint a box around its bounds, and some extra
/// boxes, such as RenderPadding, to draw construction lines.
27
bool debugPaintSizeEnabled = false;
Adam Barth's avatar
Adam Barth committed
28 29

/// The color to use when painting RenderObject bounds.
30
Color debugPaintSizeColor = _kDebugPaintSizeColor;
31

32 33
/// The color to use when painting some boxes that just add space (e.g. an empty
/// RenderConstrainedBox or RenderPadding).
34
Color debugPaintSpacingColor = _kDebugPaintSpacingColor;
35 36

/// The color to use when painting RenderPadding edges.
37
Color debugPaintPaddingColor = _kDebugPaintPaddingColor;
38 39

/// The color to use when painting RenderPadding edges.
40
Color debugPaintPaddingInnerEdgeColor = _kDebugPaintPaddingInnerEdgeColor;
41 42

/// The color to use when painting the arrows used to show RenderPositionedBox alignment.
43
Color debugPaintArrowColor = _kDebugPaintArrowColor;
44

Adam Barth's avatar
Adam Barth committed
45
/// Causes each RenderBox to paint a line at each of its baselines.
46
bool debugPaintBaselinesEnabled = false;
Adam Barth's avatar
Adam Barth committed
47 48

/// The color to use when painting alphabetic baselines.
49
Color debugPaintAlphabeticBaselineColor = _kDebugPaintAlphabeticBaselineColor;
Adam Barth's avatar
Adam Barth committed
50 51

/// The color ot use when painting ideographic baselines.
52
Color debugPaintIdeographicBaselineColor = _kDebugPaintIdeographicBaselineColor;
53

Adam Barth's avatar
Adam Barth committed
54
/// Causes each Layer to paint a box around its bounds.
55
bool debugPaintLayerBordersEnabled = false;
Adam Barth's avatar
Adam Barth committed
56 57

/// The color to use when painting Layer borders.
58
Color debugPaintLayerBordersColor = _kDebugPaintLayerBordersColor;
59

60 61 62 63 64 65
/// Causes objects like [RenderPointerListener] to flash while they are being
/// tapped. This can be useful to see how large the hit box is, e.g. when
/// debugging buttons that are harder to hit than expected.
///
/// For details on how to support this in your [RenderBox] subclass, see
/// [RenderBox.debugHandleEvent].
66
bool debugPaintPointersEnabled = false;
67 68

/// The color to use when reporting pointers for [debugPaintPointersEnabled].
69
int debugPaintPointersColorValue = _kDebugPaintPointersColorValue;
70

71
/// Overlay a rotating set of colors when repainting layers in checked mode.
72
bool debugRepaintRainbowEnabled = false;
73 74

/// The current color to overlay when repainting a layer.
75
HSVColor debugCurrentRepaintColor = _kDebugCurrentRepaintColor;
76 77

/// The amount to increment the hue of the current repaint color.
78
double debugRepaintRainbowHueIncrement = _kDebugRepaintRainbowHueIncrement;
79

80 81 82 83
/// Log the call stacks that mark render objects as needing paint.
bool debugPrintMarkNeedsPaintStacks = false;

/// Log the call stacks that mark render objects as needing layout.
84 85 86 87 88
///
/// For sanity, this only logs the stack traces of cases where an object is
/// added to the list of nodes needing layout. This avoids printing multiple
/// redundant stack traces as a single [RenderObject.markNeedsLayout] call walks
/// up the tree.
89 90
bool debugPrintMarkNeedsLayoutStacks = false;

91 92 93
/// Check the intrinsic sizes of each [RenderBox] during layout.
bool debugCheckIntrinsicSizes = false;

94 95 96 97 98 99 100
/// Adds [Timeline] events for every RenderObject painted.
///
/// For details on how to use [Timeline] events in the Dart Observatory to
/// optimize your app, see https://fuchsia.googlesource.com/sysui/+/master/docs/performance.md
bool debugProfilePaintsEnabled = false;


101
/// Returns a list of strings representing the given transform in a format useful for [RenderObject.debugFillDescription].
102 103 104 105 106
List<String> debugDescribeTransform(Matrix4 transform) {
  List<String> matrix = transform.toString().split('\n').map((String s) => '  $s').toList();
  matrix.removeLast();
  return matrix;
}
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

/// Returns true if none of the rendering library debug variables have been changed.
///
/// This function is used by the test framework to ensure that debug variables
/// haven't been inadvertently changed.
///
/// See [https://docs.flutter.io/flutter/rendering/rendering-library.html] for
/// a complete list.
bool debugAssertAllRenderVarsUnset(String reason) {
  assert(() {
    if (debugPaintSizeEnabled ||
        debugPaintBaselinesEnabled ||
        debugPaintLayerBordersEnabled ||
        debugPaintPointersEnabled ||
        debugRepaintRainbowEnabled ||
        debugPrintMarkNeedsPaintStacks ||
        debugPrintMarkNeedsLayoutStacks ||
        debugCheckIntrinsicSizes ||
        debugProfilePaintsEnabled ||
        debugPaintSizeColor != _kDebugPaintSizeColor ||
        debugPaintSpacingColor != _kDebugPaintSpacingColor ||
        debugPaintPaddingColor != _kDebugPaintPaddingColor ||
        debugPaintPaddingInnerEdgeColor != _kDebugPaintPaddingInnerEdgeColor ||
        debugPaintArrowColor != _kDebugPaintArrowColor ||
        debugPaintAlphabeticBaselineColor != _kDebugPaintAlphabeticBaselineColor ||
        debugPaintIdeographicBaselineColor != _kDebugPaintIdeographicBaselineColor ||
        debugPaintLayerBordersColor != _kDebugPaintLayerBordersColor ||
        debugPaintPointersColorValue != _kDebugPaintPointersColorValue ||
        debugCurrentRepaintColor != _kDebugCurrentRepaintColor ||
        debugRepaintRainbowHueIncrement != _kDebugRepaintRainbowHueIncrement) {
      throw new FlutterError(reason);
    }
    return true;
  });
  return true;
}