public void Clear() { 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.yogaNode.SetMeasureFunction(m_Owner.Measure); } foreach (VisualElement e in elements) { e.InvokeHierarchyChanged(HierarchyChangeType.Remove); e.hierarchy.SetParent(null); e.m_LogicalParent = null; m_Owner.elementPanel?.OnVersionChanged(e, VersionChangeType.Hierarchy); } VisualElementListPool.Release(elements); m_Owner.IncrementVersion(VersionChangeType.Hierarchy); } }
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); } }
private void ReleaseChildList() { var children = m_Owner.m_Children; if (children != null) { m_Owner.m_Children = null; VisualElementListPool.Release(children); } }
/// <summary> /// Remove all child elements from this element's contentContainer /// </summary> public void Clear() { 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(); 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); } }
internal static void SendEnterLeave <TLeaveEvent, TEnterEvent>(VisualElement previousTopElementUnderMouse, VisualElement currentTopElementUnderMouse, IMouseEvent triggerEvent, Vector2 mousePosition) where TLeaveEvent : MouseEventBase <TLeaveEvent>, new() where TEnterEvent : MouseEventBase <TEnterEvent>, new() { if (previousTopElementUnderMouse != null && previousTopElementUnderMouse.panel == null) { // If previousTopElementUnderMouse has been removed from panel, // do as if there is no element under the mouse. previousTopElementUnderMouse = null; } // We want to find the common ancestor CA of previousTopElementUnderMouse and currentTopElementUnderMouse, // send Leave (MouseLeave or DragLeave) events to elements between CA and previousTopElementUnderMouse // and send Enter (MouseEnter or DragEnter) events to elements between CA and currentTopElementUnderMouse. int prevDepth = 0; var p = previousTopElementUnderMouse; while (p != null) { prevDepth++; p = p.hierarchy.parent; } int currDepth = 0; var c = currentTopElementUnderMouse; while (c != null) { currDepth++; c = c.hierarchy.parent; } p = previousTopElementUnderMouse; c = currentTopElementUnderMouse; while (prevDepth > currDepth) { using (var leaveEvent = MouseEventBase <TLeaveEvent> .GetPooled(triggerEvent, mousePosition, false)) { leaveEvent.target = p; p.SendEvent(leaveEvent); } prevDepth--; p = p.hierarchy.parent; } // We want to send enter events after all the leave events. // We will store the elements being entered in this list. List <VisualElement> enteringElements = VisualElementListPool.Get(currDepth); while (currDepth > prevDepth) { enteringElements.Add(c); currDepth--; c = c.hierarchy.parent; } // Now p and c are at the same depth. Go up the tree until p == c. while (p != c) { using (var leaveEvent = MouseEventBase <TLeaveEvent> .GetPooled(triggerEvent, mousePosition, false)) { leaveEvent.target = p; p.SendEvent(leaveEvent); } enteringElements.Add(c); p = p.hierarchy.parent; c = c.hierarchy.parent; } for (var i = enteringElements.Count - 1; i >= 0; i--) { using (var enterEvent = MouseEventBase <TEnterEvent> .GetPooled(triggerEvent, mousePosition, false)) { enterEvent.target = enteringElements[i]; enteringElements[i].SendEvent(enterEvent); } } VisualElementListPool.Release(enteringElements); }
internal static void SendEnterLeave <TLeaveEvent, TEnterEvent>(VisualElement previousTopElementUnderMouse, VisualElement currentTopElementUnderMouse, IMouseEvent triggerEvent, Vector2 mousePosition) where TLeaveEvent : MouseEventBase <TLeaveEvent>, new() where TEnterEvent : MouseEventBase <TEnterEvent>, new() { bool flag = previousTopElementUnderMouse != null && previousTopElementUnderMouse.panel == null; if (flag) { previousTopElementUnderMouse = null; } int i = 0; VisualElement visualElement; for (visualElement = previousTopElementUnderMouse; visualElement != null; visualElement = visualElement.hierarchy.parent) { i++; } int j = 0; VisualElement visualElement2; for (visualElement2 = currentTopElementUnderMouse; visualElement2 != null; visualElement2 = visualElement2.hierarchy.parent) { j++; } visualElement = previousTopElementUnderMouse; visualElement2 = currentTopElementUnderMouse; while (i > j) { using (TLeaveEvent pooled = MouseEventBase <TLeaveEvent> .GetPooled(triggerEvent, mousePosition, false)) { pooled.target = visualElement; visualElement.SendEvent(pooled); } i--; visualElement = visualElement.hierarchy.parent; } List <VisualElement> list = VisualElementListPool.Get(j); while (j > i) { list.Add(visualElement2); j--; visualElement2 = visualElement2.hierarchy.parent; } while (visualElement != visualElement2) { using (TLeaveEvent pooled2 = MouseEventBase <TLeaveEvent> .GetPooled(triggerEvent, mousePosition, false)) { pooled2.target = visualElement; visualElement.SendEvent(pooled2); } list.Add(visualElement2); visualElement = visualElement.hierarchy.parent; visualElement2 = visualElement2.hierarchy.parent; } for (int k = list.Count - 1; k >= 0; k--) { using (TEnterEvent pooled3 = MouseEventBase <TEnterEvent> .GetPooled(triggerEvent, mousePosition, false)) { pooled3.target = list[k]; list[k].SendEvent(pooled3); } } VisualElementListPool.Release(list); }
/// <undoc/> public void Dispose() { VisualElementListPool.Release(iterationList); iterationList = null; }