Example #1
0
		public virtual void RemoveChild(GuiWidget childToRemove)
		{
			if (!Children.Contains(childToRemove))
			{
				throw new InvalidOperationException("You can only remove children that this control has.");
			}
			childToRemove.ClearCapturedState();
			childToRemove.hasBeenRemoved = true;
			Children.Remove(childToRemove);
			childToRemove.parent = null;
			childToRemove.OnParentChanged(null);
			OnChildRemoved(new GuiWidgetEventArgs(childToRemove));
			OnLayout(new LayoutEventArgs(this, null, PropertyCausingLayout.RemoveChild));
			Invalidate();
		}
Example #2
0
		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));
		}