/// <summary> /// Function called after this Component is added to a parent Component. /// </summary> /// <param name="parent"></param> public virtual void OnAdd(Component parent) { this.Parent = parent; this.OnAncestryChanged(); }
/// <summary> /// Call this function to insert a child component to this component before a specific component. /// This function calls the OnAdd of the child, the OnAncestryChanged of the child and all its /// children, and the OnComponentAdded of this component. /// </summary> /// <param name="other">A existing child of the component, the new child is added before this component</param> /// <param name="child"></param> public void InsertBeforeComponent(Component other, Component child) { this.components.Insert(this.components.IndexOf(other), child); this.OnComponentAdded(child); }
/// <summary> /// Call this function to remove a component a child from this component. This function calls /// the OnRemove of the child and the OnComponentRemoved of this component. /// </summary> /// <param name="child"></param> public void RemoveComponent(Component child) { this.components.Remove(child); child.OnRemove(); this.OnComponentRemoved(child); }
/// <summary> /// Call this function to insert a child component to this component at a specific location. /// This function calls the OnAdd of the child, the OnAncestryChanged of the child and all its /// children, and the OnComponentAdded of this component. /// </summary> /// <param name="index">Zero based index, when the index is 0 the child is inserted as the first of this components children</param> /// <param name="child"></param> public void InsertComponent(int index, Component child) { this.components.Insert(index, child); this.OnComponentAdded(child); }
/// <summary> /// Call this function to add a child component to this component. This function /// calls the OnAdd of the child, the OnAncestryChanged of the child and all its /// children, and the OnComponentAdded of this component. /// </summary> /// <param name="child"></param> public virtual void AddComponent(Component child) { this.components.Add(child); this.OnComponentAdded(child); }
/// <summary> /// Function called when a child is removed from this component. /// </summary> /// <param name="child"></param> protected virtual void OnComponentRemoved(Component child) { }
/// <summary> /// Function called when a child component is added to this component /// </summary> /// <param name="child"></param> protected virtual void OnComponentAdded(Component child) { child.OnAdd(this); }
/// <summary> /// Function called when this Component is removed from its parent. /// </summary> public virtual void OnRemove() { this.Parent = null; this.OnAncestryChanged(); }