protected internal override Vector2 DoMeasure(float width, MeasureMode widthMode, float height, MeasureMode heightMode) { GraphView graphView = GetFirstAncestorOfType <GraphView>(); VisualElement viewport = graphView.contentViewContainer; contentRectInViewportSpace = Rect.zero; // Compute the bounding box of the content of the scope in viewport space (because nodes are not parented by the scope that contains them) foreach (GraphElement subElement in containedElements) { if (subElement.panel != panel) { continue; } if (subElement.parent == null) { continue; } Rect boundingRect = subElement.GetPosition(); if (Scope.IsValidRect(boundingRect)) { boundingRect = subElement.parent.ChangeCoordinatesTo(viewport, boundingRect); // Use the first element with a valid geometry as reference to compute the bounding box of contained elements if (!Scope.IsValidRect(contentRectInViewportSpace)) { contentRectInViewportSpace = boundingRect; } else { contentRectInViewportSpace = RectUtils.Encompass(contentRectInViewportSpace, boundingRect); } } } return(new Vector2(contentRectInViewportSpace.width, contentRectInViewportSpace.height)); }
public void UpdateGeometryFromContent() { if (panel == null || !m_Initialized || m_IsUpdatingGeometryFromContent || m_IsMovingElements) { return; } GraphView graphView = GetFirstAncestorOfType <GraphView>(); if (graphView == null) { return; } m_IsUpdatingGeometryFromContent = true; VisualElement viewport = graphView.contentViewContainer; Rect contentRectInViewportSpace = Rect.zero; // Compute the bounding box of the content of the group in viewport space (because nodes are not parented by the group that contains them) if (m_ContainedElements != null) { for (int i = 0; i < m_ContainedElements.Count; ++i) { GraphElement subElement = m_ContainedElements[i]; if (subElement.panel != panel) { continue; } Rect boundingRect = new Rect(0, 0, subElement.GetPosition().width, subElement.GetPosition().height); if (IsValidRect(boundingRect)) { boundingRect = subElement.ChangeCoordinatesTo(viewport, boundingRect); // Use the first element with a valid geometry as reference to compute the bounding box of contained elements if (!IsValidRect(contentRectInViewportSpace)) { contentRectInViewportSpace = boundingRect; } else { contentRectInViewportSpace = RectUtils.Encompass(contentRectInViewportSpace, boundingRect); } } } } if ((m_ContainedElements == null) || (m_ContainedElements.Count == 0)) { float contentX = m_ContentItem.style.borderLeftWidth.value + m_ContentItem.style.paddingLeft.value; float contentY = m_HeaderItem.layout.height + m_ContentItem.style.borderTopWidth.value + m_ContentItem.style.paddingTop.value; contentRectInViewportSpace = this.ChangeCoordinatesTo(viewport, new Rect(contentX, contentY, 0, 0)); } float titleItemImplicitWidth = k_TitleItemMinWidth; if (m_HeaderItem != null) { Vector2 implicitSize = m_TitleItem.DoMeasure(100, MeasureMode.Undefined, 100, MeasureMode.Undefined); if (IsValidSize(implicitSize)) { titleItemImplicitWidth = implicitSize.x + m_TitleItem.style.marginLeft.value + m_TitleItem.style.paddingLeft.value + m_TitleItem.style.paddingRight.value + m_TitleItem.style.marginRight.value; } } float headerItemImplicitWidth = titleItemImplicitWidth + m_HeaderItem.style.paddingLeft.value + m_HeaderItem.style.paddingRight.value; Vector2 contentRectSize = contentRectInViewportSpace.size; contentRectSize.x += m_ContentItem.style.borderLeftWidth.value + m_ContentItem.style.paddingLeft.value + m_ContentItem.style.paddingRight.value + m_ContentItem.style.borderRightWidth.value; contentRectSize.y += m_ContentItem.style.borderTopWidth.value + m_ContentItem.style.paddingTop.value + m_ContentItem.style.paddingBottom.value + m_ContentItem.style.borderBottomWidth.value; Rect groupGeometry = new Rect(); groupGeometry.position = viewport.ChangeCoordinatesTo(parent, contentRectInViewportSpace.position); groupGeometry.width = Math.Max(contentRectSize.x, headerItemImplicitWidth) + style.borderLeftWidth.value + style.borderRightWidth.value; // Ensure that the title is always visible groupGeometry.height = contentRectSize.y + m_HeaderItem.layout.height + style.borderTopWidth.value + style.borderBottomWidth.value; groupGeometry.x -= m_ContentItem.style.paddingLeft.value + style.borderLeftWidth.value; groupGeometry.y -= m_ContentItem.style.paddingTop.value + m_HeaderItem.layout.height + style.borderTopWidth.value; SetPosition(groupGeometry); Vector2 newPosInCanvasSpace = this.ChangeCoordinatesTo(viewport, new Vector2(0, 0)); mPreviousPosInCanvasSpace = newPosInCanvasSpace; m_ContainedElementsRect = viewport.ChangeCoordinatesTo(this, contentRectInViewportSpace); m_IsUpdatingGeometryFromContent = false; }
public void UpdateGeometryFromContent() { if (base.panel != null && this.m_Initialized && !this.m_IsUpdatingGeometryFromContent && !this.m_IsMovingElements) { GraphView firstAncestorOfType = base.GetFirstAncestorOfType <GraphView>(); if (firstAncestorOfType != null) { this.m_IsUpdatingGeometryFromContent = true; VisualElement contentViewContainer = firstAncestorOfType.contentViewContainer; Rect rect = Rect.zero; if (this.m_ContainedElements != null) { for (int i = 0; i < this.m_ContainedElements.Count; i++) { GraphElement graphElement = this.m_ContainedElements[i]; if (graphElement.panel == base.panel) { Rect rect2 = new Rect(0f, 0f, graphElement.GetPosition().width, graphElement.GetPosition().height); if (GroupNode.IsValidRect(rect2)) { rect2 = graphElement.ChangeCoordinatesTo(contentViewContainer, rect2); if (!GroupNode.IsValidRect(rect)) { rect = rect2; } else { rect = RectUtils.Encompass(rect, rect2); } } } } } if (this.m_ContainedElements == null || this.m_ContainedElements.Count == 0) { float x = this.m_ContentItem.style.borderLeftWidth.value + this.m_ContentItem.style.paddingLeft.value; float y = this.m_HeaderItem.layout.height + this.m_ContentItem.style.borderTopWidth.value + this.m_ContentItem.style.paddingTop.value; rect = this.ChangeCoordinatesTo(contentViewContainer, new Rect(x, y, 0f, 0f)); } float num = 10f; if (this.m_HeaderItem != null) { Vector2 size = this.m_TitleItem.DoMeasure(100f, VisualElement.MeasureMode.Undefined, 100f, VisualElement.MeasureMode.Undefined); if (GroupNode.IsValidSize(size)) { num = size.x + this.m_TitleItem.style.marginLeft.value + this.m_TitleItem.style.paddingLeft.value + this.m_TitleItem.style.paddingRight.value + this.m_TitleItem.style.marginRight.value; } } float val = num + this.m_HeaderItem.style.paddingLeft.value + this.m_HeaderItem.style.paddingRight.value; Vector2 size2 = rect.size; size2.x += this.m_ContentItem.style.borderLeftWidth.value + this.m_ContentItem.style.paddingLeft.value + this.m_ContentItem.style.paddingRight.value + this.m_ContentItem.style.borderRightWidth.value; size2.y += this.m_ContentItem.style.borderTopWidth.value + this.m_ContentItem.style.paddingTop.value + this.m_ContentItem.style.paddingBottom.value + this.m_ContentItem.style.borderBottomWidth.value; Rect position = default(Rect); position.position = contentViewContainer.ChangeCoordinatesTo(base.parent, rect.position); position.width = Math.Max(size2.x, val) + base.style.borderLeftWidth.value + base.style.borderRightWidth.value; position.height = size2.y + this.m_HeaderItem.layout.height + base.style.borderTopWidth.value + base.style.borderBottomWidth.value; position.x -= this.m_ContentItem.style.paddingLeft.value + base.style.borderLeftWidth.value; position.y -= this.m_ContentItem.style.paddingTop.value + this.m_HeaderItem.layout.height + base.style.borderTopWidth.value; this.SetPosition(position); Vector2 vector = this.ChangeCoordinatesTo(contentViewContainer, new Vector2(0f, 0f)); this.mPreviousPosInCanvasSpace = vector; this.m_ContainedElementsRect = contentViewContainer.ChangeCoordinatesTo(this, rect); this.m_IsUpdatingGeometryFromContent = false; } } }