Esempio n. 1
0
 private void ReleaseChildList()
 {
     if (!ReferenceEquals(m_Owner.m_Children, s_EmptyList))
     {
         var children = m_Owner.m_Children;
         m_Owner.m_Children = s_EmptyList;
         VisualElementListPool.Release(children);
     }
 }
Esempio n. 2
0
            /// <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");
                }

                if (m_Owner.elementPanel != null && m_Owner.elementPanel.duringLayoutPhase)
                {
                    throw new InvalidOperationException(k_InvalidHierarchyChangeMsg);
                }

                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);
            }
Esempio n. 3
0
        public List <VisualElement> GetAffectedVisualElements()
        {
            List <VisualElement> elements = VisualElementListPool.Get();

            for (int i = 0; i < shadow.childCount; ++i)
            {
                VisualElement element = shadow[i];
                if (element.style.positionType == PositionType.Relative)
                {
                    elements.Add(element);
                }
            }

            return(elements);
        }
Esempio n. 4
0
        public List <VisualElement> GetAffectedVisualElements()
        {
            List <VisualElement> elements = VisualElementListPool.Get();

            for (int i = 0; i < hierarchy.childCount; ++i)
            {
                VisualElement element = hierarchy[i];
                if (element.resolvedStyle.position == Position.Relative)
                {
                    elements.Add(element);
                }
            }

            return(elements);
        }
Esempio n. 5
0
            /// <summary>
            /// Remove all child elements from this element's contentContainer
            /// </summary>
            public void Clear()
            {
                if (m_Owner.elementPanel != null && m_Owner.elementPanel.duringLayoutPhase)
                {
                    throw new InvalidOperationException(k_InvalidHierarchyChangeMsg);
                }

                if (childCount > 0)
                {
                    // Copy children to a temporary list because removing child elements from
                    // the panel may trigger modifications (DetachFromPanelEvent callback)
                    // of the same list while we are in the foreach loop.
                    var elements = VisualElementListPool.Copy(m_Owner.m_Children);

                    ReleaseChildList();
                    m_Owner.yogaNode.Clear();

                    if (m_Owner.requireMeasureFunction)
                    {
                        m_Owner.AssignMeasureFunction();
                    }

                    foreach (VisualElement e in elements)
                    {
                        e.InvokeHierarchyChanged(HierarchyChangeType.Remove);
                        e.hierarchy.SetParent(null);
                        e.m_LogicalParent = null;
                        m_Owner.elementPanel?.OnVersionChanged(e, VersionChangeType.Hierarchy);
                    }

                    if (m_Owner.imguiContainerDescendantCount > 0)
                    {
                        int totalChange = m_Owner.imguiContainerDescendantCount;

                        if (m_Owner.isIMGUIContainer)
                        {
                            totalChange--;
                        }

                        m_Owner.ChangeIMGUIContainerCount(-totalChange);
                    }
                    VisualElementListPool.Release(elements);

                    m_Owner.IncrementVersion(VersionChangeType.Hierarchy);
                }
            }
Esempio n. 6
0
            protected void OnMouseDown(MouseDownEvent e)
            {
                if (CanStartManipulation(e))
                {
                    VisualSplitter visualSplitter = target as VisualSplitter;
                    FlexDirection  flexDirection  = visualSplitter.resolvedStyle.flexDirection;

                    if (m_AffectedElements != null)
                    {
                        VisualElementListPool.Release(m_AffectedElements);
                    }
                    m_AffectedElements = visualSplitter.GetAffectedVisualElements();

                    var shouldUseEvent = false;
                    for (int i = 0; i < m_AffectedElements.Count - 1; ++i)
                    {
                        VisualElement visualElement = m_AffectedElements[i];

                        Rect splitterRect = visualSplitter.GetSplitterRect(visualElement);

                        if (splitterRect.Contains(e.localMousePosition))
                        {
                            bool isReverse = flexDirection == FlexDirection.RowReverse || flexDirection == FlexDirection.ColumnReverse;

                            if (isReverse)
                            {
                                m_ActiveVisualElementIndex = i + 1;
                                m_NextVisualElementIndex   = i;
                            }
                            else
                            {
                                m_ActiveVisualElementIndex = i;
                                m_NextVisualElementIndex   = i + 1;
                            }
                            shouldUseEvent = true;
                        }
                    }
                    if (shouldUseEvent)
                    {
                        m_Active = true;
                        target.CaptureMouse();
                        e.StopPropagation();
                        e.PreventDefault();
                    }
                }
            }