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

Track overflow during flex layout and fix stocks row #110

Merged
merged 2 commits into from
Jul 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}