Commit c6942c99 authored by Adam Barth's avatar Adam Barth

Implement MainAxisAlignment.spaceEvenly (#3550)

Fixes #3289
parent 2047c70e
......@@ -29,33 +29,45 @@ enum FlexDirection {
vertical
}
/// How the children should be placed along the main axis in a flex layout
/// How the children should be placed along the main axis in a flex layout.
enum MainAxisAlignment {
/// Place the children as close to the start of the main axis as possible
/// Place the children as close to the start of the main axis as possible.
start,
/// Place the children as close to the end of the main axis as possible
/// Place the children as close to the end of the main axis as possible.
end,
/// Place the children as close to the middle of the main axis as possible
/// Place the children as close to the middle of the main axis as possible.
center,
/// Place the free space evenly between the children
/// Place the free space evenly between the children.
spaceBetween,
/// Place the free space evenly between the children as well as before and after the first and last child
/// Place the free space evenly between the children as well as half of that space before and after the first and last child.
spaceAround,
/// Place the free space evenly between the children as well as before and after the first and last child.
spaceEvenly,
/// Do not expand to fill the free space. None of the children may specify a flex factor.
collapse,
}
/// How the children should be placed along the cross axis in a flex layout
/// How the children should be placed along the cross axis in a flex layout.
enum CrossAxisAlignment {
/// Place the children as close to the start of the cross axis as possible
/// Place the children as close to the start of the cross axis as possible.
start,
/// Place the children as close to the end of the cross axis as possible
/// Place the children as close to the end of the cross axis as possible.
end,
/// Place the children as close to the middle of the cross axis as possible
/// Place the children as close to the middle of the cross axis as possible.
center,
/// Require the children to fill the cross axis
/// Require the children to fill the cross axis.
stretch,
/// Place the children along the cross axis such that their baselines match
/// Place the children along the cross axis such that their baselines match.
baseline,
}
......@@ -562,6 +574,10 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
betweenSpace = totalChildren > 0 ? remainingSpace / totalChildren : 0.0;
leadingSpace = betweenSpace / 2.0;
break;
case MainAxisAlignment.spaceEvenly:
betweenSpace = totalChildren > 0 ? remainingSpace / (totalChildren + 1) : 0.0;
leadingSpace = betweenSpace;
break;
}
// Position elements
......
......@@ -136,4 +136,34 @@ void main() {
expect(box2.size.width, equals(100.0));
expect(box2.size.height, equals(100.0));
});
test('Space evenly', () {
RenderConstrainedBox box1 = new RenderConstrainedBox(additionalConstraints: new BoxConstraints.tightFor(width: 100.0, height: 100.0));
RenderConstrainedBox box2 = new RenderConstrainedBox(additionalConstraints: new BoxConstraints.tightFor(width: 100.0, height: 100.0));
RenderConstrainedBox box3 = new RenderConstrainedBox(additionalConstraints: new BoxConstraints.tightFor(width: 100.0, height: 100.0));
RenderFlex flex = new RenderFlex(mainAxisAlignment: MainAxisAlignment.spaceEvenly);
flex.addAll(<RenderBox>[box1, box2, box3]);
layout(flex, constraints: const BoxConstraints(
minWidth: 0.0, maxWidth: 500.0, minHeight: 0.0, maxHeight: 400.0)
);
Offset getOffset(RenderBox box) {
FlexParentData parentData = box.parentData;
return parentData.offset;
}
expect(getOffset(box1).dx, equals(50.0));
expect(box1.size.width, equals(100.0));
expect(getOffset(box2).dx, equals(200.0));
expect(box2.size.width, equals(100.0));
expect(getOffset(box3).dx, equals(350.0));
expect(box3.size.width, equals(100.0));
flex.direction = FlexDirection.vertical;
pumpFrame();
expect(getOffset(box1).dy, equals(25.0));
expect(box1.size.height, equals(100.0));
expect(getOffset(box2).dy, equals(150.0));
expect(box2.size.height, equals(100.0));
expect(getOffset(box3).dy, equals(275.0));
expect(box3.size.height, equals(100.0));
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment