public object StartDragging(VisualElement item) { var items = _itemsContainer.Children().ToArray(); var context = new DraggingContext { items = items, originalPositions = items.Select(t => t.layout).ToArray(), draggedIndex = _itemsContainer.IndexOf(item), myOriginalPosition = _itemsContainer.layout }; Select(context.draggedIndex); for (int i = 0; i < context.items.Length; ++i) { VisualElement child = context.items[i]; Rect rect = context.originalPositions[i]; child.style.position = PositionType.Absolute; child.style.left = rect.x; child.style.top = rect.y; child.style.width = rect.width; child.style.height = rect.height; } item.BringToFront(); _itemsContainer.style.width = context.myOriginalPosition.width; _itemsContainer.style.height = context.myOriginalPosition.height; return(context); }
void UpdateCollapsibleAreaVisibility() { if (m_CollapsibleArea == null) { return; } bool displayBottom = expanded && extensionContainer.childCount > 0; if (displayBottom) { if (m_CollapsibleArea.parent == null) { VisualElement contents = mainContainer.Q("contents"); if (contents == null) { return; } contents.Add(m_CollapsibleArea); } m_CollapsibleArea.BringToFront(); } else { if (m_CollapsibleArea.parent != null) { m_CollapsibleArea.RemoveFromHierarchy(); } } }
public object StartDragging(VisualElement item) { //Fix all item so that they can be animated and we can control their positions DraggingContext context = new DraggingContext(); context.items = m_ListContainer.Children().ToArray(); context.originalPositions = context.items.Select(t => t.layout).ToArray(); context.draggedIndex = m_ListContainer.IndexOf(item); context.myOriginalPosition = m_ListContainer.layout; Select(context.draggedIndex); for (int i = 0; i < context.items.Length; ++i) { VisualElement child = context.items[i]; Rect rect = context.originalPositions[i]; child.style.position = PositionType.Absolute; child.style.left = rect.x; child.style.top = rect.y; child.style.width = rect.width; child.style.height = rect.height; } item.BringToFront(); m_ListContainer.style.width = context.myOriginalPosition.width; m_ListContainer.style.height = context.myOriginalPosition.height; return(context); }
private void DeferredExecution(GeometryChangedEvent evt) { this.RegisterCallback <GeometryChangedEvent>(DeferredExecution); this.style.color = new StyleColor(StyleKeyword.Initial); maskedText.style.width = this.resolvedStyle.width; maskedText.style.height = this.resolvedStyle.height; maskedText.style.right = -4; maskedText.style.top = -3; maskedText.style.backgroundColor = new StyleColor(StyleKeyword.Initial); VisualElementExtension.SetBorderWidth(maskedText, 2); maskedInput.BringToFront(); }
bool StartDrag(VisualElement target, Vector2 mousePosition) { var startSuccess = StartDrag(target, mousePosition, m_DraggedElement); if (!startSuccess) { return(startSuccess); } m_DraggedElement.BringToFront(); m_DraggedElement.AddToClassList(s_DraggedPreviewClassName); // So we don't have a flashing element at the top left corner // at the very start of the drag. PerformDragInner(target, mousePosition); return(startSuccess); }
void CreateGraph() { m_GraphView = new AssetGraphView { name = "Asset Dependency Graph", }; VisualElement toolbar = CreateToolbar(); VisualElement toolbar2 = CreateFilterbar(); #if !UNITY_2019_1_OR_NEWER rootVisualElement = this.GetRootVisualContainer(); #endif rootVisualElement.Add(toolbar); rootVisualElement.Add(toolbar2); rootVisualElement.Add(m_GraphView); m_GraphView.StretchToParentSize(); toolbar.BringToFront(); toolbar2.BringToFront(); }
private void StartDrag(MouseDownEvent e, int index) { if (e.button == (int)MouseButton.LeftMouse) { var mousePosition = _itemsContainer.WorldToLocal(e.mousePosition); _dragFromIndex = index; _dragToIndex = index; _dragElement = _itemsContainer.ElementAt(index); _dragElement.AddToClassList(ItemDraggingUssClassName); _dragElement.BringToFront(); _dragElement.style.left = mousePosition.x; _dragElement.style.top = mousePosition.y; _itemsContainer.Insert(index, _dragPlaceholder); this.CaptureMouse(); } }
public void OnEnable() { m_GraphView = new AssetGraphView { name = "Asset Dependency Graph", }; var toolbar = new VisualElement { style = { flexDirection = FlexDirection.Row, flexGrow = 0, backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f) } }; var options = new VisualElement { style = { alignContent = Align.Center } }; toolbar.Add(options); toolbar.Add(new Button(ExploreAsset) { text = "Explore Asset", }); toolbar.Add(new Button(ClearGraph) { text = "Clear" }); #if !UNITY_2019_1_OR_NEWER rootVisualElement = this.GetRootVisualContainer(); #endif rootVisualElement.Add(toolbar); rootVisualElement.Add(m_GraphView); m_GraphView.StretchToParentSize(); toolbar.BringToFront(); }
void UpdateCursorTrail() { VisualElement trail = null; if (cursorTrail.Count > 0) { trail = trail = cursorTrail[0]; var hover = trail.userData as HoverAnimation; if (hover != null) { hover.Reset(); } cursorTrail.RemoveAt(0); } else { trail = new VisualElement(); trail.style.position = Position.Absolute; trail.name = "trail"; trail.AddToClassList(cursorTrailClassname); trail.style.backgroundColor = Color.blue; trail.userData = new HoverAnimation(trail); canvas.Add(trail); } trail.style.display = DisplayStyle.Flex; Rect trailPos = new Rect(0, 0, trailSize, trailSize); trailPos.center = cursor.layout.center; trail.style.left = trailPos.x; trail.style.top = trailPos.y; trail.style.width = trailPos.width; trail.style.height = trailPos.height; cursor.BringToFront(); }
public Dialog(IPanel panel, VisualElement content) { AddToClassList(ussClassName); // Set-up the label and text... //this.AddManipulator(new Clickable(OnClickEvent)); m_Background = new VisualElement(); m_Background.AddToClassList(dialogBackgroundUssClassName); m_Background.AddToClassList("unity-ui-document__child"); m_Background.AddManipulator(new Clickable(OnClickBackground)); // Add background to root panel.TopRoot().Add(m_Background); //panel.visualTree.Add(m_Background); // Add dialog to background m_Background.Add(this); //hierarchy.Add(m_Background); //Set up view m_PanelView = new View("GR__Content"); this.Add(m_PanelView); m_PanelView.isDefault = true; m_PanelView.AddToClassList(dialogPanelUssClassName); m_PanelView.Focus(); if (content != null) { m_PanelView.Add(content); content.Focus(); } m_Background.BringToFront(); this.BringToFront(); }
private void OnDragPerformEvent(DragPerformEvent evt) { var selection = DragAndDrop.GetGenericData("DragSelection") as List <ISelectable>; if (!CanAcceptDrop(selection)) { SetDragIndicatorVisible(false); return; } if (m_InsertIndex != -1) { List <Tuple <VisualElement, VisualElement> > draggedElements = new List <Tuple <VisualElement, VisualElement> >(); foreach (ISelectable selectedElement in selection) { var draggedElement = selectedElement as VisualElement; if (draggedElement != null && Contains(draggedElement)) { draggedElements.Add(new Tuple <VisualElement, VisualElement>(FindSectionDirectChild(draggedElement), draggedElement)); } } if (draggedElements.Count == 0) { SetDragIndicatorVisible(false); return; } // Sorts the dragged elements from their relative order in their parent draggedElements.Sort((pair1, pair2) => { return(IndexOf(pair1.Item1).CompareTo(IndexOf(pair2.Item1))); }); int insertIndex = m_InsertIndex; foreach (Tuple <VisualElement, VisualElement> draggedElement in draggedElements) { VisualElement sectionDirectChild = draggedElement.Item1; int indexOfDraggedElement = IndexOf(sectionDirectChild); if (!((indexOfDraggedElement == insertIndex) || ((insertIndex - 1) == indexOfDraggedElement))) { if (blackboard.moveItemRequested != null) { blackboard.moveItemRequested(blackboard, m_InsertIndex, draggedElement.Item2); } else { if (insertIndex == contentContainer.childCount) { sectionDirectChild.BringToFront(); } else { sectionDirectChild.PlaceBehind(this[insertIndex]); } } } if (insertIndex > indexOfDraggedElement) // No need to increment the insert index for the next dragged element if the current dragged element is above the current insert location. { continue; } insertIndex++; } } SetDragIndicatorVisible(false); evt.StopPropagation(); }
public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManager, IEdgeConnectorListener connectorListener) { AddStyleSheetPath("Styles/MaterialNodeView"); AddToClassList("MaterialNode"); if (inNode == null) { return; } var contents = this.Q("contents"); m_ConnectorListener = connectorListener; node = inNode; persistenceKey = node.guid.ToString(); UpdateTitle(); // Add controls container var controlsContainer = new VisualElement { name = "controls" }; { m_ControlsDivider = new VisualElement { name = "divider" }; m_ControlsDivider.AddToClassList("horizontal"); controlsContainer.Add(m_ControlsDivider); m_ControlItems = new VisualElement { name = "items" }; controlsContainer.Add(m_ControlItems); // Instantiate control views from node foreach (var propertyInfo in node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { foreach (IControlAttribute attribute in propertyInfo.GetCustomAttributes(typeof(IControlAttribute), false)) { m_ControlItems.Add(attribute.InstantiateControl(node, propertyInfo)); } } } if (m_ControlItems.childCount > 0) { contents.Add(controlsContainer); } if (node.hasPreview) { // Add actual preview which floats on top of the node m_PreviewContainer = new VisualElement { name = "previewContainer", clippingOptions = ClippingOptions.ClipAndCacheContents, pickingMode = PickingMode.Ignore }; m_PreviewImage = new Image { name = "preview", pickingMode = PickingMode.Ignore, image = Texture2D.whiteTexture, }; { // Add preview collapse button on top of preview var collapsePreviewButton = new VisualElement { name = "collapse" }; collapsePreviewButton.Add(new VisualElement { name = "icon" }); collapsePreviewButton.AddManipulator(new Clickable(() => { node.owner.owner.RegisterCompleteObjectUndo("Collapse Preview"); UpdatePreviewExpandedState(false); })); m_PreviewImage.Add(collapsePreviewButton); } m_PreviewContainer.Add(m_PreviewImage); // Hook up preview image to preview manager m_PreviewRenderData = previewManager.GetPreview(inNode); m_PreviewRenderData.onPreviewChanged += UpdatePreviewTexture; UpdatePreviewTexture(); // Add fake preview which pads out the node to provide space for the floating preview m_PreviewFiller = new VisualElement { name = "previewFiller" }; m_PreviewFiller.AddToClassList("expanded"); { var previewDivider = new VisualElement { name = "divider" }; previewDivider.AddToClassList("horizontal"); m_PreviewFiller.Add(previewDivider); var expandPreviewButton = new VisualElement { name = "expand" }; expandPreviewButton.Add(new VisualElement { name = "icon" }); expandPreviewButton.AddManipulator(new Clickable(() => { node.owner.owner.RegisterCompleteObjectUndo("Expand Preview"); UpdatePreviewExpandedState(true); })); m_PreviewFiller.Add(expandPreviewButton); } contents.Add(m_PreviewFiller); UpdatePreviewExpandedState(node.previewExpanded); } // Add port input container, which acts as a pixel cache for all port inputs m_PortInputContainer = new VisualElement { name = "portInputContainer", clippingOptions = ClippingOptions.ClipAndCacheContents, pickingMode = PickingMode.Ignore }; Add(m_PortInputContainer); AddSlots(node.GetSlots <MaterialSlot>()); UpdatePortInputs(); base.expanded = node.drawState.expanded; RefreshExpandedState(); //This should not be needed. GraphView needs to improve the extension api here UpdatePortInputVisibilities(); SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0)); /*if (node is PreviewNode) * { * var resizeHandle = new Label { name = "resize", text = "" }; * resizeHandle.AddManipulator(new Draggable(OnResize)); * Add(resizeHandle); * UpdateSize(); * }*/ if (node is SubGraphNode) { RegisterCallback <MouseDownEvent>(OnSubGraphDoubleClick); } m_PortInputContainer.SendToBack(); if (node.hasPreview) { m_PreviewFiller.BringToFront(); } }
public void OnEnable() { m_GraphView = new AssetGraphView { name = "Asset Dependency Graph", }; #region Toolbar var toolbar = new VisualElement { style = { flexDirection = FlexDirection.Row, flexGrow = 0, backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f) } }; var options = new VisualElement { style = { alignContent = Align.Center } }; toolbar.Add(options); toolbar.Add(new Button(ExploreAsset) { text = "Explore Asset", }); toolbar.Add(new Button(ClearGraph) { text = "Clear" }); toolbar.Add(new Button(ResetAllGroups) { text = "Reset" }); codeToggle = new Toggle(); codeToggle.text = "Hide Scripts"; codeToggle.value = true; codeToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(codeToggle); MaterialToggle = new Toggle(); MaterialToggle.text = "Hide Materials"; MaterialToggle.value = false; MaterialToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(MaterialToggle); textureToggle = new Toggle(); textureToggle.text = "Hide Textures"; textureToggle.value = true; textureToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(textureToggle); shaderToggle = new Toggle(); shaderToggle.text = "Hide Shaders"; shaderToggle.value = true; shaderToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(shaderToggle); audioClipToggle = new Toggle(); audioClipToggle.text = "Hide Audioclips"; audioClipToggle.value = false; audioClipToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(audioClipToggle); animationClipToggle = new Toggle(); animationClipToggle.text = "Hide Animationclips"; animationClipToggle.value = false; animationClipToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(animationClipToggle); CustomToggle = new Toggle(); CustomToggle.text = "Hide Custom"; CustomToggle.value = true; CustomToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(CustomToggle); var ts = new ToolbarSearchField(); ts.RegisterValueChangedCallback(x => { if (string.IsNullOrEmpty(x.newValue)) { m_GraphView.FrameAll(); return; } m_GraphView.ClearSelection(); // m_GraphView.graphElements.ForEach(y => { // BROKEN, Case 1268337 m_GraphView.graphElements.ToList().ForEach(y => { if (y is Node node && y.title.IndexOf(x.newValue, System.StringComparison.OrdinalIgnoreCase) >= 0) { m_GraphView.AddToSelection(node); } }); m_GraphView.FrameSelection(); }); toolbar.Add(ts); AlignmentToggle = new Toggle(); AlignmentToggle.text = "Horizontal Layout"; AlignmentToggle.value = false; AlignmentToggle.RegisterValueChangedCallback(x => { ResetAllGroups(); }); toolbar.Add(AlignmentToggle); #endregion #if !UNITY_2019_1_OR_NEWER rootVisualElement = this.GetRootVisualContainer(); #endif rootVisualElement.Add(toolbar); rootVisualElement.Add(m_GraphView); m_GraphView.StretchToParentSize(); toolbar.BringToFront(); }
// public bool DragPerform(DragPerformEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget) public EventPropagation DragPerform(IMGUIEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget) { if (m_InsertIndex != -1) { List <VisualElementPair> draggedElements = new List <VisualElementPair>(); foreach (ISelectable selectedElement in selection) { var draggedElement = selectedElement as VisualElement; if (draggedElement != null && Contains(draggedElement)) { draggedElements.Add(new VisualElementPair(FindSectionDirectChild(draggedElement), draggedElement)); } } if (draggedElements.Count == 0) { SetDragIndicatorVisible(false); return(EventPropagation.Continue); } // Sorts the dragged elements from their relative order in their parent draggedElements.Sort((pair1, pair2) => { return(IndexOf(pair1.Item1).CompareTo(IndexOf(pair2.Item1))); }); int insertIndex = m_InsertIndex; foreach (var draggedElement in draggedElements) { VisualElement sectionDirectChild = draggedElement.Item1; int indexOfDraggedElement = IndexOf(sectionDirectChild); if (!((indexOfDraggedElement == insertIndex) || ((insertIndex - 1) == indexOfDraggedElement))) { Blackboard blackboard = GetFirstAncestorOfType <Blackboard>(); if (blackboard.moveItemRequested != null) { blackboard.moveItemRequested(blackboard, m_InsertIndex, draggedElement.Item2); } else { if (insertIndex == contentContainer.childCount) { sectionDirectChild.BringToFront(); } else { sectionDirectChild.PlaceBehind(this[insertIndex]); } } } if (insertIndex > indexOfDraggedElement) // No need to increment the insert index for the next dragged element if the current dragged element is above the current insert location. { continue; } insertIndex++; } } SetDragIndicatorVisible(false); return(EventPropagation.Stop); }
public void OnEnable() { m_GraphView = new AssetGraphView { name = "Asset Dependency Graph", }; var toolbar = new VisualElement { style = { flexDirection = FlexDirection.Row, flexGrow = 0, backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f) } }; var options = new VisualElement { style = { alignContent = Align.Center } }; toolbar.Add(options); toolbar.Add(new Button(ExploreAsset) { text = "Explore Asset", }); toolbar.Add(new Button(ClearGraph) { text = "Clear" }); var ts = new ToolbarSearchField(); ts.RegisterValueChangedCallback(x => { if (string.IsNullOrEmpty(x.newValue)) { m_GraphView.FrameAll(); return; } m_GraphView.ClearSelection(); // m_GraphView.graphElements.ForEach(y => { // BROKEN, Case 1268337 m_GraphView.graphElements.ToList().ForEach(y => { if (y is Node node && y.title.IndexOf(x.newValue, StringComparison.OrdinalIgnoreCase) >= 0) { m_GraphView.AddToSelection(node); } }); m_GraphView.FrameSelection(); }); toolbar.Add(ts); #if !UNITY_2019_1_OR_NEWER rootVisualElement = this.GetRootVisualContainer(); #endif rootVisualElement.Add(toolbar); rootVisualElement.Add(m_GraphView); m_GraphView.StretchToParentSize(); toolbar.BringToFront(); }