提交 02b651f7 编写于 作者: H Hixie

Let's hide double.INFINITY a bit more, by providing cleaner APIs for the cases...

Let's hide double.INFINITY a bit more, by providing cleaner APIs for the cases where we're currently trying to use it.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1209233002.
上级 40dc0bdf
......@@ -63,7 +63,7 @@ HAL: This mission is too important for me to allow you to jeopardize it.''';
Component createSeparator() {
return new Container(
constraints: const BoxConstraints(minWidth: double.INFINITY, maxHeight: 0.0),
constraints: const BoxConstraints.expandWidth(maxHeight: 0.0),
margin: const EdgeDims.symmetric(vertical: 10.0, horizontal: 64.0),
decoration: const BoxDecoration(
border: const Border(
......
......@@ -39,8 +39,7 @@ class SkyDemo extends Component {
Widget build() {
return new ConstrainedBox(
// TOOD(ianh): Fix so we don't need INFINITY here.
constraints: new BoxConstraints.tightFor(width: double.INFINITY),
constraints: const BoxConstraints.expandWidth(),
child: new RaisedButton(
child: new Text(text),
onPressed: _handlePress
......
......@@ -95,8 +95,7 @@ class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, B
child = child.parentData.nextSibling;
}
size = new Size(width, constraints.constrainHeight(y));
assert(size.width < double.INFINITY);
assert(size.height < double.INFINITY);
assert(!size.isInfinite);
}
void hitTestChildren(HitTestResult result, { Point position }) {
......
......@@ -77,7 +77,7 @@ class BoxConstraints extends Constraints {
minHeight = size.height,
maxHeight = size.height;
BoxConstraints.tightFor({
const BoxConstraints.tightFor({
double width,
double height
}): minWidth = width != null ? width : 0.0,
......@@ -91,6 +91,25 @@ class BoxConstraints extends Constraints {
minHeight = 0.0,
maxHeight = size.height;
const BoxConstraints.expandWidth({
this.maxHeight: double.INFINITY
}): minWidth = double.INFINITY,
maxWidth = double.INFINITY,
minHeight = 0.0;
const BoxConstraints.expandHeight({
this.maxWidth: double.INFINITY
}): minWidth = 0.0,
minHeight = double.INFINITY,
maxHeight = double.INFINITY;
static const BoxConstraints expand = const BoxConstraints(
minWidth: double.INFINITY,
maxWidth: double.INFINITY,
minHeight: double.INFINITY,
maxHeight: double.INFINITY
);
BoxConstraints deflate(EdgeDims edges) {
assert(edges != null);
double horizontal = edges.left + edges.right;
......@@ -172,11 +191,11 @@ class BoxConstraints extends Constraints {
final double minHeight;
final double maxHeight;
double constrainWidth(double width) {
double constrainWidth([double width = double.INFINITY]) {
return clamp(min: minWidth, max: maxWidth, value: width);
}
double constrainHeight(double height) {
double constrainHeight([double height = double.INFINITY]) {
return clamp(min: minHeight, max: maxHeight, value: height);
}
......@@ -305,8 +324,7 @@ abstract class RenderBox extends RenderObject {
void performResize() {
// default behaviour for subclasses that have sizedByParent = true
size = constraints.constrain(Size.zero);
assert(size.height < double.INFINITY);
assert(size.width < double.INFINITY);
assert(!size.isInfinite);
}
void performLayout() {
// descendants have to either override performLayout() to set both
......@@ -1139,8 +1157,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
_orientation = _rootConstraints.orientation;
}
_size = new Size(_rootConstraints.width, _rootConstraints.height);
assert(_size.height < double.INFINITY);
assert(_size.width < double.INFINITY);
assert(!_size.isInfinite);
if (child != null)
child.layout(new BoxConstraints.tight(_size));
......
......@@ -70,7 +70,7 @@ class RenderStack extends RenderBox with ContainerRenderObjectMixin<RenderBox, S
child = child.parentData.nextSibling;
}
if (!hasNonPositionedChildren)
return constraints.constrainWidth(double.INFINITY);
return constraints.constrainWidth();
assert(width == constraints.constrainWidth(width));
return width;
}
......@@ -101,7 +101,7 @@ class RenderStack extends RenderBox with ContainerRenderObjectMixin<RenderBox, S
child = child.parentData.nextSibling;
}
if (!hasNonPositionedChildren)
return constraints.constrainHeight(double.INFINITY);
return constraints.constrainHeight();
assert(height == constraints.constrainHeight(height));
return height;
}
......@@ -140,8 +140,7 @@ class RenderStack extends RenderBox with ContainerRenderObjectMixin<RenderBox, S
else
size = constraints.constrain(Size.infinite);
assert(size.width < double.INFINITY);
assert(size.height < double.INFINITY);
assert(!size.isInfinite);
assert(size.width == constraints.constrainWidth(width));
assert(size.height == constraints.constrainHeight(height));
......
......@@ -290,10 +290,7 @@ class Container extends Component {
Widget current = child;
if (child == null && width == null && height == null)
current = new SizedBox(
width: double.INFINITY,
height: double.INFINITY
);
current = new ConstrainedBox(constraints: BoxConstraints.expand);
if (padding != null)
current = new Padding(padding: padding, child: current);
......
......@@ -78,8 +78,7 @@ class RenderScaffold extends RenderBox {
bool get sizedByParent => true;
void performResize() {
size = constraints.constrain(Size.infinite);
assert(size.width < double.INFINITY);
assert(size.height < double.INFINITY);
assert(!size.isInfinite);
}
// TODO(eseidel): These change based on device size!
......
......@@ -94,8 +94,7 @@ class RenderTabBar extends RenderBox with
assert(constraints is BoxConstraints);
size = constraints.constrain(new Size(constraints.maxWidth, _kTabBarHeight));
assert(size.width < double.INFINITY);
assert(size.height < double.INFINITY);
assert(!size.isInfinite);
int childCount = _childCount();
if (childCount == 0)
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:sky/widgets/basic.dart';
import 'package:sky/widgets/raised_button.dart';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册