diff --git a/packages/flutter/lib/src/rendering/block.dart b/packages/flutter/lib/src/rendering/block.dart index 59315662bf..86acf59d0d 100644 --- a/packages/flutter/lib/src/rendering/block.dart +++ b/packages/flutter/lib/src/rendering/block.dart @@ -77,11 +77,11 @@ class RenderBlock extends RenderBox assert(() { switch (mainAxis) { case Axis.horizontal: - if (constraints.maxWidth.isInfinite) + if (!constraints.hasBoundedWidth) return true; break; case Axis.vertical: - if (constraints.maxHeight.isInfinite) + if (!constraints.hasBoundedHeight) return true; break; } @@ -97,11 +97,11 @@ class RenderBlock extends RenderBox assert(() { switch (mainAxis) { case Axis.horizontal: - if (!constraints.maxHeight.isInfinite) + if (constraints.hasBoundedHeight) return true; break; case Axis.vertical: - if (!constraints.maxWidth.isInfinite) + if (constraints.hasBoundedWidth) return true; break; } diff --git a/packages/flutter/lib/src/rendering/box.dart b/packages/flutter/lib/src/rendering/box.dart index 4a26e5d79e..db4e8a7f4e 100644 --- a/packages/flutter/lib/src/rendering/box.dart +++ b/packages/flutter/lib/src/rendering/box.dart @@ -916,19 +916,22 @@ abstract class RenderBox extends RenderObject { return result; } - final double minIntrinsicWidth = testIntrinsic(getMinIntrinsicWidth, 'getMinIntrinsicWidth', constraints.maxWidth); - final double maxIntrinsicWidth = testIntrinsic(getMaxIntrinsicWidth, 'getMaxIntrinsicWidth', constraints.maxWidth); - if (minIntrinsicWidth > maxIntrinsicWidth) { - failures.writeln(' * getMinIntrinsicWidth(${constraints.maxWidth}) returned a larger value ($minIntrinsicWidth) than getMaxIntrinsicWidth(${constraints.maxWidth}) ($maxIntrinsicWidth)'); - failureCount += 1; - } - final double minIntrinsicHeight = testIntrinsic(getMinIntrinsicHeight, 'getMinIntrinsicHeight', constraints.maxHeight); - final double maxIntrinsicHeight = testIntrinsic(getMaxIntrinsicHeight, 'getMaxIntrinsicHeight', constraints.maxHeight); - if (minIntrinsicHeight > maxIntrinsicHeight) { - failures.writeln(' * getMinIntrinsicHeight(${constraints.maxHeight}) returned a larger value ($minIntrinsicHeight) than getMaxIntrinsicHeight(${constraints.maxHeight}) ($maxIntrinsicHeight)'); - failureCount += 1; + void testIntrinsicsForValues(double getMin(double extent), double getMax(double extent), String name, double constraint) { + final double min = testIntrinsic(getMin, 'getMinIntrinsic$name', constraint); + final double max = testIntrinsic(getMax, 'getMaxIntrinsic$name', constraint); + if (min > max) { + failures.writeln(' * getMinIntrinsic$name($constraint) returned a larger value ($min) than getMaxIntrinsic$name($constraint) ($max)'); + failureCount += 1; + } } + testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', double.INFINITY); + testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', double.INFINITY); + if (constraints.hasBoundedWidth) + testIntrinsicsForValues(getMinIntrinsicWidth, getMaxIntrinsicWidth, 'Width', constraints.maxWidth); + if (constraints.hasBoundedHeight) + testIntrinsicsForValues(getMinIntrinsicHeight, getMaxIntrinsicHeight, 'Height', constraints.maxHeight); + // TODO(ianh): Test that values are internally consistent in more ways than the above. RenderObject.debugCheckingIntrinsics = false; diff --git a/packages/flutter/lib/src/rendering/grid.dart b/packages/flutter/lib/src/rendering/grid.dart index 550f8d8642..1e8811539e 100644 --- a/packages/flutter/lib/src/rendering/grid.dart +++ b/packages/flutter/lib/src/rendering/grid.dart @@ -179,40 +179,77 @@ abstract class GridDelegate { return getGridSpecification(constraints, childCount).gridSize; } + // TODO(ianh): It's a bit dubious to be using the getSize function from the delegate to + // figure out the intrinsic dimensions. We really should either not support intrinsics, + // or we should expose intrinsic delegate callbacks and throw if they're not implemented. + /// Returns the minimum width that this grid could be without failing to paint /// its contents within itself. /// + /// Override this to provide a more efficient solution. The default + /// implementation actually instantiates a grid specification and measures the + /// grid at the given height and child count. + /// /// For more details, see [RenderBox.getMinIntrinsicWidth]. double getMinIntrinsicWidth(double height, int childCount) { - return _getGridSize(new BoxConstraints.tightForFinite(height: height), childCount).width; + final double width = _getGridSize(new BoxConstraints.tightForFinite(height: height), childCount).width; + if (width.isFinite) + return width; + return 0.0; } /// Returns the smallest width beyond which increasing the width never /// decreases the preferred height. /// + /// Override this to provide a more efficient solution. The default + /// implementation actually instantiates a grid specification and measures the + /// grid at the given height and child count. + /// /// For more details, see [RenderBox.getMaxIntrinsicWidth]. double getMaxIntrinsicWidth(double height, int childCount) { - return _getGridSize(new BoxConstraints.tightForFinite(height: height), childCount).width; + final double width = _getGridSize(new BoxConstraints.tightForFinite(height: height), childCount).width; + if (width.isFinite) + return width; + return 0.0; } /// Return the minimum height that this grid could be without failing to paint /// its contents within itself. /// + /// Override this to provide a more efficient solution. The default + /// implementation actually instantiates a grid specification and measures the + /// grid at the given width and child count. + /// /// For more details, see [RenderBox.getMinIntrinsicHeight]. double getMinIntrinsicHeight(double width, int childCount) { - return _getGridSize(new BoxConstraints.tightForFinite(width: width), childCount).height; + final double height = _getGridSize(new BoxConstraints.tightForFinite(width: width), childCount).height; + if (height.isFinite) + return height; + return 0.0; } /// Returns the smallest height beyond which increasing the height never /// decreases the preferred width. /// + /// Override this to provide a more efficient solution. The default + /// implementation actually instantiates a grid specification and measures the + /// grid at the given width and child count. + /// /// For more details, see [RenderBox.getMaxIntrinsicHeight]. double getMaxIntrinsicHeight(double width, int childCount) { - return _getGridSize(new BoxConstraints.tightForFinite(width: width), childCount).height; + final double height = _getGridSize(new BoxConstraints.tightForFinite(width: width), childCount).height; + if (height.isFinite) + return height; + return 0.0; } } /// A [GridDelegate] the places its children in order throughout the grid. +/// +/// Subclasses must still provide a mechanism for sizing the grid by +/// implementing [getGridSpecification], and should also provide efficent +/// versions of the intrinsic sizing functions ([getMinIntrinsicWidth] and +/// company). abstract class GridDelegateWithInOrderChildPlacement extends GridDelegate { /// Initializes [columnSpacing], [rowSpacing], and [padding] for subclasses. /// @@ -254,7 +291,7 @@ abstract class GridDelegateWithInOrderChildPlacement extends GridDelegate { } -/// A [GridDelegate] that divides the grid's width evenly amount a fixed number of columns. +/// A [GridDelegate] that divides the grid's width evenly for a fixed number of columns. class FixedColumnCountGridDelegate extends GridDelegateWithInOrderChildPlacement { /// Creates a grid delegate that uses a fixed column count. /// @@ -302,13 +339,17 @@ class FixedColumnCountGridDelegate extends GridDelegateWithInOrderChildPlacement @override double getMinIntrinsicWidth(double height, int childCount) { + // TODO(ianh): Strictly, this should examine the children. return 0.0; } @override double getMaxIntrinsicWidth(double height, int childCount) { + // TODO(ianh): Strictly, this should examine the children. return 0.0; } + + // TODO(ianh): Provide efficient intrinsic height functions. } /// A [GridDelegate] that fills the width with a variable number of tiles. @@ -318,7 +359,6 @@ class FixedColumnCountGridDelegate extends GridDelegateWithInOrderChildPlacement /// /// - The tile width evenly divides the width of the grid. /// - The tile width is at most [maxTileWidth]. -/// class MaxTileWidthGridDelegate extends GridDelegateWithInOrderChildPlacement { /// Creates a grid delegate that uses a max tile width. /// @@ -342,7 +382,18 @@ class MaxTileWidthGridDelegate extends GridDelegateWithInOrderChildPlacement { @override GridSpecification getGridSpecification(BoxConstraints constraints, int childCount) { - assert(constraints.maxWidth < double.INFINITY); + if (!constraints.maxWidth.isFinite) { + // if we're unbounded, just shrink-wrap around a single line of tiles + return new GridSpecification.fromRegularTiles( + tileWidth: maxTileWidth, + tileHeight: maxTileWidth / tileAspectRatio, + columnCount: childCount, + rowCount: 1, + columnSpacing: columnSpacing, + rowSpacing: rowSpacing, + padding: padding + ); + } final double gridWidth = math.max(0.0, constraints.maxWidth - padding.horizontal); int columnCount = (gridWidth / maxTileWidth).ceil(); int rowCount = (childCount / columnCount).ceil(); @@ -368,6 +419,7 @@ class MaxTileWidthGridDelegate extends GridDelegateWithInOrderChildPlacement { @override double getMinIntrinsicWidth(double height, int childCount) { + // TODO(ianh): Strictly, this should examine the children. return 0.0; } @@ -375,6 +427,8 @@ class MaxTileWidthGridDelegate extends GridDelegateWithInOrderChildPlacement { double getMaxIntrinsicWidth(double height, int childCount) { return maxTileWidth * childCount; } + + // TODO(ianh): Provide efficient intrinsic height functions. } /// Parent data for use with [RenderGrid] diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index d2515ed158..5d4201547c 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -554,7 +554,7 @@ class RenderIntrinsicWidth extends RenderProxyBox { if (child == null) return 0.0; double childResult = child.getMaxIntrinsicWidth(height); - assert(!childResult.isInfinite); + assert(childResult.isFinite); return _applyStep(childResult, _stepWidth); } diff --git a/packages/flutter/lib/src/rendering/table.dart b/packages/flutter/lib/src/rendering/table.dart index ebf186a8c9..7e0b43d144 100644 --- a/packages/flutter/lib/src/rendering/table.dart +++ b/packages/flutter/lib/src/rendering/table.dart @@ -717,7 +717,7 @@ class RenderTable extends RenderBox { // winner of the 2016 world's most expensive intrinsic dimension function award // honorable mention, most likely to improve if taught about memoization award assert(_children.length == rows * columns); - final List widths = _computeColumnWidths(constraints); + final List widths = _computeColumnWidths(new BoxConstraints.tightForFinite(width: width)); double rowTop = 0.0; for (int y = 0; y < rows; y += 1) { double rowHeight = 0.0; @@ -773,6 +773,7 @@ class RenderTable extends RenderBox { } List _computeColumnWidths(BoxConstraints constraints) { + assert(constraints != null); assert(_children.length == rows * columns); // We apply the constraints to the column widths in the order of // least important to most important: