flex.dart 24.1 KB
Newer Older
1 2 3 4 5 6
// 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.

import 'dart:math' as math;

7 8
import 'box.dart';
import 'object.dart';
9

10
/// Parent data for use with [RenderFlex]
Hixie's avatar
Hixie committed
11
class FlexParentData extends ContainerBoxParentDataMixin<RenderBox> {
12 13 14 15 16 17
  /// The flex factor to use for this child
  ///
  /// If null, the child is inflexible and determines its own size. If non-null,
  /// the child is flexible and its extent in the main axis is determined by
  /// dividing the free space (after placing the inflexible children)
  /// according to the flex factors of the flexible children.
18 19
  int flex;

20
  @override
21 22 23
  String toString() => '${super.toString()}; flex=$flex';
}

24 25 26 27 28 29 30
/// The direction in which the box should flex
enum FlexDirection {
  /// Children are arranged horizontally, from left to right
  horizontal,
  /// Children are arranged vertically, from top to bottom
  vertical
}
31

32
/// How the children should be placed along the main axis in a flex layout
33
enum MainAxisAlignment {
34
  /// Place the children as close to the start of the main axis as possible
35
  start,
36
  /// Place the children as close to the end of the main axis as possible
37
  end,
38
  /// Place the children as close to the middle of the main axis as possible
39
  center,
40
  /// Place the free space evenly between the children
41
  spaceBetween,
42
  /// Place the free space evenly between the children as well as before and after the first and last child
43
  spaceAround,
44 45
  /// Do not expand to fill the free space. None of the children may specify a flex factor.
  collapse,
46 47
}

48
/// How the children should be placed along the cross axis in a flex layout
49
enum CrossAxisAlignment {
50
  /// Place the children as close to the start of the cross axis as possible
51
  start,
52
  /// Place the children as close to the end of the cross axis as possible
53
  end,
54
  /// Place the children as close to the middle of the cross axis as possible
55
  center,
56
  /// Require the children to fill the cross axis
57
  stretch,
58
  /// Place the children along the cross axis such that their baselines match
59
  baseline,
60 61 62 63
}

typedef double _ChildSizingFunction(RenderBox child, BoxConstraints constraints);

