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 '../resources/display_list.dart'; | 7 import '../resources/display_list.dart'; |
8 import 'dart:sky' as sky; | 8 import 'dart:sky' as sky; |
9 import 'package:sky/framework/app.dart'; | 9 import 'package:sky/framework/app.dart'; |
10 import 'package:sky/framework/rendering/block.dart'; | 10 import 'package:sky/framework/rendering/block.dart'; |
11 import 'package:sky/framework/rendering/box.dart'; | 11 import 'package:sky/framework/rendering/box.dart'; |
12 import 'package:sky/framework/rendering/flex.dart'; | 12 import 'package:sky/framework/rendering/flex.dart'; |
13 | 13 |
14 class RenderSolidColor extends RenderDecoratedBox { | 14 class RenderSolidColor extends RenderDecoratedBox { |
15 final sky.Size desiredSize; | 15 final sky.Size desiredSize; |
16 final int backgroundColor; | 16 final sky.Color backgroundColor; |
17 | 17 |
18 RenderSolidColor(int backgroundColor, { this.desiredSize: const sky.Size.infin
ite() }) | 18 RenderSolidColor(sky.Color backgroundColor, { this.desiredSize: const sky.Size
.infinite() }) |
19 : backgroundColor = backgroundColor, | 19 : backgroundColor = backgroundColor, |
20 super(decoration: new BoxDecoration(backgroundColor: backgroundColor)) { | 20 super(decoration: new BoxDecoration(backgroundColor: backgroundColor)) { |
21 } | 21 } |
22 | 22 |
23 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { | 23 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
24 return constraints.constrain(desiredSize); | 24 return constraints.constrain(desiredSize); |
25 } | 25 } |
26 | 26 |
27 void performLayout() { | 27 void performLayout() { |
28 size = constraints.constrain(desiredSize); | 28 size = constraints.constrain(desiredSize); |
29 } | 29 } |
30 | 30 |
31 void handlePointer(sky.PointerEvent event) { | 31 void handlePointer(sky.PointerEvent event) { |
32 if (event.type == 'pointerdown') | 32 if (event.type == 'pointerdown') |
33 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); | 33 decoration = new BoxDecoration(backgroundColor: const sky.Color(0xFFFF0000
)); |
34 else if (event.type == 'pointerup') | 34 else if (event.type == 'pointerup') |
35 decoration = new BoxDecoration(backgroundColor: backgroundColor); | 35 decoration = new BoxDecoration(backgroundColor: backgroundColor); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 TestApp app; | 39 TestApp app; |
40 | 40 |
41 void main() { | 41 void main() { |
42 initUnit(); | 42 initUnit(); |
43 | 43 |
44 test("should flex", () { | 44 test("should flex", () { |
45 RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.Vertical); | 45 RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.Vertical); |
46 | 46 |
47 RenderDecoratedBox root = new RenderDecoratedBox( | 47 RenderDecoratedBox root = new RenderDecoratedBox( |
48 decoration: new BoxDecoration(backgroundColor: 0xFF000000), | 48 decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF000000)
), |
49 child: flexRoot | 49 child: flexRoot |
50 ); | 50 ); |
51 | 51 |
52 void addFlexChildSolidColor(RenderFlex parent, int backgroundColor, { int fl
ex: 0 }) { | 52 void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, {
int flex: 0 }) { |
53 RenderSolidColor child = new RenderSolidColor(backgroundColor); | 53 RenderSolidColor child = new RenderSolidColor(backgroundColor); |
54 parent.add(child); | 54 parent.add(child); |
55 child.parentData.flex = flex; | 55 child.parentData.flex = flex; |
56 } | 56 } |
57 | 57 |
58 // Yellow bar at top | 58 // Yellow bar at top |
59 addFlexChildSolidColor(flexRoot, 0xFFFFFF00, flex: 1); | 59 addFlexChildSolidColor(flexRoot, const sky.Color(0xFFFFFF00), flex: 1); |
60 | 60 |
61 // Turquoise box | 61 // Turquoise box |
62 flexRoot.add(new RenderSolidColor(0x7700FFFF, desiredSize: new sky.Size(100.
0, 100.0))); | 62 flexRoot.add(new RenderSolidColor(const sky.Color(0x7700FFFF), desiredSize:
new sky.Size(100.0, 100.0))); |
63 | 63 |
64 // Green and cyan render block with padding | 64 // Green and cyan render block with padding |
65 var renderBlock = new RenderBlock(); | 65 var renderBlock = new RenderBlock(); |
66 | 66 |
67 renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredSize: new sky.Size(1
00.0, 50.0))); | 67 renderBlock.add(new RenderSolidColor(const sky.Color(0xFF00FF00), desiredSiz
e: new sky.Size(100.0, 50.0))); |
68 renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredSize: new sky.Size(5
0.0, 100.0))); | 68 renderBlock.add(new RenderSolidColor(const sky.Color(0x7700FFFF), desiredSiz
e: new sky.Size(50.0, 100.0))); |
69 | 69 |
70 var renderDecoratedBlock = new RenderDecoratedBox( | 70 var renderDecoratedBlock = new RenderDecoratedBox( |
71 decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF), | 71 decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFFFFFFFF)
), |
72 child: renderBlock | 72 child: renderBlock |
73 ); | 73 ); |
74 | 74 |
75 flexRoot.add(new RenderPadding(padding: const EdgeDims.all(10.0), child: ren
derDecoratedBlock)); | 75 flexRoot.add(new RenderPadding(padding: const EdgeDims.all(10.0), child: ren
derDecoratedBlock)); |
76 | 76 |
77 var row = new RenderFlex(direction: FlexDirection.Horizontal); | 77 var row = new RenderFlex(direction: FlexDirection.Horizontal); |
78 | 78 |
79 // Purple and blue cells | 79 // Purple and blue cells |
80 addFlexChildSolidColor(row, 0x77FF00FF, flex: 1); | 80 addFlexChildSolidColor(row, const sky.Color(0x77FF00FF), flex: 1); |
81 addFlexChildSolidColor(row, 0xFF0000FF, flex: 2); | 81 addFlexChildSolidColor(row, const sky.Color(0xFF0000FF), flex: 2); |
82 | 82 |
83 var decoratedRow = new RenderDecoratedBox( | 83 var decoratedRow = new RenderDecoratedBox( |
84 decoration: new BoxDecoration(backgroundColor: 0xFF333333), | 84 decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF333333)
), |
85 child: row | 85 child: row |
86 ); | 86 ); |
87 | 87 |
88 flexRoot.add(decoratedRow); | 88 flexRoot.add(decoratedRow); |
89 decoratedRow.parentData.flex = 3; | 89 decoratedRow.parentData.flex = 3; |
90 app = new TestApp(root); | 90 app = new TestApp(root); |
91 | 91 |
92 expect(root.size.width, equals(sky.view.width)); | 92 expect(root.size.width, equals(sky.view.width)); |
93 expect(root.size.height, equals(sky.view.height)); | 93 expect(root.size.height, equals(sky.view.height)); |
94 expect(renderBlock.size.width, equals(sky.view.width - 20.0)); | 94 expect(renderBlock.size.width, equals(sky.view.width - 20.0)); |
95 | 95 |
96 }); | 96 }); |
97 } | 97 } |
OLD | NEW |