Merge pull request #110 from collinjackson/baseline2
Track overflow during flex layout and fix stocks row
R=hixie
diff --git a/sky/sdk/example/stocks/lib/stock_row.dart b/sky/sdk/example/stocks/lib/stock_row.dart
index af75ba9..ab98f8a 100644
--- a/sky/sdk/example/stocks/lib/stock_row.dart
+++ b/sky/sdk/example/stocks/lib/stock_row.dart
@@ -59,7 +59,9 @@
child: new StockArrow(percentChange: stock.percentChange),
margin: const EdgeDims.only(right: 5.0)
),
- new Flex(children, alignItems: FlexAlignItems.baseline)
+ new Flexible(
+ child: new Flex(children, alignItems: FlexAlignItems.baseline)
+ )
])
)
);
diff --git a/sky/sdk/lib/rendering/flex.dart b/sky/sdk/lib/rendering/flex.dart
index c7b79f8..fd7d233 100644
--- a/sky/sdk/lib/rendering/flex.dart
+++ b/sky/sdk/lib/rendering/flex.dart
@@ -81,6 +81,8 @@
}
}
+ bool _overflowOccurredDuringLayout = false;
+
void setupParentData(RenderBox child) {
if (child.parentData is! FlexBoxParentData)
child.parentData = new FlexBoxParentData();
@@ -376,16 +378,20 @@
break;
}
+ Size desiredSize;
switch (_direction) {
case FlexDirection.horizontal:
- size = constraints.constrain(new Size(mainSize, crossSize));
+ desiredSize = new Size(mainSize, crossSize);
+ size = constraints.constrain(desiredSize);
crossSize = size.height;
break;
case FlexDirection.vertical:
+ desiredSize = new Size(crossSize, mainSize);
size = constraints.constrain(new Size(crossSize, mainSize));
crossSize = size.width;
break;
}
+ _overflowOccurredDuringLayout = desiredSize != size;
// Position elements
double childMainPosition = leadingSpace;
@@ -433,6 +439,13 @@
}
void paint(PaintingCanvas canvas, Offset offset) {
- defaultPaint(canvas, offset);
+ if (_overflowOccurredDuringLayout) {
+ canvas.save();
+ canvas.clipRect(offset & size);
+ defaultPaint(canvas, offset);
+ canvas.restore();
+ } else {
+ defaultPaint(canvas, offset);
+ }
}
}