Browse Source

fix parentContainer propagation

ncannasse 8 years ago
parent
commit
a82e6d7133
2 changed files with 13 additions and 2 deletions
  1. 6 1
      h2d/Flow.hx
  2. 7 1
      h2d/Sprite.hx

+ 6 - 1
h2d/Flow.hx

@@ -344,6 +344,11 @@ class Flow extends Sprite {
 			super.getBoundsRec(relativeTo, out, forSize);
 	}
 
+	override function setParentContainer(c) {
+		parentContainer = c;
+		// break propogation
+	}
+
 	override function addChildAt( s, pos ) {
 		if( background != null ) pos++;
 		var fp = getProperties(s);
@@ -351,7 +356,7 @@ class Flow extends Sprite {
 		if( fp == null ) fp = new FlowProperties(s) else properties.remove(fp);
 		properties.insert(pos, fp);
 		needReflow = true;
-		s.parentContainer = this;
+		s.setParentContainer(this);
 	}
 
 	override public function removeChild(s:Sprite) {

+ 7 - 1
h2d/Sprite.hx

@@ -284,12 +284,18 @@ class Sprite {
 		if( childs.remove(s) ) {
 			if( s.allocated ) s.onDelete();
 			s.parent = null;
-			s.parentContainer = null;
+			if( s.parentContainer != null ) s.setParentContainer(null);
 			s.posChanged = true;
 			onContentChanged();
 		}
 	}
 
+	function setParentContainer( c : Sprite ) {
+		parentContainer = c;
+		for( s in childs )
+			s.setParentContainer(c);
+	}
+
 	public function removeChildren() {
 		while( numChildren>0 )
 			removeChild( getChildAt(0) );