/// <summary> /// Ensures that the parent is corret and that the child is not child of another container anymore. /// </summary> /// <param name="child"></param> protected void EnsureParent(IGuiElement child) { if (child.GetParent() != null) { child.GetParent().RemoveChild(child); } child.SetParent(this); }
/// <summary> /// Removes the child. /// </summary> /// <param name="component">The component.</param> /// <param name="destroy">if set to <c>true</c> [destroy].</param> public void RemoveChild(IGuiElement component, bool destroy = false) { if (HasChild(component)) { // NOTICE: RemovedFromStage is dispatch in SetStage() for the component and all its children // @see SetStage() of the this class and of AbstractGuiElement _children.Remove(component); component.SetParent(null); component.SetStage(null); if (destroy) { component.Destroy(); } } }
/// <summary> /// Replace a child with another gui element. /// If 'which' is no child nothing is done. /// </summary> /// <param name="which">which child to remove</param> /// <param name="with">to replace with</param> /// <param name="destroyRemoved">true to destroy the removed child</param> /// <see cref="IGuiElement.Destroy" /> public void ReplaceChild(IGuiElement which, IGuiElement with, bool destroyRemoved = false) { if (HasChild(which)) { var index = _children.IndexOf(which); _children[index] = with; EnsureParent(with); with.SetStage(GetStage()); which.SetParent(null); which.SetStage(null); if (destroyRemoved) { which.Destroy(); } } }