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 }) |
Hixie
2015/05/28 18:45:22
If Size was a constant class, you could default it
| |
15 this.desiredWidth: double.INFINITY }) | |
16 : backgroundColor = backgroundColor, | 14 : backgroundColor = backgroundColor, |
17 super(new BoxDecoration(backgroundColor: backgroundColor)); | 15 super(new BoxDecoration(backgroundColor: backgroundColor)); |
18 | 16 |
19 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | 17 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { |
20 return new BoxDimensions.withConstraints(constraints, | 18 return new BoxDimensions.withConstraints(constraints, |
21 height: desiredHeight, | 19 width: desiredSize.width, |
22 width: desiredWidth); | 20 height: desiredSize.height); |
Hixie
2015/05/28 18:45:22
This would be simplified by withConstraints() taki
| |
23 } | 21 } |
24 | 22 |
25 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { | 23 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { |
26 width = constraints.constrainWidth(desiredWidth); | 24 size = constraints.constrain(desiredSize); |
27 height = constraints.constrainHeight(desiredHeight); | |
28 layoutDone(); | 25 layoutDone(); |
29 } | 26 } |
30 | 27 |
31 void handlePointer(PointerEvent event) { | 28 void handlePointer(PointerEvent event) { |
32 if (event.type == 'pointerdown') | 29 if (event.type == 'pointerdown') |
33 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); | 30 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); |
34 else if (event.type == 'pointerup') | 31 else if (event.type == 'pointerup') |
35 decoration = new BoxDecoration(backgroundColor: backgroundColor); | 32 decoration = new BoxDecoration(backgroundColor: backgroundColor); |
36 } | 33 } |
37 } | 34 } |
38 | 35 |
39 AppView app; | 36 AppView app; |
40 | 37 |
41 void main() { | 38 void main() { |
42 var root = new RenderFlex( | 39 var root = new RenderFlex( |
43 direction: FlexDirection.Vertical, | 40 direction: FlexDirection.Vertical, |
44 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); | 41 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); |
45 | 42 |
46 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) { | 43 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) { |
47 RenderNode child = new RenderSolidColor(backgroundColor); | 44 RenderNode child = new RenderSolidColor(backgroundColor, desiredSize: new Si ze.infinite()); |
Hixie
2015/05/28 18:45:22
I think the old code looked better (implying infin
| |
48 parent.add(child); | 45 parent.add(child); |
49 child.parentData.flex = flex; | 46 child.parentData.flex = flex; |
50 } | 47 } |
51 | 48 |
52 // Yellow bar at top | 49 // Yellow bar at top |
53 addFlexChild(root, 0xFFFFFF00, flex: 1); | 50 addFlexChild(root, 0xFFFFFF00, flex: 1); |
54 | 51 |
55 // Turquoise box | 52 // Turquoise box |
56 root.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desiredWidth: 100.0)); | 53 root.add(new RenderSolidColor(0x7700FFFF, desiredSize: new Size(100.0, 100.0)) ); |
57 | 54 |
58 // Green and cyan render block with padding | 55 // Green and cyan render block with padding |
59 var renderBlock = new RenderBlock(decoration: new BoxDecoration(backgroundColo r: 0xFFFFFFFF)); | 56 var renderBlock = new RenderBlock(decoration: new BoxDecoration(backgroundColo r: 0xFFFFFFFF)); |
60 | 57 |
61 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))); |
62 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))); |
63 | 60 |
64 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 )); |
65 | 62 |
66 var row = new RenderFlex( | 63 var row = new RenderFlex( |
67 direction: FlexDirection.Horizontal, | 64 direction: FlexDirection.Horizontal, |
68 decoration: new BoxDecoration(backgroundColor: 0xFF333333)); | 65 decoration: new BoxDecoration(backgroundColor: 0xFF333333)); |
69 | 66 |
70 // Purple and blue cells | 67 // Purple and blue cells |
71 addFlexChild(row, 0x77FF00FF, flex: 1); | 68 addFlexChild(row, 0x77FF00FF, flex: 1); |
72 addFlexChild(row, 0xFF0000FF, flex: 2); | 69 addFlexChild(row, 0xFF0000FF, flex: 2); |
73 | 70 |
74 root.add(row); | 71 root.add(row); |
75 row.parentData.flex = 3; | 72 row.parentData.flex = 3; |
76 | 73 |
77 app = new AppView(root); | 74 app = new AppView(root); |
78 | 75 |
79 } | 76 } |
OLD | NEW |