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

Side by Side Diff: sky/examples/widgets/spinning_mixed.dart

Issue 1218593002: Move sky/examples to sky/sdk/lib/example, and code changes to support that change. Fixes T277. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 unified diff | Download patch
OLDNEW
(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/base/scheduler.dart';
8 import 'package:sky/rendering/box.dart';
9 import 'package:sky/rendering/flex.dart';
10 import 'package:sky/rendering/sky_binding.dart';
11 import 'package:sky/widgets/basic.dart';
12 import 'package:sky/widgets/raised_button.dart';
13 import 'package:sky/widgets/widget.dart';
14 import 'package:vector_math/vector_math.dart';
15
16 import '../lib/solid_color_box.dart';
17 import '../../tests/resources/display_list.dart';
18
19 // Solid colour, RenderObject version
20 void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, { int flex: 0 }) {
21 RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor);
22 parent.add(child);
23 child.parentData.flex = flex;
24 }
25
26 // Solid colour, Widget version
27 class Rectangle extends Component {
28 Rectangle(this.color, { String key }) : super(key: key);
29 final Color color;
30 Widget build() {
31 return new Flexible(
32 child: new Container(
33 decoration: new BoxDecoration(backgroundColor: color)
34 )
35 );
36 }
37 }
38
39 Widget builder() {
40 return new Flex([
41 new Rectangle(const Color(0xFF00FFFF)),
42 new Container(
43 padding: new EdgeDims.all(10.0),
44 margin: new EdgeDims.all(10.0),
45 decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)),
46 child: new RaisedButton(
47 child: new Flex([
48 new Image(src: "https://www.dartlang.org/logos/dart-logo.png"),
49 new Text('PRESS ME'),
50 ]),
51 onPressed: () => print("Hello World")
52 )
53 ),
54 new Rectangle(const Color(0xFFFFFF00)),
55 ],
56 direction: FlexDirection.vertical,
57 justifyContent: FlexJustifyContent.spaceBetween
58 );
59 }
60
61 double timeBase;
62 RenderTransform transformBox;
63
64 final TestRenderView tester = new TestRenderView();
65
66 void rotate(double timeStamp) {
67 if (timeBase == null)
68 timeBase = timeStamp;
69 double delta = (timeStamp - timeBase) / 1000; // radians
70
71 transformBox.setIdentity();
72 transformBox.translate(transformBox.size.width / 2.0, transformBox.size.height / 2.0);
73 transformBox.rotateZ(delta);
74 transformBox.translate(-transformBox.size.width / 2.0, -transformBox.size.heig ht / 2.0);
75 }
76
77 void main() {
78 // Because we're going to use Widgets, we want to initialise its
79 // SkyBinding, not use the default one. We don't really need to do
80 // this, because RenderBoxToWidgetAdapter does it for us, but
81 // it's good practice in case we happen to not have a
82 // RenderBoxToWidgetAdapter in our tree at startup, or in case we
83 // want a renderViewOverride.
84 WidgetSkyBinding.initWidgetSkyBinding();
85
86 RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical);
87
88 RenderProxyBox proxy = new RenderProxyBox();
89 new RenderBoxToWidgetAdapter(proxy, builder); // adds itself to proxy
90
91 addFlexChildSolidColor(flexRoot, const sky.Color(0xFFFF00FF), flex: 1);
92 flexRoot.add(proxy);
93 addFlexChildSolidColor(flexRoot, const sky.Color(0xFF0000FF), flex: 1);
94
95 transformBox = new RenderTransform(child: flexRoot, transform: new Matrix4.ide ntity());
96 RenderPadding root = new RenderPadding(padding: new EdgeDims.all(20.0), child: transformBox);
97
98 SkyBinding.instance.root = root;
99 addPersistentFrameCallback(rotate);
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698