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

Side by Side Diff: sky/examples/raw/simple_render_tree.dart

Issue 1161003002: Split layout2.dart into several files (Closed) Base URL: git@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 unified diff | Download patch
« no previous file with comments | « sky/examples/raw/sector_layout.dart ('k') | sky/examples/raw/touch_demo.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'package:sky/framework/app.dart';
7 import 'package:sky/framework/layout2.dart';
8
9 class RenderSolidColor extends RenderDecoratedBox {
10 final sky.Size desiredSize;
11 final int backgroundColor;
12
13 RenderSolidColor(int backgroundColor, { this.desiredSize: const sky.Size.infin ite() })
14 : backgroundColor = backgroundColor,
15 super(decoration: new BoxDecoration(backgroundColor: backgroundColor)) {
16 }
17
18 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) {
19 return new BoxDimensions.withConstraints(constraints,
20 width: desiredSize.width,
21 height: desiredSize.height);
22 }
23
24 void performLayout() {
25 size = constraints.constrain(desiredSize);
26 }
27
28 void handlePointer(sky.PointerEvent event) {
29 if (event.type == 'pointerdown')
30 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000);
31 else if (event.type == 'pointerup')
32 decoration = new BoxDecoration(backgroundColor: backgroundColor);
33 }
34 }
35
36 AppView app;
37
38 void main() {
39 RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.Vertical);
40
41 RenderNode root = new RenderDecoratedBox(
42 decoration: new BoxDecoration(backgroundColor: 0xFF000000),
43 child: flexRoot
44 );
45
46 void addFlexChildSolidColor(RenderFlex parent, int backgroundColor, { int flex : 0 }) {
47 RenderNode child = new RenderSolidColor(backgroundColor);
48 parent.add(child);
49 child.parentData.flex = flex;
50 }
51
52 // Yellow bar at top
53 addFlexChildSolidColor(flexRoot, 0xFFFFFF00, flex: 1);
54
55 // Turquoise box
56 flexRoot.add(new RenderSolidColor(0x7700FFFF, desiredSize: new sky.Size(100.0, 100.0)));
57
58 // Green and cyan render block with padding
59 var renderBlock = new RenderBlock();
60
61 renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredSize: new sky.Size(100 .0, 50.0)));
62 renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredSize: new sky.Size(50. 0, 100.0)));
63
64 var renderDecoratedBlock = new RenderDecoratedBox(
65 decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF),
66 child: renderBlock
67 );
68
69 flexRoot.add(new RenderPadding(const EdgeDims(10.0, 10.0, 10.0, 10.0), renderD ecoratedBlock));
70
71 var row = new RenderFlex(direction: FlexDirection.Horizontal);
72
73 // Purple and blue cells
74 addFlexChildSolidColor(row, 0x77FF00FF, flex: 1);
75 addFlexChildSolidColor(row, 0xFF0000FF, flex: 2);
76
77 var decoratedRow = new RenderDecoratedBox(
78 decoration: new BoxDecoration(backgroundColor: 0xFF333333),
79 child: row
80 );
81
82 flexRoot.add(decoratedRow);
83 decoratedRow.parentData.flex = 3;
84
85 app = new AppView(root);
86
87 }
OLDNEW
« no previous file with comments | « sky/examples/raw/sector_layout.dart ('k') | sky/examples/raw/touch_demo.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698