From 8ac14f86982fa8c9d834c3873aa77cb6d419b50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Drago=C8=99=20Tiselice?= Date: Thu, 15 Sep 2016 15:23:37 -0700 Subject: [PATCH] Replaced FlexDirection with Axis. (#5896) Fixes #4618. --- examples/layers/rendering/flex_layout.dart | 4 +- examples/layers/widgets/spinning_mixed.dart | 2 +- packages/flutter/lib/src/rendering/flex.dart | 82 +++++++++---------- packages/flutter/lib/src/widgets/basic.dart | 10 +-- packages/flutter/test/rendering/box_test.dart | 2 +- .../flutter/test/rendering/flex_test.dart | 12 +-- 6 files changed, 52 insertions(+), 60 deletions(-) diff --git a/examples/layers/rendering/flex_layout.dart b/examples/layers/rendering/flex_layout.dart index b29a8af995..ffaa6fa2ab 100644 --- a/examples/layers/rendering/flex_layout.dart +++ b/examples/layers/rendering/flex_layout.dart @@ -10,7 +10,7 @@ import 'package:flutter/rendering.dart'; import 'src/solid_color_box.dart'; void main() { - RenderFlex table = new RenderFlex(direction: FlexDirection.vertical); + RenderFlex table = new RenderFlex(direction: Axis.vertical); void addAlignmentRow(CrossAxisAlignment crossAxisAlignment) { TextStyle style = const TextStyle(color: const Color(0xFF000000)); @@ -50,7 +50,7 @@ void main() { const TextStyle style = const TextStyle(color: const Color(0xFF000000)); RenderParagraph paragraph = new RenderParagraph(new TextSpan(style: style, text: '$justify')); table.add(new RenderPadding(child: paragraph, padding: new EdgeInsets.only(top: 20.0))); - RenderFlex row = new RenderFlex(direction: FlexDirection.horizontal); + RenderFlex row = new RenderFlex(direction: Axis.horizontal); row.add(new RenderSolidColorBox(const Color(0xFFFFCCCC), desiredSize: new Size(80.0, 60.0))); row.add(new RenderSolidColorBox(const Color(0xFFCCFFCC), desiredSize: new Size(64.0, 60.0))); row.add(new RenderSolidColorBox(const Color(0xFFCCCCFF), desiredSize: new Size(160.0, 60.0))); diff --git a/examples/layers/widgets/spinning_mixed.dart b/examples/layers/widgets/spinning_mixed.dart index beba372e18..b18feeb304 100644 --- a/examples/layers/widgets/spinning_mixed.dart +++ b/examples/layers/widgets/spinning_mixed.dart @@ -93,7 +93,7 @@ void main() { RenderProxyBox proxy = new RenderProxyBox(); attachWidgetTreeToRenderTree(proxy); - RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical); + RenderFlex flexRoot = new RenderFlex(direction: Axis.vertical); addFlexChildSolidColor(flexRoot, const Color(0xFFFF00FF), flex: 1); flexRoot.add(proxy); addFlexChildSolidColor(flexRoot, const Color(0xFF0000FF), flex: 1); diff --git a/packages/flutter/lib/src/rendering/flex.dart b/packages/flutter/lib/src/rendering/flex.dart index dcf0e4fbd0..93b6c438f2 100644 --- a/packages/flutter/lib/src/rendering/flex.dart +++ b/packages/flutter/lib/src/rendering/flex.dart @@ -21,14 +21,6 @@ class FlexParentData extends ContainerBoxParentDataMixin { String toString() => '${super.toString()}; flex=$flex'; } -/// The direction in which the box should flex -enum FlexDirection { - /// Children are arranged horizontally, from left to right - horizontal, - /// Children are arranged vertically, from top to bottom - vertical -} - /// The incoming constraint parameter that defines how much space is available /// along the main axis in a flex layout. Flex layouts allocate the difference /// between the available space and the sum of the sizes of the children @@ -106,7 +98,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin children, - FlexDirection direction: FlexDirection.horizontal, + Axis direction: Axis.horizontal, MainAxisSize mainAxisSize: MainAxisSize.max, MainAxisAlignment mainAxisAlignment: MainAxisAlignment.start, CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center, @@ -120,9 +112,9 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin _direction; - FlexDirection _direction; - set direction (FlexDirection value) { + Axis get direction => _direction; + Axis _direction; + set direction (Axis value) { if (_direction != value) { _direction = value; markNeedsLayout(); @@ -180,7 +172,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin child.getMinIntrinsicWidth(extent) ); @@ -272,7 +264,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin child.getMaxIntrinsicWidth(extent) ); @@ -281,7 +273,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin child.getMinIntrinsicHeight(extent) ); @@ -290,7 +282,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin child.getMaxIntrinsicHeight(extent) ); @@ -298,7 +290,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin 0) { assert(() { - final String identity = _direction == FlexDirection.horizontal ? 'row' : 'column'; - final String axis = _direction == FlexDirection.horizontal ? 'horizontal' : 'vertical'; - final String dimension = _direction == FlexDirection.horizontal ? 'width' : 'height'; + final String identity = _direction == Axis.horizontal ? 'row' : 'column'; + final String axis = _direction == Axis.horizontal ? 'horizontal' : 'vertical'; + final String dimension = _direction == Axis.horizontal ? 'width' : 'height'; String error, message; String addendum = ''; if (availableSize == double.INFINITY) { @@ -351,13 +343,13 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin= minMainSize); break; - case FlexDirection.vertical: + case Axis.vertical: size = constraints.constrain(new Size(crossSize, preferredSize)); crossSize = size.width; assert(isMainAxisSizeMax ? size.height == maxMainSize : size.height >= minMainSize); @@ -512,12 +504,12 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin[padding], - direction: FlexDirection.vertical, + direction: Axis.vertical, crossAxisAlignment: CrossAxisAlignment.stretch ); RenderBox outer = new RenderDecoratedBox( diff --git a/packages/flutter/test/rendering/flex_test.dart b/packages/flutter/test/rendering/flex_test.dart index 62962d9195..99bd6b36ee 100644 --- a/packages/flutter/test/rendering/flex_test.dart +++ b/packages/flutter/test/rendering/flex_test.dart @@ -24,7 +24,7 @@ void main() { additionalConstraints: const BoxConstraints.expand() ); RenderFlex flex = new RenderFlex( - direction: FlexDirection.vertical, + direction: Axis.vertical, children: [ new RenderConstrainedBox(additionalConstraints: new BoxConstraints.tightFor(height: 200.0)), flexible, @@ -46,7 +46,7 @@ void main() { additionalConstraints: const BoxConstraints.expand() ); RenderFlex flex = new RenderFlex( - direction: FlexDirection.horizontal, + direction: Axis.horizontal, children: [ new RenderConstrainedBox(additionalConstraints: new BoxConstraints.tightFor(width: 200.0)), flexible, @@ -65,7 +65,7 @@ void main() { test('Vertical Flipped Constraints', () { RenderFlex flex = new RenderFlex( - direction: FlexDirection.vertical, + direction: Axis.vertical, children: [ new RenderAspectRatio(aspectRatio: 1.0), ] @@ -81,7 +81,7 @@ void main() { test('Defaults', () { RenderFlex flex = new RenderFlex(); expect(flex.crossAxisAlignment, equals(CrossAxisAlignment.center)); - expect(flex.direction, equals(FlexDirection.horizontal)); + expect(flex.direction, equals(Axis.horizontal)); }); test('Parent data', () { @@ -129,7 +129,7 @@ void main() { expect(box2.size.width, equals(100.0)); expect(box2.size.height, equals(100.0)); - flex.direction = FlexDirection.vertical; + flex.direction = Axis.vertical; pumpFrame(); expect(box1.size.width, equals(100.0)); expect(box1.size.height, equals(0.0)); @@ -157,7 +157,7 @@ void main() { expect(getOffset(box3).dx, equals(350.0)); expect(box3.size.width, equals(100.0)); - flex.direction = FlexDirection.vertical; + flex.direction = Axis.vertical; pumpFrame(); expect(getOffset(box1).dy, equals(25.0)); expect(box1.size.height, equals(100.0));