public virtual void AddChild(GuiWidget childToAdd, int indexInChildrenList = -1) { #if DEBUG if (childToAdd.hasBeenRemoved) { throw new Exception("You are adding a child that has previously been remove. You should probably be creating a new widget, or calling ClearRemovedFlag() before adding."); } #endif if (indexInChildrenList == -1) { indexInChildrenList = Children.Count; } if (childToAdd == this) { BreakInDebugger("A GuiWidget cannot be a child of itself."); } if (indexInChildrenList > Children.Count) { throw new IndexOutOfRangeException(); } if (Children.Contains(childToAdd)) { throw new Exception("You cannot add the same child twice."); } if (childToAdd.Parent != null) { throw new Exception("This is alread the child of another widget."); } childToAdd.parent = this; childToAdd.widgetHasBeenClosed = false; Children.Insert(indexInChildrenList, childToAdd); OnChildAdded(new GuiWidgetEventArgs(childToAdd)); childToAdd.OnParentChanged(null); childToAdd.InitLayout(); OnLayout(new LayoutEventArgs(this, childToAdd, PropertyCausingLayout.AddChild)); }