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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: sky/sdk/example/rendering/simple_autolayout.dart
diff --git a/sky/sdk/example/rendering/simple_autolayout.dart b/sky/sdk/example/rendering/simple_autolayout.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4fe2526e4b5f5979c716b3cda0496738e59c6357
--- /dev/null
+++ b/sky/sdk/example/rendering/simple_autolayout.dart
@@ -0,0 +1,65 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:sky';
+import 'package:sky/rendering/box.dart';
+import 'package:sky/rendering/object.dart';
+import 'package:sky/rendering/sky_binding.dart';
+import 'package:sky/rendering/auto_layout.dart';
+import 'package:cassowary/cassowary.dart' as al;
+
+void main() {
+ var c1 = new RenderDecoratedBox(
Hixie 2015/07/09 00:53:14 don't use 'var'
Chinmay 2015/07/09 21:44:19 ack
+ decoration: new BoxDecoration(backgroundColor: const Color(0xFFFF0000))
+ );
+
+ var c2 = new RenderDecoratedBox(
+ decoration: new BoxDecoration(backgroundColor: const Color(0xFF00FF00))
+ );
+
+ var c3 = new RenderDecoratedBox(
+ decoration: new BoxDecoration(backgroundColor: const Color(0xFF0000FF))
+ );
+
+ var c4 = new RenderDecoratedBox(
+ decoration: new BoxDecoration(backgroundColor: const Color(0xFFFFFFFF))
+ );
+
+ var root = new RenderAutoLayout(children: [c1, c2, c3, c4]);
+
+ AutoLayoutParentData p1 = c1.parentData;
+ AutoLayoutParentData p2 = c2.parentData;
+ AutoLayoutParentData p3 = c3.parentData;
+ AutoLayoutParentData p4 = c4.parentData;
+
+ root.addConstraints(<al.Constraint>[
+ // Sum of widths of each box must be equal to that of the container
+ (p1.width + p2.width + p3.width == root.width) as al.Constraint,
+
+ // The boxes must be stacked left to right
+ p1.rightEdge <= p2.leftEdge,
+ p2.rightEdge <= p3.leftEdge,
+
+ // The widths of the first and the third boxes should be equal
+ (p1.width == p3.width) as al.Constraint,
+
+ // The width of the second box should be twice as much as that of the first
+ // and third
+ (p2.width * al.CM(2.0) == p1.width) as al.Constraint,
+
+ // The height of the three boxes should be equal to that of the container
+ (p1.height == p2.height) as al.Constraint,
+ (p2.height == p3.height) as al.Constraint,
+ (p3.height == root.height) as al.Constraint,
+
+ // The fourth box should be half as wide as the second and must be attached
+ // to the right edge of the same (by its center)
+ (p4.width == p2.width / al.CM(2.0)) as al.Constraint,
+ (p4.height == al.CM(50.0)) as al.Constraint,
+ (p4.horizontalCenter == p2.rightEdge) as al.Constraint,
+ (p4.verticalCenter == p2.height / al.CM(2.0)) as al.Constraint,
+ ]);
+
+ new SkyBinding(root: root);
+}

Powered by Google App Engine
This is Rietveld 408576698