OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 import '../resources/third_party/unittest/unittest.dart'; | 5 import '../resources/third_party/unittest/unittest.dart'; |
6 import '../resources/unit.dart'; | 6 import '../resources/unit.dart'; |
7 import 'dart:sky' as sky; | 7 import 'dart:sky' as sky; |
8 import 'package:sky/framework/app.dart'; | 8 import 'package:sky/framework/app.dart'; |
9 import 'package:sky/framework/layout2.dart'; | 9 import 'package:sky/framework/layout2.dart'; |
10 | 10 |
11 class RenderSolidColor extends RenderDecoratedBox { | 11 class RenderSolidColor extends RenderDecoratedBox { |
12 final sky.Size desiredSize; | 12 final sky.Size desiredSize; |
13 final int backgroundColor; | 13 final int backgroundColor; |
14 | 14 |
15 RenderSolidColor(int backgroundColor, { this.desiredSize: const sky.Size.infin
ite() }) | 15 RenderSolidColor(int backgroundColor, { this.desiredSize: const sky.Size.infin
ite() }) |
16 : backgroundColor = backgroundColor, | 16 : backgroundColor = backgroundColor, |
17 super(new BoxDecoration(backgroundColor: backgroundColor)) { | 17 super(decoration: new BoxDecoration(backgroundColor: backgroundColor)) { |
18 } | 18 } |
19 | 19 |
20 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { | 20 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
21 return constraints.constrain(desiredSize); | 21 return constraints.constrain(desiredSize); |
22 } | 22 } |
23 | 23 |
24 void performLayout() { | 24 void performLayout() { |
25 size = constraints.constrain(desiredSize); | 25 size = constraints.constrain(desiredSize); |
26 } | 26 } |
27 | 27 |
28 void handlePointer(sky.PointerEvent event) { | 28 void handlePointer(sky.PointerEvent event) { |
29 if (event.type == 'pointerdown') | 29 if (event.type == 'pointerdown') |
30 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); | 30 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); |
31 else if (event.type == 'pointerup') | 31 else if (event.type == 'pointerup') |
32 decoration = new BoxDecoration(backgroundColor: backgroundColor); | 32 decoration = new BoxDecoration(backgroundColor: backgroundColor); |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 AppView app; | 36 AppView app; |
37 | 37 |
38 void main() { | 38 void main() { |
39 initUnit(); | 39 initUnit(); |
40 | 40 |
41 test("should flex", () { | 41 test("should flex", () { |
42 var root = new RenderFlex( | 42 RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.Vertical); |
43 direction: FlexDirection.Vertical, | |
44 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); | |
45 | 43 |
46 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) { | 44 RenderNode root = new RenderDecoratedBox( |
| 45 decoration: new BoxDecoration(backgroundColor: 0xFF000000), |
| 46 child: flexRoot |
| 47 ); |
| 48 |
| 49 void addFlexChildSolidColor(RenderFlex parent, int backgroundColor, { int fl
ex: 0 }) { |
47 RenderNode child = new RenderSolidColor(backgroundColor); | 50 RenderNode child = new RenderSolidColor(backgroundColor); |
48 parent.add(child); | 51 parent.add(child); |
49 child.parentData.flex = flex; | 52 child.parentData.flex = flex; |
50 } | 53 } |
51 | 54 |
52 // Yellow bar at top | 55 // Yellow bar at top |
53 addFlexChild(root, 0xFFFFFF00, flex: 1); | 56 addFlexChildSolidColor(flexRoot, 0xFFFFFF00, flex: 1); |
54 | 57 |
55 // Turquoise box | 58 // Turquoise box |
56 root.add(new RenderSolidColor(0x7700FFFF, desiredSize: new sky.Size(100.0, 1
00.0))); | 59 flexRoot.add(new RenderSolidColor(0x7700FFFF, desiredSize: new sky.Size(100.
0, 100.0))); |
57 | 60 |
58 // Green and cyan render block with padding | 61 // Green and cyan render block with padding |
59 var renderBlock = new RenderBlock(decoration: new BoxDecoration(backgroundCo
lor: 0xFFFFFFFF)); | 62 var renderBlock = new RenderBlock(); |
60 | 63 |
61 renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredSize: new sky.Size(1
00.0, 50.0))); | 64 renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredSize: new sky.Size(1
00.0, 50.0))); |
62 renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredSize: new sky.Size(5
0.0, 100.0))); | 65 renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredSize: new sky.Size(5
0.0, 100.0))); |
63 | 66 |
64 root.add(new RenderPadding(const EdgeDims(10.0, 10.0, 10.0, 10.0), renderBlo
ck)); | 67 var renderDecoratedBlock = new RenderDecoratedBox( |
| 68 decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF), |
| 69 child: renderBlock |
| 70 ); |
65 | 71 |
66 var row = new RenderFlex( | 72 flexRoot.add(new RenderPadding(const EdgeDims(10.0, 10.0, 10.0, 10.0), rende
rDecoratedBlock)); |
67 direction: FlexDirection.Horizontal, | 73 |
68 decoration: new BoxDecoration(backgroundColor: 0xFF333333)); | 74 var row = new RenderFlex(direction: FlexDirection.Horizontal); |
69 | 75 |
70 // Purple and blue cells | 76 // Purple and blue cells |
71 addFlexChild(row, 0x77FF00FF, flex: 1); | 77 addFlexChildSolidColor(row, 0x77FF00FF, flex: 1); |
72 addFlexChild(row, 0xFF0000FF, flex: 2); | 78 addFlexChildSolidColor(row, 0xFF0000FF, flex: 2); |
73 | 79 |
74 root.add(row); | 80 var decoratedRow = new RenderDecoratedBox( |
75 row.parentData.flex = 3; | 81 decoration: new BoxDecoration(backgroundColor: 0xFF333333), |
| 82 child: row |
| 83 ); |
| 84 |
| 85 flexRoot.add(decoratedRow); |
| 86 decoratedRow.parentData.flex = 3; |
76 | 87 |
77 app = new AppView(root); | 88 app = new AppView(root); |
78 | 89 |
79 expect(root.size.width, equals(sky.view.width)); | 90 expect(root.size.width, equals(sky.view.width)); |
80 expect(root.size.height, equals(sky.view.height)); | 91 expect(root.size.height, equals(sky.view.height)); |
81 expect(renderBlock.size.width, equals(sky.view.width - 20.0)); | 92 expect(renderBlock.size.width, equals(sky.view.width - 20.0)); |
| 93 |
82 }); | 94 }); |
83 } | 95 } |
OLD | NEW |