Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Unified Diff: sky/examples/widgets/spinning_mixed.dart

Issue 1183503003: Add an example of an app that manipulates both a RenderObject tree and has some fn logic in it. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/examples/widgets/container.dart ('k') | sky/sdk/lib/framework/rendering/box.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/widgets/spinning_mixed.dart
diff --git a/sky/examples/widgets/spinning_mixed.dart b/sky/examples/widgets/spinning_mixed.dart
new file mode 100644
index 0000000000000000000000000000000000000000..407fbde30e9cf1895c8b789f3eaa46ebcf217aec
--- /dev/null
+++ b/sky/examples/widgets/spinning_mixed.dart
@@ -0,0 +1,91 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:sky' as sky;
+
+import 'package:sky/framework/rendering/box.dart';
+import 'package:sky/framework/rendering/flex.dart';
+import 'package:sky/framework/scheduler.dart';
+import 'package:sky/framework/widgets/ui_node.dart';
+import 'package:sky/framework/widgets/wrappers.dart';
+import 'package:vector_math/vector_math.dart';
+
+import '../lib/solid_color_box.dart';
+
+// Solid colour, RenderObject version
+void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, { int flex: 0 }) {
+ RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor);
+ parent.add(child);
+ child.parentData.flex = flex;
+}
+
+// Solid colour, Widget version
+class Rectangle extends Component {
+ Rectangle(this.color, { Object key }) : super(key: key);
+ final Color color;
+ UINode build() {
+ return new FlexExpandingChild(
+ new Container(
+ decoration: new BoxDecoration(backgroundColor: color)
+ )
+ );
+ }
+}
+
+UINode builder() {
+ return new Flex([
+ new Rectangle(const Color(0xFF00FFFF), key: 'a'),
+ new Container(
+ padding: new EdgeDims.all(10.0),
+ margin: new EdgeDims.all(10.0),
+ decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)),
+ child: new Image(src: "https://www.dartlang.org/logos/dart-logo.png",
+ size: new Size(300.0, 300.0),
+ key: 1
+ )
+ ),
+ new Rectangle(const Color(0xFFFFFF00), key: 'b'),
+ ],
+ direction: FlexDirection.vertical,
+ justifyContent: FlexJustifyContent.spaceBetween
+ );
+}
+
+double timeBase;
+RenderTransform transformBox;
+
+void rotate(double timeStamp) {
+ if (timeBase == null)
+ timeBase = timeStamp;
+ double delta = (timeStamp - timeBase) / 1000; // radians
+
+ transformBox.setIdentity();
+ transformBox.translate(transformBox.size.width / 2.0, transformBox.size.height / 2.0);
+ transformBox.rotateZ(delta);
+ transformBox.translate(-transformBox.size.width / 2.0, -transformBox.size.height / 2.0);
+}
+
+void main() {
+ RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical);
+
+ RenderProxyBox proxy = new RenderProxyBox();
+ new RenderObjectToUINodeAdapter(proxy, builder); // adds itself to proxy
+
+ addFlexChildSolidColor(flexRoot, const sky.Color(0xFFFF00FF), flex: 1);
+ flexRoot.add(proxy);
+ addFlexChildSolidColor(flexRoot, const sky.Color(0xFF0000FF), flex: 1);
+
+ transformBox = new RenderTransform(child: flexRoot, transform: new Matrix4.identity());
+ RenderPadding root = new RenderPadding(padding: new EdgeDims.all(20.0), child: transformBox);
+
+ // Because we're going to use UINodes, we want to initialise its
+ // AppView, not use the default one. We don't really need to do
+ // this, because RenderObjectToUINodeAdapter does it for us, but
+ // it's good practice in case we happen to not have a
+ // RenderObjectToUINodeAdapter in our tree at startup.
+ UINodeAppView.initUINodeAppView();
+ UINodeAppView.appView.root = root;
+
+ addPersistentFrameCallback(rotate);
+}
« no previous file with comments | « sky/examples/widgets/container.dart ('k') | sky/sdk/lib/framework/rendering/box.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698