static bool WasSelectableDescendantHitByMouse(GraphElement currentTarget, MouseDownEvent evt) { VisualElement targetElement = evt.target as VisualElement; if (targetElement == null || currentTarget == targetElement) { return(false); } VisualElement descendant = targetElement; while (descendant != null && currentTarget != descendant) { GraphElement selectableDescendant = descendant as GraphElement; if (selectableDescendant != null && selectableDescendant.enabledInHierarchy && selectableDescendant.pickingMode != PickingMode.Ignore && selectableDescendant.IsSelectable()) { Vector2 localMousePosition = currentTarget.ChangeCoordinatesTo(descendant, evt.localMousePosition); if (selectableDescendant.HitTest(localMousePosition)) { return(true); } } descendant = descendant.parent; } return(false); }
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; }
Rect CalculateElementRect(GraphElement elem) { // TODO: Should Edges be displayed at all? // TODO: Maybe edges need their own capabilities flag. if (elem is Edge || elem is Port) { return(new Rect(0, 0, 0, 0)); } Rect rect = elem.ChangeCoordinatesTo(graphView.contentViewContainer, elem.rect); rect.x = m_ContentRect.x + ((rect.x - m_ContentRectLocal.x) * m_ContentRect.width / m_ContentRectLocal.width); rect.y = m_ContentRect.y + ((rect.y - m_ContentRectLocal.y) * m_ContentRect.height / m_ContentRectLocal.height); rect.width *= m_ContentRect.width / m_ContentRectLocal.width; rect.height *= m_ContentRect.height / m_ContentRectLocal.height; // Clip using a minimal 2 pixel wide frame around edges // (except yMin since we already have the titleBar offset which is enough for clipping) var xMin = 2; var yMin = 0; var xMax = layout.width - 2; var yMax = layout.height - 2; if (rect.x < xMin) { if (rect.x < xMin - rect.width) { return(new Rect(0, 0, 0, 0)); } rect.width -= xMin - rect.x; rect.x = xMin; } if (rect.x + rect.width >= xMax) { if (rect.x >= xMax) { return(new Rect(0, 0, 0, 0)); } rect.width -= rect.x + rect.width - xMax; } if (rect.y < yMin + titleBarOffset) { if (rect.y < yMin + titleBarOffset - rect.height) { return(new Rect(0, 0, 0, 0)); } rect.height -= yMin + titleBarOffset - rect.y; rect.y = yMin + titleBarOffset; } if (rect.y + rect.height >= yMax) { if (rect.y >= yMax) { return(new Rect(0, 0, 0, 0)); } rect.height -= rect.y + rect.height - yMax; } return(rect); }
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; } } }