Chromium Code Reviews| OLD | NEW |
|---|---|
| (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; | |
|
abarth-chromium
2015/07/08 22:22:01
I think the usual dart convention is to use lower
Chinmay
2015/07/08 23:01:01
ack
| |
| 11 | |
| 12 void main() { | |
| 13 var c1 = new RenderDecoratedBox( | |
| 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 } | |
| OLD | NEW |