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

Side by Side Diff: sky/sdk/example/rendering/simple_autolayout.dart

Issue 1230583003: Integrate the linear constraint solver into Sky as a RenderBox subclass. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Address CL concerns 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';
6 import 'package:sky/rendering/box.dart';
7 import 'package:sky/rendering/object.dart';
8 import 'package:sky/rendering/sky_binding.dart';
9 import 'package:sky/rendering/auto_layout.dart';
10 import 'package:cassowary/cassowary.dart' as al;
11
12 void main() {
13 var c1 = new RenderDecoratedBox(
Hixie 2015/07/09 00:53:14 don't use 'var'
Chinmay 2015/07/09 21:44:19 ack
14 decoration: new BoxDecoration(backgroundColor: const Color(0xFFFF0000))
15 );
16
17 var c2 = new RenderDecoratedBox(
18 decoration: new BoxDecoration(backgroundColor: const Color(0xFF00FF00))
19 );
20
21 var c3 = new RenderDecoratedBox(
22 decoration: new BoxDecoration(backgroundColor: const Color(0xFF0000FF))
23 );
24
25 var c4 = new RenderDecoratedBox(
26 decoration: new BoxDecoration(backgroundColor: const Color(0xFFFFFFFF))
27 );
28
29 var root = new RenderAutoLayout(children: [c1, c2, c3, c4]);
30
31 AutoLayoutParentData p1 = c1.parentData;
32 AutoLayoutParentData p2 = c2.parentData;
33 AutoLayoutParentData p3 = c3.parentData;
34 AutoLayoutParentData p4 = c4.parentData;
35
36 root.addConstraints(<al.Constraint>[
37 // Sum of widths of each box must be equal to that of the container
38 (p1.width + p2.width + p3.width == root.width) as al.Constraint,
39
40 // The boxes must be stacked left to right
41 p1.rightEdge <= p2.leftEdge,
42 p2.rightEdge <= p3.leftEdge,
43
44 // The widths of the first and the third boxes should be equal
45 (p1.width == p3.width) as al.Constraint,
46
47 // The width of the second box should be twice as much as that of the first
48 // and third
49 (p2.width * al.CM(2.0) == p1.width) as al.Constraint,
50
51 // The height of the three boxes should be equal to that of the container
52 (p1.height == p2.height) as al.Constraint,
53 (p2.height == p3.height) as al.Constraint,
54 (p3.height == root.height) as al.Constraint,
55
56 // The fourth box should be half as wide as the second and must be attached
57 // to the right edge of the same (by its center)
58 (p4.width == p2.width / al.CM(2.0)) as al.Constraint,
59 (p4.height == al.CM(50.0)) as al.Constraint,
60 (p4.horizontalCenter == p2.rightEdge) as al.Constraint,
61 (p4.verticalCenter == p2.height / al.CM(2.0)) as al.Constraint,
62 ]);
63
64 new SkyBinding(root: root);
65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698