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

Side by Side Diff: sky/tests/raw/render_flex.dart

Issue 1146123003: Move simple_render_tree into tests as render_flex (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: now with expected.txt 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/sdk/lib/framework/layout2.dart ('k') | sky/tests/raw/render_flex-expected.txt » ('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 '../resources/third_party/unittest/unittest.dart';
6 import '../resources/unit.dart';
7 import 'dart:sky' as sky;
8 import 'package:sky/framework/app.dart';
9 import 'package:sky/framework/layout2.dart';
10
11 class RenderSolidColor extends RenderDecoratedBox {
12 final sky.Size desiredSize;
13 final int backgroundColor;
14
15 RenderSolidColor(int backgroundColor, { this.desiredSize: const sky.Size.infin ite() })
16 : backgroundColor = backgroundColor,
17 super(new BoxDecoration(backgroundColor: backgroundColor)) {
18 }
19
20 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) {
21 return new BoxDimensions.withConstraints(constraints,
22 width: desiredSize.width,
23 height: desiredSize.height);
24 }
25
26 void performLayout() {
27 size = constraints.constrain(desiredSize);
28 }
29
30 void handlePointer(sky.PointerEvent event) {
31 if (event.type == 'pointerdown')
32 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000);
33 else if (event.type == 'pointerup')
34 decoration = new BoxDecoration(backgroundColor: backgroundColor);
35 }
36 }
37
38 AppView app;
39
40 void main() {
41 initUnit();
42
43 test("should flex", () {
44 var root = new RenderFlex(
45 direction: FlexDirection.Vertical,
46 decoration: new BoxDecoration(backgroundColor: 0xFF000000));
47
48 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) {
49 RenderNode child = new RenderSolidColor(backgroundColor);
50 parent.add(child);
51 child.parentData.flex = flex;
52 }
53
54 // Yellow bar at top
55 addFlexChild(root, 0xFFFFFF00, flex: 1);
56
57 // Turquoise box
58 root.add(new RenderSolidColor(0x7700FFFF, desiredSize: new sky.Size(100.0, 1 00.0)));
59
60 // Green and cyan render block with padding
61 var renderBlock = new RenderBlock(decoration: new BoxDecoration(backgroundCo lor: 0xFFFFFFFF));
62
63 renderBlock.add(new RenderSolidColor(0xFF00FF00, desiredSize: new sky.Size(1 00.0, 50.0)));
64 renderBlock.add(new RenderSolidColor(0x7700FFFF, desiredSize: new sky.Size(5 0.0, 100.0)));
65
66 root.add(new RenderPadding(const EdgeDims(10.0, 10.0, 10.0, 10.0), renderBlo ck));
67
68 var row = new RenderFlex(
69 direction: FlexDirection.Horizontal,
70 decoration: new BoxDecoration(backgroundColor: 0xFF333333));
71
72 // Purple and blue cells
73 addFlexChild(row, 0x77FF00FF, flex: 1);
74 addFlexChild(row, 0xFF0000FF, flex: 2);
75
76 root.add(row);
77 row.parentData.flex = 3;
78
79 app = new AppView(root);
80
81 expect(root.size.width, equals(sky.view.width));
82 expect(root.size.height, equals(sky.view.height));
83 expect(renderBlock.size.width, equals(sky.view.width - 20.0));
84 });
85 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/layout2.dart ('k') | sky/tests/raw/render_flex-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698