Beispiel #1
0
        private void UpdateSubTree(VisualElement ve, int currentLayoutPass)
        {
            Rect rect         = new Rect(ve.yogaNode.LayoutX, ve.yogaNode.LayoutY, ve.yogaNode.LayoutWidth, ve.yogaNode.LayoutHeight);
            Rect lastPadding  = new Rect(ve.yogaNode.LayoutPaddingLeft, ve.yogaNode.LayoutPaddingTop, ve.yogaNode.LayoutWidth - (ve.yogaNode.LayoutPaddingLeft + ve.yogaNode.LayoutPaddingRight), ve.yogaNode.LayoutHeight - (ve.yogaNode.LayoutPaddingTop + ve.yogaNode.LayoutPaddingBottom));
            Rect lastLayout   = ve.lastLayout;
            Rect lastPadding2 = ve.lastPadding;
            VersionChangeType versionChangeType = (VersionChangeType)0;
            bool flag  = lastLayout.size != rect.size;
            bool flag2 = lastPadding2.size != lastPadding.size;
            bool flag3 = flag | flag2;

            if (flag3)
            {
                versionChangeType |= (VersionChangeType.Size | VersionChangeType.Repaint);
            }
            bool flag4 = rect.position != lastLayout.position;
            bool flag5 = lastPadding.position != lastPadding2.position;
            bool flag6 = flag4 | flag5;

            if (flag6)
            {
                versionChangeType |= VersionChangeType.Transform;
            }
            bool flag7 = versionChangeType > (VersionChangeType)0;

            if (flag7)
            {
                ve.IncrementVersion(versionChangeType);
            }
            ve.lastLayout  = rect;
            ve.lastPadding = lastPadding;
            bool hasNewLayout = ve.yogaNode.HasNewLayout;
            bool flag8        = hasNewLayout;

            if (flag8)
            {
                int childCount = ve.hierarchy.childCount;
                for (int i = 0; i < childCount; i++)
                {
                    this.UpdateSubTree(ve.hierarchy[i], currentLayoutPass);
                }
            }
            bool flag9 = flag | flag4;

            if (flag9)
            {
                using (GeometryChangedEvent pooled = GeometryChangedEvent.GetPooled(lastLayout, rect))
                {
                    pooled.layoutPass = currentLayoutPass;
                    pooled.target     = ve;
                    ve.SendEvent(pooled);
                }
            }
            bool flag10 = hasNewLayout;

            if (flag10)
            {
                ve.yogaNode.MarkLayoutSeen();
            }
        }
            /// <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");
                }

                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);
            }
Beispiel #3
0
        // When this becomes more common, this should be a member list straight inside VisualElement
        public static void SetAdditionalBinding(VisualElement ve, IBinding b)
        {
            var current = GetAdditionalBinding(ve);

            current?.Release();
            ve.SetProperty(s_AdditionalBindingObjectVEPropertyName, b);
            ve.IncrementVersion(VersionChangeType.Bindings);
        }
        private void UpdateSubTree(VisualElement ve, int currentLayoutPass)
        {
            Rect yogaRect    = new Rect(ve.yogaNode.LayoutX, ve.yogaNode.LayoutY, ve.yogaNode.LayoutWidth, ve.yogaNode.LayoutHeight);
            Rect lastRect    = ve.renderData.lastLayout;
            bool rectChanged = false;

            // If the last layout rect is different than the current one we must dirty transform on children
            if ((lastRect.width != yogaRect.width) || (lastRect.height != yogaRect.height))
            {
                ve.IncrementVersion(VersionChangeType.Clip | VersionChangeType.Repaint); // Layout change require a clip update + repaint
                rectChanged = true;
            }
            if (yogaRect.position != lastRect.position)
            {
                ve.IncrementVersion(VersionChangeType.Transform);
                rectChanged = true;
            }
            ve.renderData.lastLayout = yogaRect;

            // ignore clean sub trees
            bool hasNewLayout = ve.yogaNode.HasNewLayout;

            if (hasNewLayout)
            {
                for (int i = 0; i < ve.hierarchy.childCount; ++i)
                {
                    UpdateSubTree(ve.hierarchy[i], currentLayoutPass);
                }
            }

            if (rectChanged)
            {
                using (var evt = GeometryChangedEvent.GetPooled(lastRect, yogaRect))
                {
                    evt.layoutPass = currentLayoutPass;
                    evt.target     = ve;
                    ve.SendEvent(evt);
                }
            }

            if (hasNewLayout)
            {
                ve.yogaNode.MarkLayoutSeen();
            }
        }
        private void UpdateSubTree(VisualElement root)
        {
            Rect yogaRect    = new Rect(root.yogaNode.LayoutX, root.yogaNode.LayoutY, root.yogaNode.LayoutWidth, root.yogaNode.LayoutHeight);
            Rect lastRect    = root.renderData.lastLayout;
            bool rectChanged = lastRect != yogaRect;

            // If the last layout rect is different than the current one we must dirty transform on children
            if (rectChanged)
            {
                if (yogaRect.position != lastRect.position)
                {
                    root.IncrementVersion(VersionChangeType.Transform);
                }
                root.IncrementVersion(VersionChangeType.Size);
                root.renderData.lastLayout = yogaRect;
            }

            // ignore clean sub trees
            bool hasNewLayout = root.yogaNode.HasNewLayout;

            if (hasNewLayout)
            {
                for (int i = 0; i < root.hierarchy.childCount; ++i)
                {
                    UpdateSubTree(root.hierarchy[i]);
                }
            }

            if (rectChanged)
            {
                using (var evt = GeometryChangedEvent.GetPooled(lastRect, yogaRect))
                {
                    evt.target = root;
                    root.SendEvent(evt);
                }
            }

            if (hasNewLayout)
            {
                root.yogaNode.MarkLayoutSeen();
                // Layout change require a repaint
                root.IncrementVersion(VersionChangeType.Repaint);
            }
        }
