diff dynamin/gui/container.d @ 83:3cfc83a99cbc

Add List.opIndexAssign and switch to one callback for change notification. Also, update controls to work with the new API.
author Jordan Miner <jminer7@gmail.com>
date Sun, 18 Jul 2010 22:20:50 -0500
parents 651082a9b364
children 73060bc3f004
line wrap: on
line diff
--- a/dynamin/gui/container.d	Sat Jul 17 16:54:09 2010 -0500
+++ b/dynamin/gui/container.d	Sun Jul 18 22:20:50 2010 -0500
@@ -88,31 +88,33 @@
 	}
 
 	// not an event
-	void whenChildAdded(Control child, int) {
-		if(child.parent)
-			child.parent.remove(child);
-		child.parent = this;
-		repaint();
+	void whenChildrenChanged(ListChangeType, Control oldChild, Control newChild, uint) {
+		if(oldChild) {
+			oldChild.parent = null;
+			repaint();
 
-		void callAdded(Control ctrl) {
-			scope e = new HierarchyEventArgs(ctrl);
-			descendantAdded(e);
+			scope e = new HierarchyEventArgs(oldChild);
+			descendantRemoved(e);
+		}
 
-			if(auto cntr = cast(Container)ctrl) {
-				foreach(c; cntr._children)
-					callAdded(c);
-			}
-		}
-		callAdded(child);
-	}
+		if(newChild) {
+			if(newChild.parent)
+				newChild.parent.remove(newChild);
+			newChild.parent = this;
+			repaint();
 
-	// not an event
-	void whenChildRemoved(Control child, int) {
-		child.parent = null;
-		repaint();
+			void callAdded(Control ctrl) {
+				scope e = new HierarchyEventArgs(ctrl);
+				descendantAdded(e);
 
-		scope e = new HierarchyEventArgs(child);
-		descendantRemoved(e);
+				if(auto cntr = cast(Container)ctrl) {
+					foreach(c; cntr._children)
+						callAdded(c);
+				}
+			}
+			callAdded(newChild);
+		}
+
 	}
 
 	void dispatchDescendantAdded(HierarchyEventArgs e) {
@@ -169,7 +171,7 @@
 		descendantRemoved.setUp(&whenDescendantRemoved,
 		                        &dispatchDescendantRemoved);
 
-		_children = new ControlList(&whenChildAdded, &whenChildRemoved);
+		_children = new ControlList(&whenChildrenChanged);
 
 		elasticX = true;
 		elasticY = true;