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

Unified Diff: sky/framework/node.dart

Issue 1093633002: Layout API prototype, for discussion (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: remove some casting for clarity Created 5 years, 8 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
« sky/framework/layout.dart ('K') | « sky/framework/layout.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/node.dart
diff --git a/sky/framework/node.dart b/sky/framework/node.dart
new file mode 100644
index 0000000000000000000000000000000000000000..030ad4dff5de6e79ff0475ff2a1b8dff01db29bd
--- /dev/null
+++ b/sky/framework/node.dart
@@ -0,0 +1,52 @@
+library node;
+
+class Node {
+
+ // nodes always have an order greater than their ancestors'.
+ // there's no guarantee regarding order between siblings
+
+ int _order = 0;
+ int get order => _order;
+ void reorderChild(Node child) { // internal, do not call
+ assert(child._attached == _attached);
+ if (child._order <= _order) {
+ child._order = _order + 1;
+ child.reorderChildren();
+ }
+ }
+ void reorderChildren() { // internal, do not call
+ // override this in subclasses with child nodes
+ // simply call reorderChild(child) for each child
+ }
+
+ bool _attached = false;
+ bool get attached => _attached;
+ void attach() {
+ // override this in subclasses with child nodes
+ // simply call attach() for each child then call your superclass
+ _attached = true;
+ attachChildren();
+ }
+ attachChildren() { } // workaround for lack of inter-class mixins in Dart
+ void detach() {
+ // override this in subclasses with child nodes
+ // simply call detach() for each child then call your superclass
+ _attached = false;
+ detachChildren();
+ }
+ detachChildren() { } // workaround for lack of inter-class mixins in Dart
+
+ void setAsChild(Node child) { // only for use by subclasses
+ assert(child != null);
+ if (attached)
+ child.attach();
+ reorderChild(child);
+ }
+ void dropChild(Node child) { // only for use by subclasses
+ assert(child != null);
+ assert(child.attached == attached);
+ if (attached)
+ child.detach();
+ }
+
+}
« sky/framework/layout.dart ('K') | « sky/framework/layout.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698