Beispiel #6
0
        public void Add(StyleSheet styleSheet)
        {
            if (styleSheet == null)
            {
                throw new ArgumentNullException(nameof(styleSheet));
            }

            if (m_Element.styleSheetList == null)
            {
                m_Element.styleSheetList = new List <StyleSheet>();
            }
            else if (m_Element.styleSheetList.Contains(styleSheet))
            {
                return;
            }

            m_Element.styleSheetList.Add(styleSheet);
            m_Element.IncrementVersion(VersionChangeType.StyleSheet);
        }
        /// <summary>
        /// Adds a style sheet for the owner element.
        /// </summary>
        public void Add(StyleSheet styleSheet)
        {
            if (styleSheet == null)
            {
                throw new ArgumentNullException(nameof(styleSheet));
            }

            if (m_Element.styleSheetList == null)
            {
                m_Element.styleSheetList = new List <StyleSheet>();
            }
            else if (m_Element.styleSheetList.Contains(styleSheet))
            {
                return;
            }

            m_Element.styleSheetList.Add(styleSheet);
            m_Element.IncrementVersion(VersionChangeType.StyleSheet);

            m_Element.elementPanel?.liveReloadSystem.StartStyleSheetAssetTracking(styleSheet);
        }
Beispiel #8
0
        public static void AddBindingRequest(VisualElement ve, IBindingRequest req)
        {
            List <IBindingRequest> l = ve.GetProperty(s_BindingRequestObjectVEPropertyName) as List <IBindingRequest>;

            if (l == null)
            {
                l = RequestObjectListPool.Get();
                ve.SetProperty(s_BindingRequestObjectVEPropertyName, l);
            }

            l.Add(req);
            ve.IncrementVersion(VersionChangeType.Bindings);
        }
        /// <summary>
        /// Adds a style sheet for the owner element.
        /// </summary>
        public void Add(StyleSheet styleSheet)
        {
            if (styleSheet == null)
            {
                throw new ArgumentNullException(nameof(styleSheet));
            }

            if (m_Element.styleSheetList == null)
            {
                m_Element.styleSheetList = new List <StyleSheet>();
            }
            else if (m_Element.styleSheetList.Contains(styleSheet))
            {
                return;
            }

            m_Element.styleSheetList.Add(styleSheet);
            m_Element.IncrementVersion(VersionChangeType.StyleSheet);

#if UNITY_EDITOR
            m_Element.elementPanel?.m_LiveReloadStyleSheetAssetTracker?.StartTrackingAsset(styleSheet);
#endif
        }
        private void UpdateSubTree(VisualElement ve, int currentLayoutPass)
        {
            Rect yogaLayoutRect  = new Rect(ve.yogaNode.LayoutX, ve.yogaNode.LayoutY, ve.yogaNode.LayoutWidth, ve.yogaNode.LayoutHeight);
            Rect yogaPaddingRect = new Rect(
                ve.yogaNode.LayoutPaddingLeft,
                ve.yogaNode.LayoutPaddingTop,
                ve.yogaNode.LayoutWidth - (ve.yogaNode.LayoutPaddingLeft + ve.yogaNode.LayoutPaddingRight),
                ve.yogaNode.LayoutHeight - (ve.yogaNode.LayoutPaddingTop + ve.yogaNode.LayoutPaddingBottom));
            Rect lastLayoutRect  = ve.lastLayout;
            Rect lastPaddingRect = ve.lastPadding;

            VersionChangeType changeType = 0;

            // Changing the layout/padding size should trigger the following version changes:
            // - Size:    to update the clipping rect, when required
            // - Repaint: to update the geometry inside the new rect
            bool layoutSizeChanged  = lastLayoutRect.size != yogaLayoutRect.size;
            bool paddingSizeChanged = lastPaddingRect.size != yogaPaddingRect.size;

            if (layoutSizeChanged || paddingSizeChanged)
            {
                changeType |= VersionChangeType.Size | VersionChangeType.Repaint;
            }

            // Changing the layout/padding position should trigger the following version change:
            // - Transform: to draw the element and content at the right position
            bool layoutPositionChanged  = yogaLayoutRect.position != lastLayoutRect.position;
            bool paddingPositionChanged = yogaPaddingRect.position != lastPaddingRect.position;

            if (layoutPositionChanged || paddingPositionChanged)
            {
                changeType |= VersionChangeType.Transform;
            }

            if (changeType != 0)
            {
                ve.IncrementVersion(changeType);
            }

            ve.lastLayout  = yogaLayoutRect;
            ve.lastPadding = yogaPaddingRect;

            // ignore clean sub trees
            bool hasNewLayout = ve.yogaNode.HasNewLayout;

            if (hasNewLayout)
            {
                var childCount = ve.hierarchy.childCount;
                for (int i = 0; i < childCount; ++i)
                {
                    UpdateSubTree(ve.hierarchy[i], currentLayoutPass);
                }
            }

            // Only send GeometryChanged events when the layout changes
            // (padding changes don't affect the element's geometry).
            if (layoutSizeChanged || layoutPositionChanged)
            {
                using (var evt = GeometryChangedEvent.GetPooled(lastLayoutRect, yogaLayoutRect))
                {
                    evt.layoutPass = currentLayoutPass;
                    evt.target     = ve;
                    ve.SendEvent(evt);
                }
            }

            if (hasNewLayout)
            {
                ve.yogaNode.MarkLayoutSeen();
            }
        }
