提交 c4b64d74 编写于 作者: H Hixie

Rename Container's desiredSize argument to width and height arguments.

Also change SizedBox.

This makes the code that uses Container() and SizedBox() much more readable.

The underlying RenderSizedBox is not affected by this change.

R=abarth@chromium.org, eseidel@chromium.org

Review URL: https://codereview.chromium.org/1166203002
上级 7382a261
...@@ -24,13 +24,13 @@ class ContainerApp extends App { ...@@ -24,13 +24,13 @@ class ContainerApp extends App {
new Container( new Container(
padding: new EdgeDims.all(10.0), padding: new EdgeDims.all(10.0),
margin: new EdgeDims.all(10.0), margin: new EdgeDims.all(10.0),
desiredSize: new sky.Size(double.INFINITY, 100.0), height: 100.0,
decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF00FF00)), decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF00FF00)),
child: new BlockContainer( child: new BlockContainer(
children: [ children: [
new Container( new Container(
decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFFFFFF00)), decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFFFFFF00)),
desiredSize: new sky.Size(double.INFINITY, 20.0) height: 20.0,
), ),
new Image(src: "https://www.dartlang.org/logos/dart-logo.png", new Image(src: "https://www.dartlang.org/logos/dart-logo.png",
size: new sky.Size(300.0, 300.0), size: new sky.Size(300.0, 300.0),
......
...@@ -32,21 +32,21 @@ class StockRow extends Component { ...@@ -32,21 +32,21 @@ class StockRow extends Component {
// ), // ),
new FlexExpandingChild(new Text(stock.symbol)), new FlexExpandingChild(new Text(stock.symbol)),
new Container( new Container(
desiredSize: const sky.Size.fromWidth(75.0), width: 75.0,
padding: const EdgeDims.only(right: 16.0), padding: const EdgeDims.only(right: 16.0),
// text-align: right // text-align: right
child: new Text(lastSale) child: new Text(lastSale)
), ),
// text-align: right, ${typography.black.caption}; // text-align: right, ${typography.black.caption};
new SizedBox( new SizedBox(
desiredSize: const sky.Size.fromWidth(75.0), width: 75.0,
child: new Text(changeInPrice) child: new Text(changeInPrice)
), ),
]; ];
return new Container( return new Container(
padding: const EdgeDims(16.0, 16.0, 20.0, 16.0), padding: const EdgeDims(16.0, 16.0, 20.0, 16.0),
desiredSize: const sky.Size.fromHeight(kHeight), height: kHeight,
decoration: const BoxDecoration( decoration: const BoxDecoration(
backgroundColor: const sky.Color(0xFFFFFFFF), backgroundColor: const sky.Color(0xFFFFFFFF),
border: const Border( border: const Border(
......
...@@ -31,7 +31,8 @@ class Checkbox extends ButtonBase { ...@@ -31,7 +31,8 @@ class Checkbox extends ButtonBase {
return new EventListenerNode( return new EventListenerNode(
new Container( new Container(
margin: const EdgeDims.symmetric(horizontal: 5.0), margin: const EdgeDims.symmetric(horizontal: 5.0),
desiredSize: new sky.Size(edgeSize + 2.0, edgeSize + 2.0), width: edgeSize + 2.0,
height: edgeSize + 2.0,
child: new CustomPaint( child: new CustomPaint(
callback: (sky.Canvas canvas) { callback: (sky.Canvas canvas) {
......
...@@ -113,10 +113,7 @@ class Drawer extends AnimatedComponent { ...@@ -113,10 +113,7 @@ class Drawer extends AnimatedComponent {
Color maskColor = new Color(((_position / _kWidth + 1) * 0xFF).floor() << 24); Color maskColor = new Color(((_position / _kWidth + 1) * 0xFF).floor() << 24);
var mask = new EventListenerNode( var mask = new EventListenerNode(
new Container( new Container(decoration: new BoxDecoration(backgroundColor: maskColor)),
desiredSize: Size.infinite,
decoration: new BoxDecoration(backgroundColor: maskColor)
),
onGestureTap: controller.handleMaskTap, onGestureTap: controller.handleMaskTap,
onGestureFlingStart: controller.handleFlingStart onGestureFlingStart: controller.handleFlingStart
); );
...@@ -124,7 +121,7 @@ class Drawer extends AnimatedComponent { ...@@ -124,7 +121,7 @@ class Drawer extends AnimatedComponent {
Material content = new Material( Material content = new Material(
content: new Container( content: new Container(
decoration: new BoxDecoration(backgroundColor: new Color(0xFFFFFFFF)), decoration: new BoxDecoration(backgroundColor: new Color(0xFFFFFFFF)),
desiredSize: new Size.fromWidth(_kWidth), width: _kWidth,
transform: transform, transform: transform,
child: new BlockContainer(children: children) child: new BlockContainer(children: children)
), ),
......
...@@ -15,7 +15,7 @@ class DrawerHeader extends Component { ...@@ -15,7 +15,7 @@ class DrawerHeader extends Component {
UINode build() { UINode build() {
return new Container( return new Container(
key: 'drawer-header-outside', key: 'drawer-header-outside',
desiredSize: const Size.fromHeight(kStatusBarHeight + kMaterialDrawerHeight), height: kStatusBarHeight + kMaterialDrawerHeight,
decoration: new BoxDecoration( decoration: new BoxDecoration(
backgroundColor: BlueGrey[50], backgroundColor: BlueGrey[50],
border: const Border( border: const Border(
...@@ -31,10 +31,7 @@ class DrawerHeader extends Component { ...@@ -31,10 +31,7 @@ class DrawerHeader extends Component {
key: 'drawer-header-inside', key: 'drawer-header-inside',
direction: FlexDirection.vertical, direction: FlexDirection.vertical,
children: [ children: [
new FlexExpandingChild(new Container( new FlexExpandingChild(new Container(key: 'drawer-header-spacer')),
key: 'drawer-header-spacer',
desiredSize: Size.infinite
)),
new Container( new Container(
key: 'drawer-header-label', key: 'drawer-header-label',
padding: const EdgeDims.symmetric(horizontal: 16.0), padding: const EdgeDims.symmetric(horizontal: 16.0),
......
...@@ -31,7 +31,8 @@ class FloatingActionButton extends Component { ...@@ -31,7 +31,8 @@ class FloatingActionButton extends Component {
canvas.drawCircle(radius, radius, radius, new sky.Paint()..color = Red[500]); canvas.drawCircle(radius, radius, radius, new sky.Paint()..color = Red[500]);
}, },
child: new Container( child: new Container(
desiredSize: const sky.Size(_kSize, _kSize), width: _kSize,
height: _kSize,
child: new InkWell(children: children))), child: new InkWell(children: children))),
level: level); level: level);
} }
......
...@@ -9,6 +9,7 @@ class MenuDivider extends Component { ...@@ -9,6 +9,7 @@ class MenuDivider extends Component {
UINode build() { UINode build() {
return new Container( return new Container(
height: 0.0,
decoration: const BoxDecoration( decoration: const BoxDecoration(
border: const Border( border: const Border(
bottom: const BorderSide( bottom: const BorderSide(
......
...@@ -40,7 +40,7 @@ class MenuItem extends ButtonBase { ...@@ -40,7 +40,7 @@ class MenuItem extends ButtonBase {
) )
] ]
), ),
desiredSize: const Size.fromHeight(48.0), height: 48.0,
decoration: highlight ? highlightDecoration : null decoration: highlight ? highlightDecoration : null
), ),
onGestureTap: onGestureTap onGestureTap: onGestureTap
......
...@@ -33,7 +33,8 @@ class Radio extends ButtonBase { ...@@ -33,7 +33,8 @@ class Radio extends ButtonBase {
return new EventListenerNode( return new EventListenerNode(
new Container( new Container(
margin: const EdgeDims.symmetric(horizontal: 5.0), margin: const EdgeDims.symmetric(horizontal: 5.0),
desiredSize: new Size(diameter, diameter), width: diameter,
height: diameter,
child: new CustomPaint( child: new CustomPaint(
callback: (sky.Canvas canvas) { callback: (sky.Canvas canvas) {
......
...@@ -80,8 +80,8 @@ class RenderScaffold extends RenderBox { ...@@ -80,8 +80,8 @@ class RenderScaffold extends RenderBox {
static const kToolbarHeight = 100.0; static const kToolbarHeight = 100.0;
static const kStatusbarHeight = 50.0; static const kStatusbarHeight = 50.0;
static const kButtonX = -16.0; // from right edge of body static const kButtonX = 16.0; // left from right edge of body
static const kButtonY = -16.0; // from bottom edge of body static const kButtonY = 16.0; // up from bottom edge of body
void performLayout() { void performLayout() {
double bodyHeight = size.height; double bodyHeight = size.height;
...@@ -115,7 +115,7 @@ class RenderScaffold extends RenderBox { ...@@ -115,7 +115,7 @@ class RenderScaffold extends RenderBox {
} }
if (_slots[ScaffoldSlots.floatingActionButton] != null) { if (_slots[ScaffoldSlots.floatingActionButton] != null) {
RenderBox floatingActionButton = _slots[ScaffoldSlots.floatingActionButton]; RenderBox floatingActionButton = _slots[ScaffoldSlots.floatingActionButton];
Size area = new Size(size.width + kButtonX, size.height + kButtonY); Size area = new Size(size.width - kButtonX, size.height - kButtonY);
floatingActionButton.layout(new BoxConstraints.loose(area)); floatingActionButton.layout(new BoxConstraints.loose(area));
assert(floatingActionButton.parentData is BoxParentData); assert(floatingActionButton.parentData is BoxParentData);
floatingActionButton.parentData.position = (area - floatingActionButton.size).toPoint(); floatingActionButton.parentData.position = (area - floatingActionButton.size).toPoint();
......
...@@ -38,7 +38,7 @@ class ToolBar extends Component { ...@@ -38,7 +38,7 @@ class ToolBar extends Component {
children: children, children: children,
direction: FlexDirection.horizontal direction: FlexDirection.horizontal
), ),
desiredSize: new Size.fromHeight(56.0), height: 56.0,
padding: new EdgeDims(kStatusBarHeight.toDouble(), 8.0, 0.0, 8.0), padding: new EdgeDims(kStatusBarHeight.toDouble(), 8.0, 0.0, 8.0),
decoration: new BoxDecoration(backgroundColor: backgroundColor) decoration: new BoxDecoration(backgroundColor: backgroundColor)
); );
......
...@@ -408,10 +408,11 @@ class SizedBox extends OneChildRenderObjectWrapper { ...@@ -408,10 +408,11 @@ class SizedBox extends OneChildRenderObjectWrapper {
final Size desiredSize; final Size desiredSize;
SizedBox({ SizedBox({
this.desiredSize: sky.Size.infinite, double width: double.INFINITY,
double height: double.INFINITY,
UINode child, UINode child,
Object key Object key
}) : super(child: child, key: key); }) : desiredSize = new Size(width, height), super(child: child, key: key);
RenderSizedBox createNode() => new RenderSizedBox(desiredSize: desiredSize); RenderSizedBox createNode() => new RenderSizedBox(desiredSize: desiredSize);
...@@ -958,14 +959,16 @@ class Container extends Component { ...@@ -958,14 +959,16 @@ class Container extends Component {
final EdgeDims margin; final EdgeDims margin;
final EdgeDims padding; final EdgeDims padding;
final Matrix4 transform; final Matrix4 transform;
final Size desiredSize; final double width;
final double height;
Container({ Container({
Object key, Object key,
this.child, this.child,
this.constraints, this.constraints,
this.decoration, this.decoration,
this.desiredSize, this.width,
this.height,
this.margin, this.margin,
this.padding, this.padding,
this.transform this.transform
...@@ -974,14 +977,21 @@ class Container extends Component { ...@@ -974,14 +977,21 @@ class Container extends Component {
UINode build() { UINode build() {
UINode current = child; UINode current = child;
if (child == null && width == null && height == null)
current = new SizedBox();
if (padding != null) if (padding != null)
current = new Padding(padding: padding, child: current); current = new Padding(padding: padding, child: current);
if (decoration != null) if (decoration != null)
current = new DecoratedBox(decoration: decoration, child: current); current = new DecoratedBox(decoration: decoration, child: current);
if (desiredSize != null) if (width != null || height != null)
current = new SizedBox(desiredSize: desiredSize, child: current); current = new SizedBox(
width: width == null ? double.INFINITY : width,
height: height == null ? double.INFINITY : height,
child: current
);
if (constraints != null) if (constraints != null)
current = new ConstrainedBox(constraints: constraints, child: current); current = new ConstrainedBox(constraints: constraints, child: current);
...@@ -992,9 +1002,6 @@ class Container extends Component { ...@@ -992,9 +1002,6 @@ class Container extends Component {
if (transform != null) if (transform != null)
current = new Transform(transform: transform, child: current); current = new Transform(transform: transform, child: current);
if (current == null)
current = new SizedBox();
return current; return current;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册