OLD | NEW |
| 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 |
| 3 // found in the LICENSE file. |
1 | 4 |
2 import 'package:vector_math/vector_math.dart'; | 5 import 'package:vector_math/vector_math.dart'; |
3 | 6 |
4 import '../rendering/block.dart'; | 7 import '../rendering/block.dart'; |
5 import '../rendering/box.dart'; | 8 import '../rendering/box.dart'; |
6 import '../rendering/flex.dart'; | 9 import '../rendering/flex.dart'; |
7 import '../rendering/object.dart'; | 10 import '../rendering/object.dart'; |
8 import '../rendering/paragraph.dart'; | 11 import '../rendering/paragraph.dart'; |
9 import '../rendering/stack.dart'; | 12 import '../rendering/stack.dart'; |
10 import 'ui_node.dart'; | 13 import 'ui_node.dart'; |
11 | 14 |
12 export '../rendering/box.dart' show BoxConstraints, BoxDecoration, Border, Borde
rSide, EdgeDims; | 15 export '../rendering/box.dart' show BoxConstraints, BoxDecoration, Border, Borde
rSide, EdgeDims; |
13 export '../rendering/flex.dart' show FlexDirection, FlexJustifyContent, FlexAlig
nItems; | 16 export '../rendering/flex.dart' show FlexDirection, FlexJustifyContent, FlexAlig
nItems; |
14 export '../rendering/object.dart' show Point, Size, Rect, Color, Paint, Path; | 17 export '../rendering/object.dart' show Point, Size, Rect, Color, Paint, Path; |
15 export 'ui_node.dart' show UINode, Component, App, EventListenerNode, ParentData
Node; | 18 export 'ui_node.dart' show UINode, Component, App, EventListenerNode, ParentData
Node; |
16 | 19 |
17 | 20 |
18 // PAINTING NODES | 21 // PAINTING NODES |
19 | 22 |
20 class Opacity extends OneChildRenderObjectWrapper { | 23 class Opacity extends OneChildRenderObjectWrapper { |
21 Opacity({ this.opacity, UINode child, Object key }) | 24 Opacity({ String key, this.opacity, UINode child }) |
22 : super(child: child, key: key); | 25 : super(key: key, child: child); |
23 | 26 |
24 RenderOpacity get root { RenderOpacity result = super.root; return result; } | 27 RenderOpacity get root => super.root; |
25 final double opacity; | 28 final double opacity; |
26 | 29 |
27 RenderOpacity createNode() => new RenderOpacity(opacity: opacity); | 30 RenderOpacity createNode() => new RenderOpacity(opacity: opacity); |
28 | 31 |
29 void syncRenderObject(Opacity old) { | 32 void syncRenderObject(Opacity old) { |
30 super.syncRenderObject(old); | 33 super.syncRenderObject(old); |
31 root.opacity = opacity; | 34 root.opacity = opacity; |
32 } | 35 } |
33 } | 36 } |
34 | 37 |
35 class DecoratedBox extends OneChildRenderObjectWrapper { | 38 class DecoratedBox extends OneChildRenderObjectWrapper { |
36 | 39 |
37 DecoratedBox({ this.decoration, UINode child, Object key }) | 40 DecoratedBox({ String key, this.decoration, UINode child }) |
38 : super(child: child, key: key); | 41 : super(key: key, child: child); |
39 | 42 |
40 RenderDecoratedBox get root { RenderDecoratedBox result = super.root; return r
esult; } | 43 RenderDecoratedBox get root => super.root; |
41 final BoxDecoration decoration; | 44 final BoxDecoration decoration; |
42 | 45 |
43 RenderDecoratedBox createNode() => new RenderDecoratedBox(decoration: decorati
on); | 46 RenderDecoratedBox createNode() => new RenderDecoratedBox(decoration: decorati
on); |
44 | 47 |
45 void syncRenderObject(DecoratedBox old) { | 48 void syncRenderObject(DecoratedBox old) { |
46 super.syncRenderObject(old); | 49 super.syncRenderObject(old); |
47 root.decoration = decoration; | 50 root.decoration = decoration; |
48 } | 51 } |
49 | 52 |
50 } | 53 } |
51 | 54 |
52 class CustomPaint extends OneChildRenderObjectWrapper { | 55 class CustomPaint extends OneChildRenderObjectWrapper { |
53 | 56 |
54 CustomPaint({ this.callback, this.token, UINode child, Object key }) | 57 CustomPaint({ String key, this.callback, this.token, UINode child }) |
55 : super(child: child, key: key); | 58 : super(key: key, child: child); |
56 | 59 |
57 RenderCustomPaint get root { RenderCustomPaint result = super.root; return res
ult; } | 60 RenderCustomPaint get root => super.root; |
58 final CustomPaintCallback callback; | 61 final CustomPaintCallback callback; |
59 final dynamic token; // set this to be repainted automatically when the token
changes | 62 final dynamic token; // set this to be repainted automatically when the token
changes |
60 | 63 |
61 RenderCustomPaint createNode() => new RenderCustomPaint(callback: callback); | 64 RenderCustomPaint createNode() => new RenderCustomPaint(callback: callback); |
62 | 65 |
63 void syncRenderObject(CustomPaint old) { | 66 void syncRenderObject(CustomPaint old) { |
64 super.syncRenderObject(old); | 67 super.syncRenderObject(old); |
65 if (old != null && old.token != token) | 68 if (old != null && old.token != token) |
66 root.markNeedsPaint(); | 69 root.markNeedsPaint(); |
67 root.callback = callback; | 70 root.callback = callback; |
68 } | 71 } |
69 | 72 |
70 void remove() { | 73 void remove() { |
71 root.callback = null; | 74 root.callback = null; |
72 super.remove(); | 75 super.remove(); |
73 } | 76 } |
74 | 77 |
75 } | 78 } |
76 | 79 |
77 class ClipRect extends OneChildRenderObjectWrapper { | 80 class ClipRect extends OneChildRenderObjectWrapper { |
| 81 ClipRect({ String key, UINode child }) |
| 82 : super(key: key, child: child); |
78 | 83 |
79 ClipRect({ UINode child, Object key }) | 84 RenderClipRect get root => super.root; |
80 : super(child: child, key: key); | |
81 | |
82 RenderClipRect get root { RenderClipRect result = super.root; return result; } | |
83 RenderClipRect createNode() => new RenderClipRect(); | 85 RenderClipRect createNode() => new RenderClipRect(); |
84 } | 86 } |
85 | 87 |
86 class ClipOval extends OneChildRenderObjectWrapper { | 88 class ClipOval extends OneChildRenderObjectWrapper { |
| 89 ClipOval({ String key, UINode child }) |
| 90 : super(key: key, child: child); |
87 | 91 |
88 ClipOval({ UINode child, Object key }) | 92 RenderClipOval get root => super.root; |
89 : super(child: child, key: key); | |
90 | |
91 RenderClipOval get root { RenderClipOval result = super.root; return result; } | |
92 RenderClipOval createNode() => new RenderClipOval(); | 93 RenderClipOval createNode() => new RenderClipOval(); |
93 } | 94 } |
94 | 95 |
95 | 96 |
96 // POSITIONING AND SIZING NODES | 97 // POSITIONING AND SIZING NODES |
97 | 98 |
98 class Transform extends OneChildRenderObjectWrapper { | 99 class Transform extends OneChildRenderObjectWrapper { |
99 | 100 |
100 Transform({ this.transform, UINode child, Object key }) | 101 Transform({ String key, this.transform, UINode child }) |
101 : super(child: child, key: key); | 102 : super(key: key, child: child); |
102 | 103 |
103 RenderTransform get root { RenderTransform result = super.root; return result;
} | 104 RenderTransform get root => super.root; |
104 final Matrix4 transform; | 105 final Matrix4 transform; |
105 | 106 |
106 RenderTransform createNode() => new RenderTransform(transform: transform); | 107 RenderTransform createNode() => new RenderTransform(transform: transform); |
107 | 108 |
108 void syncRenderObject(Transform old) { | 109 void syncRenderObject(Transform old) { |
109 super.syncRenderObject(old); | 110 super.syncRenderObject(old); |
110 root.transform = transform; | 111 root.transform = transform; |
111 } | 112 } |
112 | 113 |
113 } | 114 } |
114 | 115 |
115 class Padding extends OneChildRenderObjectWrapper { | 116 class Padding extends OneChildRenderObjectWrapper { |
116 | 117 |
117 Padding({ this.padding, UINode child, Object key }) | 118 Padding({ String key, this.padding, UINode child }) |
118 : super(child: child, key: key); | 119 : super(key: key, child: child); |
119 | 120 |
120 RenderPadding get root { RenderPadding result = super.root; return result; } | 121 RenderPadding get root => super.root; |
121 final EdgeDims padding; | 122 final EdgeDims padding; |
122 | 123 |
123 RenderPadding createNode() => new RenderPadding(padding: padding); | 124 RenderPadding createNode() => new RenderPadding(padding: padding); |
124 | 125 |
125 void syncRenderObject(Padding old) { | 126 void syncRenderObject(Padding old) { |
126 super.syncRenderObject(old); | 127 super.syncRenderObject(old); |
127 root.padding = padding; | 128 root.padding = padding; |
128 } | 129 } |
129 | 130 |
130 } | 131 } |
131 | 132 |
132 class Center extends OneChildRenderObjectWrapper { | 133 class Center extends OneChildRenderObjectWrapper { |
| 134 Center({ String key, UINode child }) |
| 135 : super(key: key, child: child); |
133 | 136 |
134 Center({ UINode child, Object key }) | 137 RenderPositionedBox get root => super.root; |
135 : super(child: child, key: key); | |
136 | |
137 RenderPositionedBox get root { RenderPositionedBox result = super.root; return
result; } | |
138 | |
139 RenderPositionedBox createNode() => new RenderPositionedBox(); | 138 RenderPositionedBox createNode() => new RenderPositionedBox(); |
140 | |
141 } | 139 } |
142 | 140 |
143 class SizedBox extends OneChildRenderObjectWrapper { | 141 class SizedBox extends OneChildRenderObjectWrapper { |
144 | 142 |
145 SizedBox({ | 143 SizedBox({ |
| 144 String key, |
146 this.width, | 145 this.width, |
147 this.height, | 146 this.height, |
148 UINode child, | 147 UINode child |
149 Object key | 148 }) : super(key: key, child: child); |
150 }) : super(child: child, key: key); | |
151 | 149 |
152 RenderConstrainedBox get root { RenderConstrainedBox result = super.root; retu
rn result; } | 150 RenderConstrainedBox get root => super.root; |
153 | 151 |
154 final double width; | 152 final double width; |
155 final double height; | 153 final double height; |
156 | 154 |
157 RenderConstrainedBox createNode() => new RenderConstrainedBox(additionalConstr
aints: _additionalConstraints()); | 155 RenderConstrainedBox createNode() => new RenderConstrainedBox(additionalConstr
aints: _additionalConstraints()); |
158 | 156 |
159 BoxConstraints _additionalConstraints() { | 157 BoxConstraints _additionalConstraints() { |
160 var result = const BoxConstraints(); | 158 var result = const BoxConstraints(); |
161 if (width != null) | 159 if (width != null) |
162 result = result.applyWidth(width); | 160 result = result.applyWidth(width); |
163 if (height != null) | 161 if (height != null) |
164 result = result.applyHeight(height); | 162 result = result.applyHeight(height); |
165 return result; | 163 return result; |
166 } | 164 } |
167 | 165 |
168 void syncRenderObject(SizedBox old) { | 166 void syncRenderObject(SizedBox old) { |
169 super.syncRenderObject(old); | 167 super.syncRenderObject(old); |
170 root.additionalConstraints = _additionalConstraints(); | 168 root.additionalConstraints = _additionalConstraints(); |
171 } | 169 } |
172 | 170 |
173 } | 171 } |
174 | 172 |
175 class ConstrainedBox extends OneChildRenderObjectWrapper { | 173 class ConstrainedBox extends OneChildRenderObjectWrapper { |
176 | 174 |
177 ConstrainedBox({ this.constraints, UINode child, Object key }) | 175 ConstrainedBox({ String key, this.constraints, UINode child }) |
178 : super(child: child, key: key); | 176 : super(key: key, child: child); |
179 | 177 |
180 RenderConstrainedBox get root { RenderConstrainedBox result = super.root; retu
rn result; } | 178 RenderConstrainedBox get root => super.root; |
| 179 |
181 final BoxConstraints constraints; | 180 final BoxConstraints constraints; |
182 | 181 |
183 RenderConstrainedBox createNode() => new RenderConstrainedBox(additionalConstr
aints: constraints); | 182 RenderConstrainedBox createNode() => new RenderConstrainedBox(additionalConstr
aints: constraints); |
184 | 183 |
185 void syncRenderObject(ConstrainedBox old) { | 184 void syncRenderObject(ConstrainedBox old) { |
186 super.syncRenderObject(old); | 185 super.syncRenderObject(old); |
187 root.additionalConstraints = constraints; | 186 root.additionalConstraints = constraints; |
188 } | 187 } |
189 | 188 |
190 } | 189 } |
191 | 190 |
192 class ShrinkWrapWidth extends OneChildRenderObjectWrapper { | 191 class ShrinkWrapWidth extends OneChildRenderObjectWrapper { |
| 192 ShrinkWrapWidth({ String key, UINode child }) |
| 193 : super(key: key, child: child); |
193 | 194 |
194 ShrinkWrapWidth({ UINode child, Object key }) : super(child: child, key: key); | 195 RenderShrinkWrapWidth get root => super.root; |
195 | |
196 RenderShrinkWrapWidth get root { RenderShrinkWrapWidth result = super.root; re
turn result; } | |
197 | |
198 RenderShrinkWrapWidth createNode() => new RenderShrinkWrapWidth(); | 196 RenderShrinkWrapWidth createNode() => new RenderShrinkWrapWidth(); |
199 | |
200 } | 197 } |
201 | 198 |
202 class SizeObserver extends OneChildRenderObjectWrapper { | 199 class SizeObserver extends OneChildRenderObjectWrapper { |
203 | 200 |
204 SizeObserver({ this.callback, UINode child, Object key }) | 201 SizeObserver({ String key, this.callback, UINode child }) |
205 : super(child: child, key: key); | 202 : super(key: key, child: child); |
206 | 203 |
207 RenderSizeObserver get root { RenderSizeObserver result = super.root; return r
esult; } | 204 RenderSizeObserver get root => super.root; |
208 final SizeChangedCallback callback; | 205 final SizeChangedCallback callback; |
209 | 206 |
210 RenderSizeObserver createNode() => new RenderSizeObserver(callback: callback); | 207 RenderSizeObserver createNode() => new RenderSizeObserver(callback: callback); |
211 | 208 |
212 void syncRenderObject(SizeObserver old) { | 209 void syncRenderObject(SizeObserver old) { |
213 super.syncRenderObject(old); | 210 super.syncRenderObject(old); |
214 root.callback = callback; | 211 root.callback = callback; |
215 } | 212 } |
216 | 213 |
217 void remove() { | 214 void remove() { |
218 root.callback = null; | 215 root.callback = null; |
219 super.remove(); | 216 super.remove(); |
220 } | 217 } |
221 | 218 |
222 } | 219 } |
223 | 220 |
224 | 221 |
225 // CONVENIENCE CLASS TO COMBINE COMMON PAINTING, POSITIONING, AND SIZING NODES | 222 // CONVENIENCE CLASS TO COMBINE COMMON PAINTING, POSITIONING, AND SIZING NODES |
226 | 223 |
227 class Container extends Component { | 224 class Container extends Component { |
228 | 225 |
229 Container({ | 226 Container({ |
230 Object key, | 227 String key, |
231 this.child, | 228 this.child, |
232 this.constraints, | 229 this.constraints, |
233 this.decoration, | 230 this.decoration, |
234 this.width, | 231 this.width, |
235 this.height, | 232 this.height, |
236 this.margin, | 233 this.margin, |
237 this.padding, | 234 this.padding, |
238 this.transform | 235 this.transform |
239 }) : super(key: key); | 236 }) : super(key: key); |
240 | 237 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 277 |
281 return current; | 278 return current; |
282 } | 279 } |
283 | 280 |
284 } | 281 } |
285 | 282 |
286 | 283 |
287 // LAYOUT NODES | 284 // LAYOUT NODES |
288 | 285 |
289 class Block extends MultiChildRenderObjectWrapper { | 286 class Block extends MultiChildRenderObjectWrapper { |
290 | 287 Block(List<UINode> children, { String key }) |
291 Block(List<UINode> children, { Object key }) | |
292 : super(key: key, children: children); | 288 : super(key: key, children: children); |
293 | 289 |
294 RenderBlock get root { RenderBlock result = super.root; return result; } | 290 RenderBlock get root => super.root; |
295 RenderBlock createNode() => new RenderBlock(); | 291 RenderBlock createNode() => new RenderBlock(); |
296 | |
297 } | 292 } |
298 | 293 |
299 class Stack extends MultiChildRenderObjectWrapper { | 294 class Stack extends MultiChildRenderObjectWrapper { |
300 | 295 Stack(List<UINode> children, { String key }) |
301 Stack(List<UINode> children, { Object key }) | |
302 : super(key: key, children: children); | 296 : super(key: key, children: children); |
303 | 297 |
304 RenderStack get root { RenderStack result = super.root; return result; } | 298 RenderStack get root => super.root; |
305 RenderStack createNode() => new RenderStack(); | 299 RenderStack createNode() => new RenderStack(); |
306 | |
307 } | 300 } |
308 | 301 |
309 class Positioned extends ParentDataNode { | 302 class Positioned extends ParentDataNode { |
310 Positioned({ | 303 Positioned({ |
| 304 String key, |
311 UINode child, | 305 UINode child, |
312 double top, | 306 double top, |
313 double right, | 307 double right, |
314 double bottom, | 308 double bottom, |
315 double left | 309 double left |
316 }) : super(content, new StackParentData()..top = top | 310 }) : super(content, |
317 ..right = right | 311 new StackParentData()..top = top |
318 ..bottom = bottom | 312 ..right = right |
319 ..left = left); | 313 ..bottom = bottom |
| 314 ..left = left, |
| 315 key: key); |
320 } | 316 } |
321 | 317 |
322 class Flex extends MultiChildRenderObjectWrapper { | 318 class Flex extends MultiChildRenderObjectWrapper { |
323 | 319 |
324 Flex(List<UINode> children, { | 320 Flex(List<UINode> children, { |
325 Object key, | 321 String key, |
326 this.direction: FlexDirection.horizontal, | 322 this.direction: FlexDirection.horizontal, |
327 this.justifyContent: FlexJustifyContent.flexStart, | 323 this.justifyContent: FlexJustifyContent.flexStart, |
328 this.alignItems: FlexAlignItems.center | 324 this.alignItems: FlexAlignItems.center |
329 }) : super(key: key, children: children); | 325 }) : super(key: key, children: children); |
330 | 326 |
331 RenderFlex get root { RenderFlex result = super.root; return result; } | 327 RenderFlex get root => super.root; |
332 RenderFlex createNode() => new RenderFlex(direction: this.direction); | 328 RenderFlex createNode() => new RenderFlex(direction: this.direction); |
333 | 329 |
334 final FlexDirection direction; | 330 final FlexDirection direction; |
335 final FlexJustifyContent justifyContent; | 331 final FlexJustifyContent justifyContent; |
336 final FlexAlignItems alignItems; | 332 final FlexAlignItems alignItems; |
337 | 333 |
338 void syncRenderObject(UINode old) { | 334 void syncRenderObject(UINode old) { |
339 super.syncRenderObject(old); | 335 super.syncRenderObject(old); |
340 root.direction = direction; | 336 root.direction = direction; |
341 root.justifyContent = justifyContent; | 337 root.justifyContent = justifyContent; |
342 root.alignItems = alignItems; | 338 root.alignItems = alignItems; |
343 } | 339 } |
344 | 340 |
345 } | 341 } |
346 | 342 |
347 class Flexible extends ParentDataNode { | 343 class Flexible extends ParentDataNode { |
348 Flexible({ UINode child, int flex: 1, Object key }) | 344 Flexible({ String key, UINode child, int flex: 1 }) |
349 : super(child, new FlexBoxParentData()..flex = flex, key: key); | 345 : super(child, new FlexBoxParentData()..flex = flex, key: key); |
350 } | 346 } |
351 | 347 |
352 class Paragraph extends RenderObjectWrapper { | 348 class Paragraph extends RenderObjectWrapper { |
353 | 349 |
354 Paragraph({ Object key, this.text, this.style }) : super(key: key); | 350 Paragraph({ String key, this.text, this.style }) : super(key: key); |
355 | 351 |
356 RenderParagraph get root { RenderParagraph result = super.root; return result;
} | 352 RenderParagraph get root => super.root; |
357 RenderParagraph createNode() => new RenderParagraph(text: text, style: style); | 353 RenderParagraph createNode() => new RenderParagraph(text: text, style: style); |
358 | 354 |
359 final String text; | 355 final String text; |
360 final TextStyle style; | 356 final TextStyle style; |
361 | 357 |
362 void syncRenderObject(UINode old) { | 358 void syncRenderObject(UINode old) { |
363 super.syncRenderObject(old); | 359 super.syncRenderObject(old); |
364 root.text = text; | 360 root.text = text; |
365 root.style = style; | 361 root.style = style; |
366 } | 362 } |
367 | 363 |
368 void insert(RenderObjectWrapper child, dynamic slot) { | 364 void insert(RenderObjectWrapper child, dynamic slot) { |
369 assert(false); | 365 assert(false); |
370 // Paragraph does not support having children currently | 366 // Paragraph does not support having children currently |
371 } | 367 } |
372 | 368 |
373 } | 369 } |
374 | 370 |
375 class Text extends Component { | 371 class Text extends Component { |
376 Text(this.data, { TextStyle this.style }) : super(key: '*text*'); | 372 Text(this.data, { TextStyle this.style }) : super(key: '*text*'); |
377 final String data; | 373 final String data; |
378 final TextStyle style; | 374 final TextStyle style; |
379 bool get interchangeable => true; | 375 bool get interchangeable => true; |
380 UINode build() => new Paragraph(text: data, style: style); | 376 UINode build() => new Paragraph(text: data, style: style); |
381 } | 377 } |
382 | 378 |
383 class Image extends RenderObjectWrapper { | 379 class Image extends RenderObjectWrapper { |
384 | 380 |
385 Image({ | 381 Image({ |
386 Object key, | 382 String key, |
387 this.src, | 383 this.src, |
388 this.size | 384 this.size |
389 }) : super(key: key); | 385 }) : super(key: key); |
390 | 386 |
391 RenderImage get root { RenderImage result = super.root; return result; } | 387 RenderImage get root => super.root; |
392 RenderImage createNode() => new RenderImage(this.src, this.size); | 388 RenderImage createNode() => new RenderImage(this.src, this.size); |
393 | 389 |
394 final String src; | 390 final String src; |
395 final Size size; | 391 final Size size; |
396 | 392 |
397 void syncRenderObject(UINode old) { | 393 void syncRenderObject(UINode old) { |
398 super.syncRenderObject(old); | 394 super.syncRenderObject(old); |
399 root.src = src; | 395 root.src = src; |
400 root.requestedSize = size; | 396 root.requestedSize = size; |
401 } | 397 } |
402 | 398 |
403 void insert(RenderObjectWrapper child, dynamic slot) { | 399 void insert(RenderObjectWrapper child, dynamic slot) { |
404 assert(false); | 400 assert(false); |
405 // Image does not support having children currently | 401 // Image does not support having children currently |
406 } | 402 } |
407 | 403 |
408 } | 404 } |
OLD | NEW |