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 'dart:sky'; | 5 import 'dart:sky'; |
6 import 'package:sky/framework/app.dart'; | 6 import 'package:sky/framework/app.dart'; |
7 import 'package:sky/framework/layout2.dart'; | 7 import 'package:sky/framework/layout2.dart'; |
8 | 8 |
9 class RenderSolidColor extends RenderDecoratedBox { | 9 class RenderSolidColor extends RenderDecoratedBox { |
10 final Size desiredSize; | 10 final Size desiredSize; |
11 final int backgroundColor; | 11 final int backgroundColor; |
12 | 12 |
13 RenderSolidColor(int backgroundColor, { this.desiredSize }) | 13 RenderSolidColor(int backgroundColor, { this.desiredSize: const sky.Size.infin
ite() }) |
14 : backgroundColor = backgroundColor, | 14 : backgroundColor = backgroundColor, |
15 super(new BoxDecoration(backgroundColor: backgroundColor)) { | 15 super(new BoxDecoration(backgroundColor: backgroundColor)) { |
16 } | 16 } |
17 | 17 |
18 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | 18 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { |
19 return new BoxDimensions.withConstraints(constraints, | 19 return new BoxDimensions.withConstraints(constraints, |
20 width: desiredSize.width, | 20 width: desiredSize.width, |
21 height: desiredSize.height); | 21 height: desiredSize.height); |
22 } | 22 } |
23 | 23 |
(...skipping 10 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 AppView app; | 36 AppView app; |
37 | 37 |
38 void main() { | 38 void main() { |
39 var root = new RenderFlex( | 39 var root = new RenderFlex( |
40 direction: FlexDirection.Vertical, | 40 direction: FlexDirection.Vertical, |
41 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); | 41 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); |
42 | 42 |
43 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) { | 43 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) { |
44 RenderNode child = new RenderSolidColor(backgroundColor, desiredSize: new Si
ze.infinite()); | 44 RenderNode child = new RenderSolidColor(backgroundColor); |
45 parent.add(child); | 45 parent.add(child); |
46 child.parentData.flex = flex; | 46 child.parentData.flex = flex; |
47 } | 47 } |
48 | 48 |
49 // Yellow bar at top | 49 // Yellow bar at top |
50 addFlexChild(root, 0xFFFFFF00, flex: 1); | 50 addFlexChild(root, 0xFFFFFF00, flex: 1); |
51 | 51 |
52 // Turquoise box | 52 // Turquoise box |
53 root.add(new RenderSolidColor(0x7700FFFF, desiredSize: new Size(100.0, 100.0))
); | 53 root.add(new RenderSolidColor(0x7700FFFF, desiredSize: new Size(100.0, 100.0))
); |
54 | 54 |
(...skipping 12 matching lines...) Expand all Loading... |
67 // Purple and blue cells | 67 // Purple and blue cells |
68 addFlexChild(row, 0x77FF00FF, flex: 1); | 68 addFlexChild(row, 0x77FF00FF, flex: 1); |
69 addFlexChild(row, 0xFF0000FF, flex: 2); | 69 addFlexChild(row, 0xFF0000FF, flex: 2); |
70 | 70 |
71 root.add(row); | 71 root.add(row); |
72 row.parentData.flex = 3; | 72 row.parentData.flex = 3; |
73 | 73 |
74 app = new AppView(root); | 74 app = new AppView(root); |
75 | 75 |
76 } | 76 } |
OLD | NEW |