Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1fcc507

Browse files
committed
Merge pull request #110 from collinjackson/baseline2
Track overflow during flex layout and fix stocks row R=hixie
2 parents 81611c5 + 329fb96 commit 1fcc507

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

sky/sdk/example/stocks/lib/stock_row.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class StockRow extends Component {
5959
child: new StockArrow(percentChange: stock.percentChange),
6060
margin: const EdgeDims.only(right: 5.0)
6161
),
62-
new Flex(children, alignItems: FlexAlignItems.baseline)
62+
new Flexible(
63+
child: new Flex(children, alignItems: FlexAlignItems.baseline)
64+
)
6365
])
6466
)
6567
);

sky/sdk/lib/rendering/flex.dart

+15-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
8181
}
8282
}
8383

84+
bool _overflowOccurredDuringLayout = false;
85+
8486
void setupParentData(RenderBox child) {
8587
if (child.parentData is! FlexBoxParentData)
8688
child.parentData = new FlexBoxParentData();
@@ -376,16 +378,20 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
376378
break;
377379
}
378380

381+
Size desiredSize;
379382
switch (_direction) {
380383
case FlexDirection.horizontal:
381-
size = constraints.constrain(new Size(mainSize, crossSize));
384+
desiredSize = new Size(mainSize, crossSize);
385+
size = constraints.constrain(desiredSize);
382386
crossSize = size.height;
383387
break;
384388
case FlexDirection.vertical:
389+
desiredSize = new Size(crossSize, mainSize);
385390
size = constraints.constrain(new Size(crossSize, mainSize));
386391
crossSize = size.width;
387392
break;
388393
}
394+
_overflowOccurredDuringLayout = desiredSize != size;
389395

390396
// Position elements
391397
double childMainPosition = leadingSpace;
@@ -433,6 +439,13 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
433439
}
434440

435441
void paint(PaintingCanvas canvas, Offset offset) {
436-
defaultPaint(canvas, offset);
442+
if (_overflowOccurredDuringLayout) {
443+
canvas.save();
444+
canvas.clipRect(offset & size);
445+
defaultPaint(canvas, offset);
446+
canvas.restore();
447+
} else {
448+
defaultPaint(canvas, offset);
449+
}
437450
}
438451
}

0 commit comments

Comments
 (0)