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