OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
Hixie
2015/05/28 19:14:28
This shouldn't be an example. It should be somethi
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 import 'dart:sky'; | |
6 import 'package:sky/framework/app.dart'; | |
7 import 'package:sky/framework/layout2.dart'; | |
8 | |
9 class RenderParagraph extends RenderDecoratedBox { | |
10 final String text; | |
11 LayoutRoot _layoutRoot = new LayoutRoot(); | |
12 Document _document; | |
13 BoxConstraints _constraints; | |
Hixie
2015/05/28 19:14:29
You can remove _constraints (dartanalyzer should h
| |
14 | |
15 RenderParagraph(String this.text) : | |
16 super(new BoxDecoration(backgroundColor: 0xFFFFFFFF)) { | |
17 _document = new Document(); | |
18 _layoutRoot.rootElement = _document.createElement('p'); | |
19 _layoutRoot.rootElement.appendChild(_document.createText(this.text)); | |
20 } | |
21 | |
22 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | |
23 assert(false); | |
24 return null; | |
25 } | |
26 | |
27 void performLayout() { | |
28 _layoutRoot.maxWidth = constraints.constrainWidth(double.INFINITY); | |
Hixie
2015/05/28 19:14:28
Why not _layoutRoot.maxWidth = constraints.maxWidt
| |
29 _layoutRoot.layout(); | |
30 width = _layoutRoot.rootElement.width; | |
31 height = _layoutRoot.rootElement.height; | |
32 } | |
33 | |
34 void hitTestChildren(HitTestResult result, { double x, double y }) { | |
35 // defaultHitTestChildren(result, x: x, y: y); | |
36 } | |
37 | |
38 void paint(RenderNodeDisplayList canvas) { | |
39 super.paint(canvas); | |
40 _layoutRoot.paint(canvas); | |
41 } | |
42 } | |
43 | |
44 class RenderSolidColor extends RenderDecoratedBox { | |
45 final double desiredHeight; | |
46 final double desiredWidth; | |
47 final int backgroundColor; | |
48 | |
49 RenderSolidColor(int backgroundColor, { this.desiredHeight: double.INFINITY, | |
50 this.desiredWidth: double.INFINITY }) | |
51 : backgroundColor = backgroundColor, | |
52 super(new BoxDecoration(backgroundColor: backgroundColor)); | |
53 | |
54 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | |
55 return new BoxDimensions.withConstraints(constraints, | |
56 height: desiredHeight, | |
57 width: desiredWidth); | |
58 } | |
59 | |
60 void performLayout() { | |
61 width = constraints.constrainWidth(desiredWidth); | |
62 height = constraints.constrainHeight(desiredHeight); | |
63 } | |
64 | |
65 void handlePointer(PointerEvent event) { | |
66 if (event.type == 'pointerdown') | |
67 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); | |
68 else if (event.type == 'pointerup') | |
69 decoration = new BoxDecoration(backgroundColor: backgroundColor); | |
70 } | |
71 } | |
72 | |
73 AppView app; | |
74 | |
75 void main() { | |
76 var root = new RenderFlex( | |
77 direction: FlexDirection.Vertical, | |
78 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); | |
79 | |
80 RenderNode child = new RenderSolidColor(0xFFFFFF00); | |
81 root.add(child); | |
82 child.parentData.flex = 2; | |
83 | |
84 // The internet is a beautiful place. https://baconipsum.com/ | |
85 String meatyString = """Bacon ipsum dolor amet ham fatback tri-tip, prosciutto | |
86 porchetta bacon kevin meatball meatloaf pig beef ribs chicken. Brisket ribeye | |
87 andouille leberkas capicola meatloaf. Chicken pig ball tip pork picanha bresaola | |
88 alcatra. Pork pork belly alcatra, flank chuck drumstick biltong doner jowl. | |
89 Pancetta meatball tongue tenderloin rump tail jowl boudin."""; | |
90 | |
91 child = new RenderParagraph(meatyString); | |
92 root.add(child); | |
93 child.parentData.flex = 1; | |
94 | |
95 app = new AppView(root); | |
96 } | |
OLD | NEW |