Skip to content

Commit

Permalink
Merge pull request #110 from collinjackson/baseline2
Browse files Browse the repository at this point in the history
Track overflow during flex layout and fix stocks row

R=hixie
  • Loading branch information
collinjackson committed Jul 18, 2015
2 parents 81611c5 + 329fb96 commit 1fcc507
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion sky/sdk/example/stocks/lib/stock_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class StockRow extends Component {
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)
)
])
)
);
Expand Down
17 changes: 15 additions & 2 deletions sky/sdk/lib/rendering/flex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
}
}

bool _overflowOccurredDuringLayout = false;

void setupParentData(RenderBox child) {
if (child.parentData is! FlexBoxParentData)
child.parentData = new FlexBoxParentData();
Expand Down Expand Up @@ -376,16 +378,20 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
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;
Expand Down Expand Up @@ -433,6 +439,13 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
}

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);
}
}
}

0 comments on commit 1fcc507

Please sign in to comment.