internal void SetPanel(BaseVisualElementPanel p) { if (panel == p) { return; } //We now gather all Elements in order to dispatch events in an efficient manner List <VisualElement> elements = VisualElementListPool.Get(); try { elements.Add(this); GatherAllChildren(elements); foreach (var e in elements) { e.ChangePanel(p); } } finally { VisualElementListPool.Release(elements); } }
private void ReleaseChildList() { var children = m_Owner.m_Children; if (children != null) { m_Owner.m_Children = null; VisualElementListPool.Release(children); } }
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); } }
internal void SetPanel(BaseVisualElementPanel p) { if (panel == p) { return; } //We now gather all Elements in order to dispatch events in an efficient manner List <VisualElement> elements = VisualElementListPool.Get(); try { elements.Add(this); GatherAllChildren(elements); EventDispatcher.Gate?pDispatcherGate = null; if (p?.dispatcher != null) { pDispatcherGate = new EventDispatcher.Gate(p.dispatcher); } EventDispatcher.Gate?panelDispatcherGate = null; if (panel?.dispatcher != null && panel.dispatcher != p?.dispatcher) { panelDispatcherGate = new EventDispatcher.Gate(panel.dispatcher); } using (pDispatcherGate) using (panelDispatcherGate) { foreach (var e in elements) { e.ChangePanel(p); } } } finally { VisualElementListPool.Release(elements); } }
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); }
void DispatchEnterLeave(VisualElement previousTopElementUnderMouse, VisualElement currentTopElementUnderMouse, Func <EventBase> getEnterEventFunc, Func <EventBase> getLeaveEventFunc) { if (previousTopElementUnderMouse == currentTopElementUnderMouse) { return; } // 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.shadow.parent; } int currDepth = 0; var c = currentTopElementUnderMouse; while (c != null) { currDepth++; c = c.shadow.parent; } p = previousTopElementUnderMouse; c = currentTopElementUnderMouse; while (prevDepth > currDepth) { using (var leaveEvent = getLeaveEventFunc()) { leaveEvent.target = p; DispatchEvent(leaveEvent, p.panel); } prevDepth--; p = p.shadow.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.shadow.parent; } // Now p and c are at the same depth. Go up the tree until p == c. while (p != c) { using (var leaveEvent = getLeaveEventFunc()) { leaveEvent.target = p; DispatchEvent(leaveEvent, p.panel); } enteringElements.Add(c); p = p.shadow.parent; c = c.shadow.parent; } for (var i = enteringElements.Count - 1; i >= 0; i--) { using (var enterEvent = getEnterEventFunc()) { enterEvent.target = enteringElements[i]; DispatchEvent(enterEvent, enteringElements[i].panel); } } VisualElementListPool.Release(enteringElements); }