public void Insert(int index, VisualElement child)
            {
                if (child == null)
                {
                    throw new ArgumentException("Cannot insert null child");
                }

                if (index > childCount)
                {
                    throw new IndexOutOfRangeException("Index out of range: " + index);
                }

                if (child == m_Owner)
                {
                    throw new ArgumentException("Cannot insert element as its own child");
                }

                child.RemoveFromHierarchy();

                child.shadow.SetParent(m_Owner);
                if (m_Owner.m_Children == null)
                {
                    //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.yogaNode.SetMeasureFunction(null);
                }

                PutChildAtIndex(child, index);

                child.SetEnabledFromHierarchy(m_Owner.enabledInHierarchy);

                // child styles are dependent on topology
                child.Dirty(ChangeType.Styles);
                child.Dirty(ChangeType.Transform);
                m_Owner.Dirty(ChangeType.Layout);

                // persistent data key may have changed or needs initialization
                if (!string.IsNullOrEmpty(child.persistenceKey))
                {
                    child.Dirty(ChangeType.PersistentData);
                }
            }
예제 #2
0
            public void Insert(int index, VisualElement child)
            {
                if (child == null)
                {
                    throw new ArgumentException("Cannot insert null child");
                }

                if (index > childCount)
                {
                    throw new IndexOutOfRangeException("Index out of range: " + index);
                }

                if (child == m_Owner)
                {
                    throw new ArgumentException("Cannot insert element as its own child");
                }

                child.RemoveFromHierarchy();

                child.shadow.SetParent(m_Owner);
                if (m_Owner.m_Children == null)
                {
                    //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.yogaNode.SetMeasureFunction(null);
                }

                PutChildAtIndex(child, index);

                child.SetEnabledFromHierarchy(m_Owner.enabledInHierarchy);

                child.IncrementVersion(VersionChangeType.Hierarchy);
                m_Owner.IncrementVersion(VersionChangeType.Hierarchy);
            }