Пример #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);
     }
 }
Пример #2
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);
                }
            }
Пример #3
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();
                    }
                }
            }