64 65 66 67 68 69 70 71 72 73
/// Implements the flex layout algorithm
///
/// In flex layout, children are arranged linearly along the main axis (either
/// horizontally or vertically). First, inflexible children (those with a null
/// flex factor) are allocated space along the main axis. If the flex is given
/// unlimited space in the main axis, the flex sizes its main axis to the total
/// size of the inflexible children along the main axis and forbids flexible
/// children. Otherwise, the flex expands to the maximum max-axis size and the
/// remaining space along is divided among the flexible children according to
/// their flex factors. Any remaining free space (i.e., if there aren't any
74
/// flexible children) is allocated according to the [mainAxisAlignment] property.
75 76 77
///
/// In the cross axis, children determine their own size. The flex then sizes
/// its cross axis to fix the largest of its children. The children are then
78
/// positioned along the cross axis according to the [crossAxisAlignment] property.
79 80
class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, FlexParentData>,
                                        RenderBoxContainerDefaultsMixin<RenderBox, FlexParentData> {
81 82

  RenderFlex({
83
    List<RenderBox> children,
84
    FlexDirection direction: FlexDirection.horizontal,
85 86
    MainAxisAlignment mainAxisAlignment: MainAxisAlignment.start,
    CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center,
87
    TextBaseline textBaseline
88
  }) : _direction = direction,
89 90
       _mainAxisAlignment = mainAxisAlignment,
       _crossAxisAlignment = crossAxisAlignment,
91
       _textBaseline = textBaseline {
92 93 94
    addAll(children);
  }

95
  /// The direction to use as the main axis
96
  FlexDirection get direction => _direction;
97
  FlexDirection _direction;
98 99 100 101 102 103 104
  void set direction (FlexDirection value) {
    if (_direction != value) {
      _direction = value;
      markNeedsLayout();
    }
  }

105
  /// How the children should be placed along the main axis
106 107 108 109 110
  MainAxisAlignment get mainAxisAlignment => _mainAxisAlignment;
  MainAxisAlignment _mainAxisAlignment;
  void set mainAxisAlignment (MainAxisAlignment value) {
    if (_mainAxisAlignment != value) {
      _mainAxisAlignment = value;
111 112 113 114
      markNeedsLayout();
    }
  }

115
  /// How the children should be placed along the cross axis
116 117 118 119 120
  CrossAxisAlignment get crossAxisAlignment => _crossAxisAlignment;
  CrossAxisAlignment _crossAxisAlignment;
  void set crossAxisAlignment (CrossAxisAlignment value) {
    if (_crossAxisAlignment != value) {
      _crossAxisAlignment = value;
121 122 123 124
      markNeedsLayout();
    }
  }

125
  /// If using aligning items according to their baseline, which baseline to use
126
  TextBaseline get textBaseline => _textBaseline;
127
  TextBaseline _textBaseline;
128 129 130 131 132 133 134
  void set textBaseline (TextBaseline value) {
    if (_textBaseline != value) {
      _textBaseline = value;
      markNeedsLayout();
    }
  }

135
  /// Set during layout if overflow occurred on the main axis
136
  double _overflow;
137

138
  @override
139
  void setupParentData(RenderBox child) {
140 141
    if (child.parentData is! FlexParentData)
      child.parentData = new FlexParentData();
142 143 144 145 146
  }

  double _getIntrinsicSize({ BoxConstraints constraints,
                             FlexDirection sizingDirection,
                             _ChildSizingFunction childSize }) {
Hixie's avatar
Hixie committed
147
    assert(constraints.debugAssertIsNormalized);
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    // http://www.w3.org/TR/2015/WD-css-flexbox-1-20150514/#intrinsic-sizes
    if (_direction == sizingDirection) {
      // INTRINSIC MAIN SIZE
      // Intrinsic main size is the smallest size the flex container can take
      // while maintaining the min/max-content contributions of its flex items.
      BoxConstraints childConstraints;
      switch(_direction) {
        case FlexDirection.horizontal:
          childConstraints = new BoxConstraints(maxHeight: constraints.maxHeight);
          break;
        case FlexDirection.vertical:
          childConstraints = new BoxConstraints(maxWidth: constraints.maxWidth);
          break;
      }

      double totalFlex = 0.0;
      double inflexibleSpace = 0.0;
      double maxFlexFractionSoFar = 0.0;
      RenderBox child = firstChild;
      while (child != null) {
        int flex = _getFlex(child);
        totalFlex += flex;
        if (flex > 0) {
          double flexFraction = childSize(child, childConstraints) / _getFlex(child);
          maxFlexFractionSoFar = math.max(maxFlexFractionSoFar, flexFraction);
        } else {
          inflexibleSpace += childSize(child, childConstraints);
        }
Hixie's avatar
Hixie committed
176 177
        final FlexParentData childParentData = child.parentData;
        child = childParentData.nextSibling;
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
      }
      double mainSize = maxFlexFractionSoFar * totalFlex + inflexibleSpace;

      // Ensure that we don't violate the given constraints with our result
      switch(_direction) {
        case FlexDirection.horizontal:
          return constraints.constrainWidth(mainSize);
        case FlexDirection.vertical:
          return constraints.constrainHeight(mainSize);
      }
    } else {
      // INTRINSIC CROSS SIZE
      // The spec wants us to perform layout into the given available main-axis
      // space and return the cross size. That's too expensive, so instead we
      // size inflexible children according to their max intrinsic size in the
      // main direction and use those constraints to determine their max
      // intrinsic size in the cross direction. We don't care if the caller
      // asked for max or min -- the answer is always computed using the
      // max size in the main direction.

      double availableMainSpace;
      BoxConstraints childConstraints;
      switch(_direction) {
        case FlexDirection.horizontal:
202
          childConstraints = new BoxConstraints(maxHeight: constraints.maxHeight);
203 204 205
          availableMainSpace = constraints.maxWidth;
          break;
        case FlexDirection.vertical:
206
          childConstraints = new BoxConstraints(maxWidth: constraints.maxWidth);
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
          availableMainSpace = constraints.maxHeight;
          break;
      }

      // Get inflexible space using the max in the main direction
      int totalFlex = 0;
      double inflexibleSpace = 0.0;
      double maxCrossSize = 0.0;
      RenderBox child = firstChild;
      while (child != null) {
        int flex = _getFlex(child);
        totalFlex += flex;
        double mainSize;
        double crossSize;
        if (flex == 0) {
          switch (_direction) {
              case FlexDirection.horizontal:
                mainSize = child.getMaxIntrinsicWidth(childConstraints);
                BoxConstraints widthConstraints =
                  new BoxConstraints(minWidth: mainSize, maxWidth: mainSize);
                crossSize = child.getMaxIntrinsicHeight(widthConstraints);
                break;
              case FlexDirection.vertical:
                mainSize = child.getMaxIntrinsicHeight(childConstraints);
                BoxConstraints heightConstraints =
                  new BoxConstraints(minWidth: mainSize, maxWidth: mainSize);
                crossSize = child.getMaxIntrinsicWidth(heightConstraints);
                break;
          }
          inflexibleSpace += mainSize;
          maxCrossSize = math.max(maxCrossSize, crossSize);
        }
Hixie's avatar
Hixie committed
239 240
        final FlexParentData childParentData = child.parentData;
        child = childParentData.nextSibling;
241 242 243
      }

      // Determine the spacePerFlex by allocating the remaining available space
244 245 246
      // When you're overconstrained spacePerFlex can be negative.
      double spacePerFlex = math.max(0.0,
          (availableMainSpace - inflexibleSpace) / totalFlex);
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268

      // Size remaining items, find the maximum cross size
      child = firstChild;
      while (child != null) {
        int flex = _getFlex(child);
        if (flex > 0) {
          double childMainSize = spacePerFlex * flex;
          double crossSize;
          switch (_direction) {
            case FlexDirection.horizontal:
              BoxConstraints childConstraints =
                new BoxConstraints(minWidth: childMainSize, maxWidth: childMainSize);
              crossSize = child.getMaxIntrinsicHeight(childConstraints);
              break;
            case FlexDirection.vertical:
              BoxConstraints childConstraints =
                new BoxConstraints(minHeight: childMainSize, maxHeight: childMainSize);
              crossSize = child.getMaxIntrinsicWidth(childConstraints);
              break;
          }
          maxCrossSize = math.max(maxCrossSize, crossSize);
        }
Hixie's avatar
Hixie committed
269 270
        final FlexParentData childParentData = child.parentData;
        child = childParentData.nextSibling;
271 272 273 274 275 276 277 278 279 280 281 282
      }

      // Ensure that we don't violate the given constraints with our result
      switch(_direction) {
        case FlexDirection.horizontal:
          return constraints.constrainHeight(maxCrossSize);
        case FlexDirection.vertical:
          return constraints.constrainWidth(maxCrossSize);
      }
    }
  }

283
  @override
284 285 286 287
  double getMinIntrinsicWidth(BoxConstraints constraints) {
    return _getIntrinsicSize(
      constraints: constraints,
      sizingDirection: FlexDirection.horizontal,
Hixie's avatar
Hixie committed
288
      childSize: (RenderBox child, BoxConstraints innerConstraints) => child.getMinIntrinsicWidth(innerConstraints)
289 290 291
    );
  }

292
  @override
293 294 295 296
  double getMaxIntrinsicWidth(BoxConstraints constraints) {
    return _getIntrinsicSize(
      constraints: constraints,
      sizingDirection: FlexDirection.horizontal,
Hixie's avatar
Hixie committed
297
      childSize: (RenderBox child, BoxConstraints innerConstraints) => child.getMaxIntrinsicWidth(innerConstraints)
298 299 300
    );
  }

301
  @override
302 303 304 305
  double getMinIntrinsicHeight(BoxConstraints constraints) {
    return _getIntrinsicSize(
      constraints: constraints,
      sizingDirection: FlexDirection.vertical,
Hixie's avatar
Hixie committed
306
      childSize: (RenderBox child, BoxConstraints innerConstraints) => child.getMinIntrinsicHeight(innerConstraints)
307 308 309
    );
  }

310
  @override
311 312 313 314
  double getMaxIntrinsicHeight(BoxConstraints constraints) {
    return _getIntrinsicSize(
      constraints: constraints,
      sizingDirection: FlexDirection.vertical,
Hixie's avatar
Hixie committed
315
      childSize: (RenderBox child, BoxConstraints innerConstraints) => child.getMaxIntrinsicHeight(innerConstraints));
316 317
  }

318
  @override
319 320 321 322 323 324 325
  double computeDistanceToActualBaseline(TextBaseline baseline) {
    if (_direction == FlexDirection.horizontal)
      return defaultComputeDistanceToHighestActualBaseline(baseline);
    return defaultComputeDistanceToFirstActualBaseline(baseline);
  }

  int _getFlex(RenderBox child) {
Hixie's avatar
Hixie committed
326 327
    final FlexParentData childParentData = child.parentData;
    return childParentData.flex != null ? childParentData.flex : 0;
328 329 330 331 332 333 334 335 336 337
  }

  double _getCrossSize(RenderBox child) {
    return (_direction == FlexDirection.horizontal) ? child.size.height : child.size.width;
  }

  double _getMainSize(RenderBox child) {
    return (_direction == FlexDirection.horizontal) ? child.size.width : child.size.height;
  }

338
  @override
339
  void performLayout() {
340 341 342
    // Originally based on http://www.w3.org/TR/css-flexbox-1/ Section 9.7 Resolving Flexible Lengths

    // Determine used flex factor, size inflexible items, calculate free space.
343 344 345
    int totalFlex = 0;
    int totalChildren = 0;
    assert(constraints != null);
346
    final double mainSize = (_direction == FlexDirection.horizontal) ? constraints.constrainWidth() : constraints.constrainHeight();
347
    final bool canFlex = mainSize < double.INFINITY && mainAxisAlignment != MainAxisAlignment.collapse;
348 349
    double crossSize = 0.0;  // This is determined as we lay out the children
    double freeSpace = canFlex ? mainSize : 0.0;
350 351
    RenderBox child = firstChild;
    while (child != null) {
Hixie's avatar
Hixie committed
352
      final FlexParentData childParentData = child.parentData;
353 354 355
      totalChildren++;
      int flex = _getFlex(child);
      if (flex > 0) {
356
        // Flexible children can only be used when the RenderFlex box's container has a finite size.
Hans Muller's avatar
Hans Muller committed
357
        // When the container is infinite, for example if you are in a scrollable viewport, then
358
        // it wouldn't make any sense to have a flexible child.
Seth Ladd's avatar
Seth Ladd committed
359
        assert(canFlex && 'See https://flutter.io/layout/#flex' is String);
Hixie's avatar
Hixie committed
360
        totalFlex += childParentData.flex;
361 362
      } else {
        BoxConstraints innerConstraints;
363
        if (crossAxisAlignment == CrossAxisAlignment.stretch) {
364 365
          switch (_direction) {
            case FlexDirection.horizontal:
366
              innerConstraints = new BoxConstraints(minHeight: constraints.maxHeight,
367 368 369
                                                    maxHeight: constraints.maxHeight);
              break;
            case FlexDirection.vertical:
370
              innerConstraints = new BoxConstraints(minWidth: constraints.maxWidth,
371
                                                    maxWidth: constraints.maxWidth);
372 373 374
              break;
          }
        } else {
375 376 377 378 379 380 381 382
          switch (_direction) {
            case FlexDirection.horizontal:
              innerConstraints = new BoxConstraints(maxHeight: constraints.maxHeight);
              break;
            case FlexDirection.vertical:
              innerConstraints = new BoxConstraints(maxWidth: constraints.maxWidth);
              break;
          }
383 384 385 386 387
        }
        child.layout(innerConstraints, parentUsesSize: true);
        freeSpace -= _getMainSize(child);
        crossSize = math.max(crossSize, _getCrossSize(child));
      }
Hixie's avatar
Hixie committed
388 389
      assert(child.parentData == childParentData);
      child = childParentData.nextSibling;
390
    }
391 392
    _overflow = math.max(0.0, -freeSpace);
    freeSpace = math.max(0.0, freeSpace);
393

394
    // Distribute remaining space to flexible children, and determine baseline.
395
    double maxBaselineDistance = 0.0;
396
    double usedSpace = 0.0;
397
    if (totalFlex > 0 || crossAxisAlignment == CrossAxisAlignment.baseline) {
398 399 400 401 402 403 404
      double spacePerFlex = totalFlex > 0 ? (freeSpace / totalFlex) : 0.0;
      child = firstChild;
      while (child != null) {
        int flex = _getFlex(child);
        if (flex > 0) {
          double spaceForChild = spacePerFlex * flex;
          BoxConstraints innerConstraints;
405
          if (crossAxisAlignment == CrossAxisAlignment.stretch) {
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
            switch (_direction) {
              case FlexDirection.horizontal:
                innerConstraints = new BoxConstraints(minWidth: spaceForChild,
                                                      maxWidth: spaceForChild,
                                                      minHeight: constraints.maxHeight,
                                                      maxHeight: constraints.maxHeight);
                break;
              case FlexDirection.vertical:
                innerConstraints = new BoxConstraints(minWidth: constraints.maxWidth,
                                                      maxWidth: constraints.maxWidth,
                                                      minHeight: spaceForChild,
                                                      maxHeight: spaceForChild);
                break;
            }
          } else {
            switch (_direction) {
              case FlexDirection.horizontal:
                innerConstraints = new BoxConstraints(minWidth: spaceForChild,
                                                      maxWidth: spaceForChild,
                                                      maxHeight: constraints.maxHeight);
                break;
              case FlexDirection.vertical:
                innerConstraints = new BoxConstraints(maxWidth: constraints.maxWidth,
                                                      minHeight: spaceForChild,
                                                      maxHeight: spaceForChild);
                break;
            }
433
          }
434 435 436
          child.layout(innerConstraints, parentUsesSize: true);
          usedSpace += _getMainSize(child);
          crossSize = math.max(crossSize, _getCrossSize(child));
437
        }
438
        if (crossAxisAlignment == CrossAxisAlignment.baseline) {
439
          assert(textBaseline != null && 'To use FlexAlignItems.baseline, you must also specify which baseline to use using the "baseline" argument.' is String);
440 441 442 443
          double distance = child.getDistanceToBaseline(textBaseline, onlyReal: true);
          if (distance != null)
            maxBaselineDistance = math.max(maxBaselineDistance, distance);
        }
Hixie's avatar
Hixie committed
444 445
        final FlexParentData childParentData = child.parentData;
        child = childParentData.nextSibling;
446
      }
447 448
    }

449
    // Align items along the main axis.
450 451
    double leadingSpace;
    double betweenSpace;
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
    double remainingSpace;
    if (canFlex) {
      remainingSpace = math.max(0.0, freeSpace - usedSpace);
      switch (_direction) {
        case FlexDirection.horizontal:
          size = constraints.constrain(new Size(mainSize, crossSize));
          crossSize = size.height;
          assert(size.width == mainSize);
          break;
        case FlexDirection.vertical:
          size = constraints.constrain(new Size(crossSize, mainSize));
          crossSize = size.width;
          assert(size.height == mainSize);
          break;
      }
    } else {
      leadingSpace = 0.0;
      betweenSpace = 0.0;
      switch (_direction) {
        case FlexDirection.horizontal:
472
          size = constraints.constrain(new Size(_overflow, crossSize));
473
          crossSize = size.height;
474
          remainingSpace = math.max(0.0, size.width - _overflow);
475 476
          break;
        case FlexDirection.vertical:
477
          size = constraints.constrain(new Size(crossSize, _overflow));
478
          crossSize = size.width;
479
          remainingSpace = math.max(0.0, size.height - _overflow);
480 481 482 483
          break;
      }
      _overflow = 0.0;
    }
484 485 486
    switch (_mainAxisAlignment) {
      case MainAxisAlignment.start:
      case MainAxisAlignment.collapse:
487 488 489
        leadingSpace = 0.0;
        betweenSpace = 0.0;
        break;
490
      case MainAxisAlignment.end:
491 492 493
        leadingSpace = remainingSpace;
        betweenSpace = 0.0;
        break;
494
      case MainAxisAlignment.center:
495 496 497
        leadingSpace = remainingSpace / 2.0;
        betweenSpace = 0.0;
        break;
498
      case MainAxisAlignment.spaceBetween:
499 500 501
        leadingSpace = 0.0;
        betweenSpace = totalChildren > 1 ? remainingSpace / (totalChildren - 1) : 0.0;
        break;
502
      case MainAxisAlignment.spaceAround:
503 504 505 506 507
        betweenSpace = totalChildren > 0 ? remainingSpace / totalChildren : 0.0;
        leadingSpace = betweenSpace / 2.0;
        break;
    }

Collin Jackson's avatar
Collin Jackson committed
508
    // Position elements
509 510 511
    double childMainPosition = leadingSpace;
    child = firstChild;
    while (child != null) {
Hixie's avatar
Hixie committed
512
      final FlexParentData childParentData = child.parentData;
513
      double childCrossPosition;
514 515 516
      switch (_crossAxisAlignment) {
        case CrossAxisAlignment.stretch:
        case CrossAxisAlignment.start:
517 518
          childCrossPosition = 0.0;
          break;
519
        case CrossAxisAlignment.end:
520 521
          childCrossPosition = crossSize - _getCrossSize(child);
          break;
522
        case CrossAxisAlignment.center:
523 524
          childCrossPosition = crossSize / 2.0 - _getCrossSize(child) / 2.0;
          break;
525
        case CrossAxisAlignment.baseline:
526 527
          childCrossPosition = 0.0;
          if (_direction == FlexDirection.horizontal) {
528 529
            assert(textBaseline != null);
            double distance = child.getDistanceToBaseline(textBaseline, onlyReal: true);
530 531 532 533
            if (distance != null)
              childCrossPosition = maxBaselineDistance - distance;
          }
          break;
534 535 536
      }
      switch (_direction) {
        case FlexDirection.horizontal:
537
          childParentData.offset = new Offset(childMainPosition, childCrossPosition);
538 539
          break;
        case FlexDirection.vertical:
540
          childParentData.offset = new Offset(childCrossPosition, childMainPosition);
541 542 543
          break;
      }
      childMainPosition += _getMainSize(child) + betweenSpace;
Hixie's avatar
Hixie committed
544
      child = childParentData.nextSibling;
545 546 547
    }
  }

548
  @override
Adam Barth's avatar
Adam Barth committed
549 550
  bool hitTestChildren(HitTestResult result, { Point position }) {
    return defaultHitTestChildren(result, position: position);
551 552
  }

553
  @override
554
  void paint(PaintingContext context, Offset offset) {
555
    if (_overflow <= 0.0) {
556
      defaultPaint(context, offset);
557
      return;
558
    }
Collin Jackson's avatar
Collin Jackson committed
559

560
    // We have overflow. Clip it.
561 562
    context.pushClipRect(needsCompositing, offset, Point.origin & size, defaultPaint);

563 564 565 566 567 568 569 570 571 572 573
    assert(() {
      // In debug mode, if you have overflow, we highlight where the
      // overflow would be by painting that area red. Since that is
      // likely to be clipped by an ancestor, we also draw a thick red
      // line at the edge that's overflowing.

      // If you do want clipping, use a RenderClip (Clip in the
      // Widgets library).

      Paint markerPaint = new Paint()..color = const Color(0xE0FF0000);
      Paint highlightPaint = new Paint()..color = const Color(0x7FFF0000);
574
      const double kMarkerSize = 0.1;
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
      Rect markerRect, overflowRect;
      switch(direction) {
        case FlexDirection.horizontal:
          markerRect = offset + new Offset(size.width * (1.0 - kMarkerSize), 0.0) &
                       new Size(size.width * kMarkerSize, size.height);
          overflowRect = offset + new Offset(size.width, 0.0) &
                         new Size(_overflow, size.height);
          break;
        case FlexDirection.vertical:
          markerRect = offset + new Offset(0.0, size.height * (1.0 - kMarkerSize)) &
                       new Size(size.width, size.height * kMarkerSize);
          overflowRect = offset + new Offset(0.0, size.height) &
                         new Size(size.width, _overflow);
          break;
      }
      context.canvas.drawRect(markerRect, markerPaint);
      context.canvas.drawRect(overflowRect, highlightPaint);
      return true;
    });
  }
Collin Jackson's avatar
Collin Jackson committed
595

596
  @override
Hixie's avatar
Hixie committed
597 598
  Rect describeApproximatePaintClip(RenderObject child) => _overflow > 0.0 ? Point.origin & size : null;

599
  @override
600 601
  String toString() {
    String header = super.toString();
602
    if (_overflow is double && _overflow > 0.0)
603 604
      header += ' OVERFLOWING';
    return header;
Collin Jackson's avatar
Collin Jackson committed
605
  }
606

607
  @override
608 609 610
  void debugFillDescription(List<String> description) {
    super.debugFillDescription(description);
    description.add('direction: $_direction');
611 612
    description.add('mainAxisAlignment: $_mainAxisAlignment');
    description.add('crossAxisAlignment: $_crossAxisAlignment');
613
    description.add('textBaseline: $_textBaseline');
614
  }
615

616
}