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:math'; | 5 import 'dart:math'; |
6 import 'dart:sky'; | 6 import 'dart:sky'; |
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; | |
11 final double desiredWidth; | |
10 final int backgroundColor; | 12 final int backgroundColor; |
11 | 13 |
12 RenderSolidColor(int backgroundColor) | 14 RenderSolidColor(int backgroundColor, { double desiredHeight: double.INFINITY, |
13 : super(new BoxDecoration(backgroundColor: backgroundColor)), | 15 double desiredWidth: double.INFINITY } ) |
14 backgroundColor = backgroundColor; | 16 : desiredHeight = desiredHeight, |
17 desiredWidth = desiredWidth, | |
18 backgroundColor = backgroundColor, | |
19 super(new BoxDecoration(backgroundColor: backgroundColor)); | |
15 | 20 |
16 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | 21 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { |
17 return new BoxDimensions.withConstraints(constraints, height: 200.0); | 22 return new BoxDimensions.withConstraints(constraints, |
23 height: desiredHeight, | |
24 width: desiredWidth); | |
18 } | 25 } |
19 | 26 |
20 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { | 27 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { |
21 width = constraints.constrainWidth(constraints.maxWidth); | 28 width = constraints.constrainWidth(desiredWidth); |
22 height = constraints.constrainHeight(200.0); | 29 height = constraints.constrainHeight(desiredHeight); |
23 layoutDone(); | 30 layoutDone(); |
24 } | 31 } |
25 | 32 |
26 bool handlePointer(PointerEvent event, { double x: 0.0, double y: 0.0 }) { | 33 bool handlePointer(PointerEvent event, { double x: 0.0, double y: 0.0 }) { |
27 if (event.type == 'pointerdown') { | 34 if (event.type == 'pointerdown') { |
28 setBoxDecoration(new BoxDecoration(backgroundColor: 0xFFFF0000)); | 35 setBoxDecoration(new BoxDecoration(backgroundColor: 0xFFFF0000)); |
29 return true; | 36 return true; |
30 } | 37 } |
31 | 38 |
32 if (event.type == 'pointerup') { | 39 if (event.type == 'pointerup') { |
(...skipping 16 matching lines...) Expand all Loading... | |
49 bool handleEvent(Event event) { | 56 bool handleEvent(Event event) { |
50 if (event is! PointerEvent) | 57 if (event is! PointerEvent) |
51 return false; | 58 return false; |
52 return renderView.handlePointer(event, x: event.x, y: event.y); | 59 return renderView.handlePointer(event, x: event.x, y: event.y); |
53 } | 60 } |
54 | 61 |
55 void main() { | 62 void main() { |
56 view.setEventCallback(handleEvent); | 63 view.setEventCallback(handleEvent); |
57 view.setBeginFrameCallback(beginFrame); | 64 view.setBeginFrameCallback(beginFrame); |
58 | 65 |
59 var root = new RenderBlock( | 66 var root = new RenderFlex( |
60 decoration: new BoxDecoration(backgroundColor: 0xFF00FFFF), | 67 direction: FlexDirection.Vertical, |
68 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); | |
69 | |
70 void addFlexChild(RenderFlex renderFlex, int backgroundColor, { int flex: 0 }) { | |
Hixie
2015/05/23 00:34:20
renderFlex => parent
| |
71 RenderNode child = new RenderSolidColor(backgroundColor); | |
72 renderFlex.add(child); | |
73 renderFlex.setParentData(child); | |
Hixie
2015/05/23 00:34:20
add() implies setParentData()
| |
74 child.parentData.flex = flex; | |
75 } | |
76 | |
77 // Yellow bar at top | |
78 addFlexChild(root, 0xFFFFFF00, flex: 1); | |
79 | |
80 // Turquoise box | |
81 root.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desiredWidth: 100.0)); | |
82 | |
83 // Green and cyan render block with padding | |
84 var renderBlock = new RenderBlock( | |
85 decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF), | |
61 padding: const EdgeDims(10.0, 10.0, 10.0, 10.0)); | 86 padding: const EdgeDims(10.0, 10.0, 10.0, 10.0)); |
62 | 87 |
63 root.add(new RenderSolidColor(0xFF00FF00)); | 88 renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredHeight: 50.0, desiredW idth: 100.0)); |
64 root.add(new RenderSolidColor(0xFF0000FF)); | 89 renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desired Width: 50.0)); |
90 | |
91 root.add(renderBlock); | |
92 | |
93 var row = new RenderFlex( | |
94 direction: FlexDirection.Horizontal, | |
95 decoration: new BoxDecoration(backgroundColor: 0xFF333333)); | |
96 | |
97 // Purple and blue cells | |
98 addFlexChild(row, 0x77FF00FF, flex: 1); | |
99 addFlexChild(row, 0xFF0000FF, flex: 2); | |
100 | |
101 root.add(row); | |
102 root.setParentData(row); | |
103 row.parentData.flex = 3; | |
65 | 104 |
66 renderView = new RenderView(root: root); | 105 renderView = new RenderView(root: root); |
67 renderView.layout(newWidth: view.width, newHeight: view.height); | 106 renderView.layout(newWidth: view.width, newHeight: view.height); |
68 | 107 |
69 view.scheduleFrame(); | 108 view.scheduleFrame(); |
70 } | 109 } |
OLD | NEW |