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 double desiredHeight; | 10 final Size desiredSize; |
11 final double desiredWidth; | |
12 final int backgroundColor; | 11 final int backgroundColor; |
13 | 12 |
14 RenderSolidColor(int backgroundColor, { this.desiredHeight: double.INFINITY, | 13 RenderSolidColor(int backgroundColor, { this.desiredSize }) |
15 this.desiredWidth: double.INFINITY }) | |
16 : backgroundColor = backgroundColor, | 14 : backgroundColor = backgroundColor, |
17 super(new BoxDecoration(backgroundColor: backgroundColor)); | 15 super(new BoxDecoration(backgroundColor: backgroundColor)) { |
| 16 } |
18 | 17 |
19 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | 18 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { |
20 return new BoxDimensions.withConstraints(constraints, | 19 return new BoxDimensions.withConstraints(constraints, |
21 height: desiredHeight, | 20 width: desiredSize.width, |
22 width: desiredWidth); | 21 height: desiredSize.height); |
23 } | 22 } |
24 | 23 |
25 void performLayout() { | 24 void performLayout() { |
26 width = constraints.constrainWidth(desiredWidth); | 25 size = constraints.constrain(desiredSize); |
27 height = constraints.constrainHeight(desiredHeight); | |
28 } | 26 } |
29 | 27 |
30 void handlePointer(PointerEvent event) { | 28 void handlePointer(PointerEvent event) { |
31 if (event.type == 'pointerdown') | 29 if (event.type == 'pointerdown') |
32 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); | 30 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); |
33 else if (event.type == 'pointerup') | 31 else if (event.type == 'pointerup') |
34 decoration = new BoxDecoration(backgroundColor: backgroundColor); | 32 decoration = new BoxDecoration(backgroundColor: backgroundColor); |
35 } | 33 } |
36 } | 34 } |
37 | 35 |
38 AppView app; | 36 AppView app; |
39 | 37 |
40 void main() { | 38 void main() { |
41 var root = new RenderFlex( | 39 var root = new RenderFlex( |
42 direction: FlexDirection.Vertical, | 40 direction: FlexDirection.Vertical, |
43 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); | 41 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); |
44 | 42 |
45 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) { | 43 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) { |
46 RenderNode child = new RenderSolidColor(backgroundColor); | 44 RenderNode child = new RenderSolidColor(backgroundColor, desiredSize: new Si
ze.infinite()); |
47 parent.add(child); | 45 parent.add(child); |
48 child.parentData.flex = flex; | 46 child.parentData.flex = flex; |
49 } | 47 } |
50 | 48 |
51 // Yellow bar at top | 49 // Yellow bar at top |
52 addFlexChild(root, 0xFFFFFF00, flex: 1); | 50 addFlexChild(root, 0xFFFFFF00, flex: 1); |
53 | 51 |
54 // Turquoise box | 52 // Turquoise box |
55 root.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desiredWidth:
100.0)); | 53 root.add(new RenderSolidColor(0x7700FFFF, desiredSize: new Size(100.0, 100.0))
); |
56 | 54 |
57 // Green and cyan render block with padding | 55 // Green and cyan render block with padding |
58 var renderBlock = new RenderBlock(decoration: new BoxDecoration(backgroundColo
r: 0xFFFFFFFF)); | 56 var renderBlock = new RenderBlock(decoration: new BoxDecoration(backgroundColo
r: 0xFFFFFFFF)); |
59 | 57 |
60 renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredHeight: 50.0, desiredW
idth: 100.0)); | 58 renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredSize: new Size(100.0,
50.0))); |
61 renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desired
Width: 50.0)); | 59 renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredSize: new Size(50.0, 1
00.0))); |
62 | 60 |
63 root.add(new RenderPadding(const EdgeDims(10.0, 10.0, 10.0, 10.0), renderBlock
)); | 61 root.add(new RenderPadding(const EdgeDims(10.0, 10.0, 10.0, 10.0), renderBlock
)); |
64 | 62 |
65 var row = new RenderFlex( | 63 var row = new RenderFlex( |
66 direction: FlexDirection.Horizontal, | 64 direction: FlexDirection.Horizontal, |
67 decoration: new BoxDecoration(backgroundColor: 0xFF333333)); | 65 decoration: new BoxDecoration(backgroundColor: 0xFF333333)); |
68 | 66 |
69 // Purple and blue cells | 67 // Purple and blue cells |
70 addFlexChild(row, 0x77FF00FF, flex: 1); | 68 addFlexChild(row, 0x77FF00FF, flex: 1); |
71 addFlexChild(row, 0xFF0000FF, flex: 2); | 69 addFlexChild(row, 0xFF0000FF, flex: 2); |
72 | 70 |
73 root.add(row); | 71 root.add(row); |
74 row.parentData.flex = 3; | 72 row.parentData.flex = 3; |
75 | 73 |
76 app = new AppView(root); | 74 app = new AppView(root); |
77 | 75 |
78 } | 76 } |
OLD | NEW |