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 RenderParagraph extends RenderDecoratedBox { |
| 10 final String text; |
| 11 LayoutRoot _layoutRoot = new LayoutRoot(); |
| 12 Document _document; |
| 13 |
| 14 RenderParagraph(String this.text) : |
| 15 super(new BoxDecoration(backgroundColor: 0xFFFFFFFF)) { |
| 16 _document = new Document(); |
| 17 _layoutRoot.rootElement = _document.createElement('p'); |
| 18 _layoutRoot.rootElement.appendChild(_document.createText(this.text)); |
| 19 } |
| 20 |
| 21 void performLayout() { |
| 22 _layoutRoot.maxWidth = constraints.maxWidth; |
| 23 _layoutRoot.minWidth = constraints.minWidth; |
| 24 _layoutRoot.layout(); |
| 25 width = _layoutRoot.rootElement.width; |
| 26 height = _layoutRoot.rootElement.height; |
| 27 } |
| 28 |
| 29 void hitTestChildren(HitTestResult result, { double x, double y }) { |
| 30 // defaultHitTestChildren(result, x: x, y: y); |
| 31 } |
| 32 |
| 33 void paint(RenderNodeDisplayList canvas) { |
| 34 super.paint(canvas); |
| 35 _layoutRoot.paint(canvas); |
| 36 } |
| 37 } |
| 38 |
9 class RenderSolidColor extends RenderDecoratedBox { | 39 class RenderSolidColor extends RenderDecoratedBox { |
10 final double desiredHeight; | 40 final double desiredHeight; |
11 final double desiredWidth; | 41 final double desiredWidth; |
12 final int backgroundColor; | 42 final int backgroundColor; |
13 | 43 |
14 RenderSolidColor(int backgroundColor, { this.desiredHeight: double.INFINITY, | 44 RenderSolidColor(int backgroundColor, { this.desiredHeight: double.INFINITY, |
15 this.desiredWidth: double.INFINITY }) | 45 this.desiredWidth: double.INFINITY }) |
16 : backgroundColor = backgroundColor, | 46 : backgroundColor = backgroundColor, |
17 super(new BoxDecoration(backgroundColor: backgroundColor)); | 47 super(new BoxDecoration(backgroundColor: backgroundColor)); |
18 | 48 |
(...skipping 16 matching lines...) Expand all Loading... |
35 } | 65 } |
36 } | 66 } |
37 | 67 |
38 AppView app; | 68 AppView app; |
39 | 69 |
40 void main() { | 70 void main() { |
41 var root = new RenderFlex( | 71 var root = new RenderFlex( |
42 direction: FlexDirection.Vertical, | 72 direction: FlexDirection.Vertical, |
43 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); | 73 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); |
44 | 74 |
45 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) { | 75 RenderNode child = new RenderSolidColor(0xFFFFFF00); |
46 RenderNode child = new RenderSolidColor(backgroundColor); | 76 root.add(child); |
47 parent.add(child); | 77 child.parentData.flex = 2; |
48 child.parentData.flex = flex; | |
49 } | |
50 | 78 |
51 // Yellow bar at top | 79 // The internet is a beautiful place. https://baconipsum.com/ |
52 addFlexChild(root, 0xFFFFFF00, flex: 1); | 80 String meatyString = """Bacon ipsum dolor amet ham fatback tri-tip, prosciutto |
| 81 porchetta bacon kevin meatball meatloaf pig beef ribs chicken. Brisket ribeye |
| 82 andouille leberkas capicola meatloaf. Chicken pig ball tip pork picanha bresaola |
| 83 alcatra. Pork pork belly alcatra, flank chuck drumstick biltong doner jowl. |
| 84 Pancetta meatball tongue tenderloin rump tail jowl boudin."""; |
53 | 85 |
54 // Turquoise box | 86 child = new RenderParagraph(meatyString); |
55 root.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desiredWidth:
100.0)); | 87 root.add(child); |
56 | 88 child.parentData.flex = 1; |
57 // Green and cyan render block with padding | |
58 var renderBlock = new RenderBlock(decoration: new BoxDecoration(backgroundColo
r: 0xFFFFFFFF)); | |
59 | |
60 renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredHeight: 50.0, desiredW
idth: 100.0)); | |
61 renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredHeight: 100.0, desired
Width: 50.0)); | |
62 | |
63 root.add(new RenderPadding(const EdgeDims(10.0, 10.0, 10.0, 10.0), renderBlock
)); | |
64 | |
65 var row = new RenderFlex( | |
66 direction: FlexDirection.Horizontal, | |
67 decoration: new BoxDecoration(backgroundColor: 0xFF333333)); | |
68 | |
69 // Purple and blue cells | |
70 addFlexChild(row, 0x77FF00FF, flex: 1); | |
71 addFlexChild(row, 0xFF0000FF, flex: 2); | |
72 | |
73 root.add(row); | |
74 row.parentData.flex = 3; | |
75 | 89 |
76 app = new AppView(root); | 90 app = new AppView(root); |
77 | |
78 } | 91 } |
OLD | NEW |