/// <summary> /// Insert an element into this element's contentContainer /// </summary> public void Insert(int index, VisualElement child) { if (child == null) { throw new ArgumentException("Cannot insert null child"); } if (index > childCount) { throw new ArgumentOutOfRangeException("Index out of range: " + index); } if (child == m_Owner) { throw new ArgumentException("Cannot insert element as its own child"); } child.RemoveFromHierarchy(); if (ReferenceEquals(m_Owner.m_Children, s_EmptyList)) { //TODO: Trigger a release on finalizer or something, this means we'll need to make the pool thread-safe as well m_Owner.m_Children = VisualElementListPool.Get(); } if (m_Owner.yogaNode.IsMeasureDefined) { m_Owner.RemoveMeasureFunction(); } PutChildAtIndex(child, index); int imguiContainerCount = child.imguiContainerDescendantCount + (child.isIMGUIContainer ? 1 : 0); if (imguiContainerCount > 0) { m_Owner.ChangeIMGUIContainerCount(imguiContainerCount); } child.hierarchy.SetParent(m_Owner); child.PropagateEnabledToChildren(m_Owner.enabledInHierarchy); child.InvokeHierarchyChanged(HierarchyChangeType.Add); child.IncrementVersion(VersionChangeType.Hierarchy); m_Owner.IncrementVersion(VersionChangeType.Hierarchy); }