示例#1
0
        /// <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();
                }
            }
        }
示例#2
0
        /// <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();
                }
            }
        }