| 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();
|
| + }
|
| +
|
| +}
|
|
|