Beispiel #11
0
        private void UpdateSubTree(VisualElement ve, bool isDisplayed, List <KeyValuePair <Rect, VisualElement> > changeEvents)
        {
            Rect yogaLayoutRect = new Rect(ve.yogaNode.LayoutX, ve.yogaNode.LayoutY, ve.yogaNode.LayoutWidth, ve.yogaNode.LayoutHeight);

            // we encode right/bottom into width/height
            Rect rawPadding = new Rect(ve.yogaNode.LayoutPaddingLeft, ve.yogaNode.LayoutPaddingLeft, ve.yogaNode.LayoutPaddingRight, ve.yogaNode.LayoutPaddingBottom);

            // This is not the "real" padding rect: it may differ in size and position because the borders are ignored.
            // Alone, it cannot be used to identify padding size changes, because the bottom and right values depend on the
            // layout rect width/height. A change in layout rect width/height with a corresponding variation in
            // right/bottom values may yield the same pseudoPaddingRect. Fortunately, the layout rect size and padding rect
            // size change trigger the same code path which explains why we haven't seen any issue with this so far.
            Rect yogaPseudoPaddingRect = new Rect(
                rawPadding.x,
                rawPadding.y,
                yogaLayoutRect.width - (rawPadding.x + rawPadding.width),
                yogaLayoutRect.height - (rawPadding.y + rawPadding.height));
            Rect lastLayoutRect        = ve.lastLayout;
            Rect lastPseudoPaddingRect = ve.lastPseudoPadding;
            bool wasHierarchyDisplayed = ve.isHierarchyDisplayed;

            VersionChangeType changeType = 0;
            // Changing the layout/padding size should trigger the following version changes:
            // - Size:    to update the clipping rect, when required
            // - Repaint: to update the geometry inside the new rect
            bool layoutSizeChanged        = lastLayoutRect.size != yogaLayoutRect.size;
            bool pseudoPaddingSizeChanged = lastPseudoPaddingRect.size != yogaPseudoPaddingRect.size;

            if (layoutSizeChanged || pseudoPaddingSizeChanged)
            {
                changeType |= VersionChangeType.Size | VersionChangeType.Repaint;
            }

            // Changing the layout/padding position should trigger the following version change:
            // - Transform: to draw the element and content at the right position
            bool layoutPositionChanged  = yogaLayoutRect.position != lastLayoutRect.position;
            bool paddingPositionChanged = yogaPseudoPaddingRect.position != lastPseudoPaddingRect.position;

            if (layoutPositionChanged || paddingPositionChanged)
            {
                changeType |= VersionChangeType.Transform;
            }

            isDisplayed            &= ve.resolvedStyle.display != DisplayStyle.None;
            ve.isHierarchyDisplayed = isDisplayed;

            if (changeType != 0)
            {
                ve.IncrementVersion(changeType);
            }

            ve.lastLayout        = yogaLayoutRect;
            ve.lastPseudoPadding = yogaPseudoPaddingRect;

            // ignore clean sub trees
            bool hasNewLayout = ve.yogaNode.HasNewLayout;

            if (hasNewLayout)
            {
                var childCount = ve.hierarchy.childCount;
                for (int i = 0; i < childCount; ++i)
                {
                    var child = ve.hierarchy[i];

                    if (child.yogaNode.HasNewLayout)
                    {
                        UpdateSubTree(child, isDisplayed, changeEvents);
                    }
                }
            }

            // Only send GeometryChanged events when the layout changes
            // (padding changes don't affect the element's outer geometry).
            if ((layoutSizeChanged || layoutPositionChanged) && ve.HasEventCallbacksOrDefaultActions(GeometryChangedEvent.EventCategory))
            {
                changeEvents.Add(new KeyValuePair <Rect, VisualElement>(lastLayoutRect, ve));
            }

            if (hasNewLayout)
            {
                ve.yogaNode.MarkLayoutSeen();
            }
        }