OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 import 'dart:sky' as sky; |
| 6 |
| 7 import 'package:sky/framework/rendering/box.dart'; |
| 8 import 'package:sky/framework/rendering/flex.dart'; |
| 9 import 'package:sky/framework/scheduler.dart'; |
| 10 import 'package:sky/framework/widgets/ui_node.dart'; |
| 11 import 'package:sky/framework/widgets/wrappers.dart'; |
| 12 import 'package:vector_math/vector_math.dart'; |
| 13 |
| 14 import '../lib/solid_color_box.dart'; |
| 15 |
| 16 // Solid colour, RenderObject version |
| 17 void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, { int
flex: 0 }) { |
| 18 RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor); |
| 19 parent.add(child); |
| 20 child.parentData.flex = flex; |
| 21 } |
| 22 |
| 23 // Solid colour, Widget version |
| 24 class Rectangle extends Component { |
| 25 Rectangle(this.color, { Object key }) : super(key: key); |
| 26 final Color color; |
| 27 UINode build() { |
| 28 return new FlexExpandingChild( |
| 29 new Container( |
| 30 decoration: new BoxDecoration(backgroundColor: color) |
| 31 ) |
| 32 ); |
| 33 } |
| 34 } |
| 35 |
| 36 UINode builder() { |
| 37 return new Flex([ |
| 38 new Rectangle(const Color(0xFF00FFFF), key: 'a'), |
| 39 new Container( |
| 40 padding: new EdgeDims.all(10.0), |
| 41 margin: new EdgeDims.all(10.0), |
| 42 decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)), |
| 43 child: new Image(src: "https://www.dartlang.org/logos/dart-logo.png", |
| 44 size: new Size(300.0, 300.0), |
| 45 key: 1 |
| 46 ) |
| 47 ), |
| 48 new Rectangle(const Color(0xFFFFFF00), key: 'b'), |
| 49 ], |
| 50 direction: FlexDirection.vertical, |
| 51 justifyContent: FlexJustifyContent.spaceBetween |
| 52 ); |
| 53 } |
| 54 |
| 55 double timeBase; |
| 56 RenderTransform transformBox; |
| 57 |
| 58 void rotate(double timeStamp) { |
| 59 if (timeBase == null) |
| 60 timeBase = timeStamp; |
| 61 double delta = (timeStamp - timeBase) / 1000; // radians |
| 62 |
| 63 transformBox.setIdentity(); |
| 64 transformBox.translate(transformBox.size.width / 2.0, transformBox.size.height
/ 2.0); |
| 65 transformBox.rotateZ(delta); |
| 66 transformBox.translate(-transformBox.size.width / 2.0, -transformBox.size.heig
ht / 2.0); |
| 67 } |
| 68 |
| 69 void main() { |
| 70 RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical); |
| 71 |
| 72 RenderProxyBox proxy = new RenderProxyBox(); |
| 73 new RenderObjectToUINodeAdapter(proxy, builder); // adds itself to proxy |
| 74 |
| 75 addFlexChildSolidColor(flexRoot, const sky.Color(0xFFFF00FF), flex: 1); |
| 76 flexRoot.add(proxy); |
| 77 addFlexChildSolidColor(flexRoot, const sky.Color(0xFF0000FF), flex: 1); |
| 78 |
| 79 transformBox = new RenderTransform(child: flexRoot, transform: new Matrix4.ide
ntity()); |
| 80 RenderPadding root = new RenderPadding(padding: new EdgeDims.all(20.0), child:
transformBox); |
| 81 |
| 82 // Because we're going to use UINodes, we want to initialise its |
| 83 // AppView, not use the default one. We don't really need to do |
| 84 // this, because RenderObjectToUINodeAdapter does it for us, but |
| 85 // it's good practice in case we happen to not have a |
| 86 // RenderObjectToUINodeAdapter in our tree at startup. |
| 87 UINodeAppView.initUINodeAppView(); |
| 88 UINodeAppView.appView.root = root; |
| 89 |
| 90 addPersistentFrameCallback(rotate); |
| 91 } |
OLD | NEW |