mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Support for alignItems (test incoming)
R=abarth@chromium.org, abarth, hansmuller Review URL: https://codereview.chromium.org/1181533003
This commit is contained in:
parent
5dabb87cd7
commit
dd0cc7fc0b
@ -35,15 +35,11 @@ class ToolBar extends Component {
|
||||
if (right != null)
|
||||
children.addAll(right);
|
||||
|
||||
// TODO(hansmuller): use align-items:flex-end when Flex supports it.
|
||||
UINode bottomJustifiedChild = new Flex([
|
||||
new Container(child: new Flex(children), height: kToolBarHeight)
|
||||
],
|
||||
direction: FlexDirection.vertical,
|
||||
justifyContent: FlexJustifyContent.flexEnd);
|
||||
|
||||
return new Container(
|
||||
child: bottomJustifiedChild,
|
||||
child: new Flex(
|
||||
[new Container(child: new Flex(children), height: kToolBarHeight)],
|
||||
alignItems: FlexAlignItems.flexEnd
|
||||
),
|
||||
padding: new EdgeDims.symmetric(horizontal: 8.0),
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: backgroundColor,
|
||||
|
||||
@ -787,7 +787,8 @@ class Flex extends MultiChildRenderObjectWrapper {
|
||||
Flex(List<UINode> children, {
|
||||
Object key,
|
||||
this.direction: FlexDirection.horizontal,
|
||||
this.justifyContent: FlexJustifyContent.flexStart
|
||||
this.justifyContent: FlexJustifyContent.flexStart,
|
||||
this.alignItems: FlexAlignItems.center
|
||||
}) : super(key: key, children: children);
|
||||
|
||||
RenderFlex get root { RenderFlex result = super.root; return result; }
|
||||
@ -795,11 +796,13 @@ class Flex extends MultiChildRenderObjectWrapper {
|
||||
|
||||
final FlexDirection direction;
|
||||
final FlexJustifyContent justifyContent;
|
||||
final FlexAlignItems alignItems;
|
||||
|
||||
void syncRenderObject(UINode old) {
|
||||
super.syncRenderObject(old);
|
||||
root.direction = direction;
|
||||
root.justifyContent = justifyContent;
|
||||
root.alignItems = alignItems;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ class FlexBoxParentData extends BoxParentData with ContainerParentDataMixin<Rend
|
||||
}
|
||||
|
||||
enum FlexDirection { horizontal, vertical }
|
||||
|
||||
enum FlexJustifyContent {
|
||||
flexStart,
|
||||
flexEnd,
|
||||
@ -27,6 +28,12 @@ enum FlexJustifyContent {
|
||||
spaceAround,
|
||||
}
|
||||
|
||||
enum FlexAlignItems {
|
||||
flexStart,
|
||||
flexEnd,
|
||||
center,
|
||||
}
|
||||
|
||||
typedef double _ChildSizingFunction(RenderBox child, BoxConstraints constraints);
|
||||
|
||||
class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, FlexBoxParentData>,
|
||||
@ -35,8 +42,9 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
|
||||
|
||||
RenderFlex({
|
||||
FlexDirection direction: FlexDirection.horizontal,
|
||||
FlexJustifyContent justifyContent: FlexJustifyContent.flexStart
|
||||
}) : _direction = direction, _justifyContent = justifyContent;
|
||||
FlexJustifyContent justifyContent: FlexJustifyContent.flexStart,
|
||||
FlexAlignItems alignItems: FlexAlignItems.center
|
||||
}) : _direction = direction, _justifyContent = justifyContent, _alignItems = alignItems;
|
||||
|
||||
FlexDirection _direction;
|
||||
FlexDirection get direction => _direction;
|
||||
@ -56,6 +64,15 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
|
||||
}
|
||||
}
|
||||
|
||||
FlexAlignItems _alignItems;
|
||||
FlexAlignItems get alignItems => _alignItems;
|
||||
void set alignItems (FlexAlignItems value) {
|
||||
if (_alignItems != value) {
|
||||
_alignItems = value;
|
||||
markNeedsLayout();
|
||||
}
|
||||
}
|
||||
|
||||
void setParentData(RenderBox child) {
|
||||
if (child.parentData is! FlexBoxParentData)
|
||||
child.parentData = new FlexBoxParentData();
|
||||
@ -334,7 +351,18 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
|
||||
double childMainPosition = leadingSpace;
|
||||
child = firstChild;
|
||||
while (child != null) {
|
||||
double childCrossPosition = crossSize / 2.0 - _getCrossSize(child) / 2.0;
|
||||
double childCrossPosition;
|
||||
switch (_alignItems) {
|
||||
case FlexAlignItems.flexStart:
|
||||
childCrossPosition = 0.0;
|
||||
break;
|
||||
case FlexAlignItems.flexEnd:
|
||||
childCrossPosition = crossSize - _getCrossSize(child);
|
||||
break;
|
||||
case FlexAlignItems.center:
|
||||
childCrossPosition = crossSize / 2.0 - _getCrossSize(child) / 2.0;
|
||||
break;
|
||||
}
|
||||
switch (_direction) {
|
||||
case FlexDirection.horizontal:
|
||||
child.parentData.position = new Point(childMainPosition, childCrossPosition);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user