Пример #1
0
        public Group()
        {
            this.AddStylesheet("Group.uss");

            m_DropArea = new GroupDropArea();
            m_DropArea.ClearClassList();
            m_DropArea.name = "dropArea";

            var           visualTree     = GraphElementsHelper.LoadUXML("GroupTitle.uxml");
            VisualElement titleContainer = visualTree.Instantiate();

            titleContainer.name = "titleContainer";

            m_TitleItem = titleContainer.Q <Label>(name: "titleLabel");

            m_TitleEditor = titleContainer.Q(name: "titleField") as TextField;
            m_TitleEditor.style.display = DisplayStyle.None;

            var titleinput = m_TitleEditor.Q(TextField.textInputUssName);

            titleinput.RegisterCallback <FocusOutEvent>(e => { OnEditTitleFinished(); });
            titleinput.RegisterCallback <KeyDownEvent>(TitleEditorOnKeyDown);

            VisualElement contentContainerPlaceholder = this.Q(name: "contentContainerPlaceholder");

            contentContainerPlaceholder.Insert(0, m_DropArea);

            headerContainer.Add(titleContainer);

            AddToClassList("group");

            capabilities |= Capabilities.Selectable | Capabilities.Movable | Capabilities.Deletable | Capabilities.Copiable;

            RegisterCallback <MouseDownEvent>(OnMouseDownEvent);
        }
Пример #2
0
        public BlackboardRow(VisualElement item, VisualElement propertyView)
        {
            var tpl = GraphElementsHelper.LoadUXML("BlackboardRow.uxml");

            this.AddStylesheet(Blackboard.StyleSheetPath);

            VisualElement mainContainer = tpl.Instantiate();

            mainContainer.AddToClassList("mainContainer");

            m_Root                  = mainContainer.Q("root");
            m_ItemContainer         = mainContainer.Q("itemContainer");
            m_PropertyViewContainer = mainContainer.Q("propertyViewContainer");

            m_ExpandButton = mainContainer.Q <Button>("expandButton");
            m_ExpandButton.clickable.clicked += () => expanded = !expanded;

            Add(mainContainer);

            ClearClassList();
            AddToClassList("blackboardRow");

            m_ItemContainer.Add(item);
            m_PropertyViewContainer.Add(propertyView);

            expanded = false;
        }
        public BlackboardSection()
        {
            var tpl = GraphElementsHelper.LoadUXML("BlackboardSection.uxml");

            this.AddStylesheet(Blackboard.StyleSheetPath);
            m_MainContainer = tpl.Instantiate();
            m_MainContainer.AddToClassList("mainContainer");

            m_Header        = m_MainContainer.Q("sectionHeader");
            m_TitleLabel    = m_MainContainer.Q <Label>("sectionTitleLabel");
            m_RowsContainer = m_MainContainer.Q("rowsContainer");

            hierarchy.Add(m_MainContainer);

            m_DragIndicator = new VisualElement();

            m_DragIndicator.name           = "dragIndicator";
            m_DragIndicator.style.position = Position.Absolute;
            hierarchy.Add(m_DragIndicator);

            ClearClassList();
            AddToClassList("blackboardSection");

            RegisterCallback <DragUpdatedEvent>(OnDragUpdatedEvent);
            RegisterCallback <DragPerformEvent>(OnDragPerformEvent);
            RegisterCallback <DragLeaveEvent>(OnDragLeaveEvent);

            m_InsertIndex = -1;
        }
Пример #4
0
        public ResizableElement(string uiFile)
        {
            var tpl = Resources.Load <VisualTreeAsset>(uiFile);

            if (tpl == null)
            {
                tpl = GraphElementsHelper.LoadUXML(uiFile);
            }

            this.AddStylesheet("Resizable.uss");

            tpl.CloneTree(this);

            foreach (ResizerDirection value in System.Enum.GetValues(typeof(ResizerDirection)))
            {
                VisualElement resizer = this.Q(value.ToString().ToLower() + "-resize");
                if (resizer != null)
                {
                    resizer.AddManipulator(new ElementResizer(this, value));
                }
            }

            foreach (ResizerDirection vertical in new[] { ResizerDirection.Top, ResizerDirection.Bottom })
            {
                foreach (ResizerDirection horizontal in new[] { ResizerDirection.Left, ResizerDirection.Right })
                {
                    VisualElement resizer = this.Q(vertical.ToString().ToLower() + "-" + horizontal.ToString().ToLower() + "-resize");
                    if (resizer != null)
                    {
                        resizer.AddManipulator(new ElementResizer(this, vertical | horizontal));
                    }
                }
            }
        }
        public IconBadge()
        {
            m_IsAttached = false;
            m_Distance   = kDefaultDistanceValue;
            var tpl = GraphElementsHelper.LoadUXML("IconBadge.uxml");

            LoadTemplate(tpl);

            RegisterCallback <CustomStyleResolvedEvent>(OnCustomStyleResolved);
            visualStyle = "error";
        }
Пример #6
0
        public StickyNote(string uiFile, Vector2 position)
        {
            var tpl = Resources.Load <VisualTreeAsset>(uiFile);

            if (tpl == null)
            {
                tpl = GraphElementsHelper.LoadUXML(uiFile);
            }

            tpl.CloneTree(this);

            capabilities = Capabilities.Movable | Capabilities.Deletable | Capabilities.Ascendable | Capabilities.Selectable | Capabilities.Copiable;

            m_Title = this.Q <Label>(name: "title");
            if (m_Title != null)
            {
                m_Title.RegisterCallback <MouseDownEvent>(OnTitleMouseDown);
            }

            m_TitleField = this.Q <TextField>(name: "title-field");
            if (m_TitleField != null)
            {
                m_TitleField.style.display = DisplayStyle.None;
                m_TitleField.Q("unity-text-input").RegisterCallback <BlurEvent>(OnTitleBlur);
                m_TitleField.RegisterCallback <ChangeEvent <string> >(OnTitleChange);
            }


            m_Contents = this.Q <Label>(name: "contents");
            if (m_Contents != null)
            {
                m_ContentsField = m_Contents.Q <TextField>(name: "contents-field");
                if (m_ContentsField != null)
                {
                    m_ContentsField.style.display = DisplayStyle.None;
                    m_ContentsField.multiline     = true;
                    m_ContentsField.Q("unity-text-input").RegisterCallback <BlurEvent>(OnContentsBlur);
                }
                m_Contents.RegisterCallback <MouseDownEvent>(OnContentsMouseDown);
            }

            SetPosition(new Rect(position, defaultSize));

            AddToClassList("sticky-note");
            AddToClassList("selectable");
            UpdateThemeClasses();
            UpdateSizeClasses();

            this.AddManipulator(new ContextualMenuManipulator(BuildContextualMenu));
        }
Пример #7
0
        internal void Init(GraphView graphView)
        {
            m_GraphView = graphView;

            var template = GraphElementsHelper.LoadUXML("PlacematElement.uxml");

            if (template != null)
            {
                template.CloneTree(this);
            }

            this.AddStylesheet("Placemat.uss");
            AddToClassList("placemat");
            AddToClassList("selectable");

            pickingMode = PickingMode.Position;

            capabilities |= Capabilities.Deletable | Capabilities.Movable | Capabilities.Selectable | Capabilities.Copiable;
            capabilities &= ~Capabilities.Ascendable;

            focusable = true;

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);

            m_TitleField           = this.Q <TextField>();
            m_TitleField.isDelayed = true;
            this.AddManipulator(new ContextualMenuManipulator(BuildContextualMenu));

            m_CollapseButton          = this.Q <Button>();
            m_CollapseButton.clicked += () => Collapsed = !Collapsed;
            m_CollapseButton.AddToClassList("placematCollapse");

            m_Resizer = this.Q <ResizableElement>();

            if (Collapsed)
            {
                m_Resizer.style.visibility = Visibility.Hidden;
                m_CollapseButton.RemoveFromClassList("icon-expanded");
            }
            else
            {
                m_Resizer.style.visibility = StyleKeyword.Null;
                m_CollapseButton.AddToClassList("icon-expanded");
            }
        }
        public Pill()
        {
            this.AddStylesheet("Pill.uss");

            var           tpl           = GraphElementsHelper.LoadUXML("Pill.uxml");
            VisualElement mainContainer = tpl.Instantiate();

            m_TitleLabel     = mainContainer.Q <Label>("title-label");
            m_Icon           = mainContainer.Q <Image>("icon");
            m_LeftContainer  = mainContainer.Q("input");
            m_RightContainer = mainContainer.Q("output");

            Add(mainContainer);

            AddToClassList("pill");

            UpdateVisibility();
            UpdateIconVisibility();
        }
        public BlackboardField(Texture icon, string text, string typeText)
        {
            var           tpl           = GraphElementsHelper.LoadUXML("BlackboardField.uxml");
            VisualElement mainContainer = tpl.Instantiate();

            this.AddStylesheet(Blackboard.StyleSheetPath);
            mainContainer.AddToClassList("mainContainer");
            mainContainer.pickingMode = PickingMode.Ignore;

            m_ContentItem = mainContainer.Q("contentItem");
            Assert.IsTrue(m_ContentItem != null);

            m_Pill = mainContainer.Q <Pill>("pill");
            Assert.IsTrue(m_Pill != null);

            m_TypeLabel = mainContainer.Q <Label>("typeLabel");
            Assert.IsTrue(m_TypeLabel != null);

            m_TextField = mainContainer.Q <TextField>("textField");
            Assert.IsTrue(m_TextField != null);

            m_TextField.style.display = DisplayStyle.None;

            var textinput = m_TextField.Q(TextField.textInputUssName);

            textinput.RegisterCallback <FocusOutEvent>(e => { OnEditTextFinished(); });

            Add(mainContainer);

            RegisterCallback <MouseDownEvent>(OnMouseDownEvent);

            capabilities |= Capabilities.Selectable | Capabilities.Droppable | Capabilities.Deletable | Capabilities.Renamable;

            ClearClassList();
            AddToClassList("blackboardField");

            this.text     = text;
            this.icon     = icon;
            this.typeText = typeText;

            this.AddManipulator(new SelectionDropper());
            this.AddManipulator(new ContextualMenuManipulator(BuildContextualMenu));
        }
Пример #10
0
        protected Port(Orientation portOrientation, Direction portDirection, Capacity portCapacity, Type type)
        {
            // currently we don't want to be styled as .graphElement since we're contained in a Node
            ClearClassList();

            var tpl = GraphElementsHelper.LoadUXML("Port.uxml");

            tpl.CloneTree(this);
            m_ConnectorBox  = this.Q(name: "connector");
            m_ConnectorText = this.Q <Label>(name: "type");

            m_ConnectorBoxCap = this.Q(name: "cap");

            m_Connections = new HashSet <Edge>();

            orientation = portOrientation;
            direction   = portDirection;
            portType    = type;
            capacity    = portCapacity;

            AddToClassList("port");
            AddToClassList(portDirection.ToString().ToLower());
            this.AddStylesheet("Port.uss");
        }
        public Blackboard(GraphView associatedGraphView = null)
        {
            var tpl = GraphElementsHelper.LoadUXML("Blackboard.uxml");

            this.AddStylesheet(StyleSheetPath);

            m_MainContainer = tpl.Instantiate();
            m_MainContainer.AddToClassList("mainContainer");

            m_Root = m_MainContainer.Q("content");

            m_HeaderItem = m_MainContainer.Q("header");
            m_HeaderItem.AddToClassList("blackboardHeader");

            m_AddButton = m_MainContainer.Q(name: "addButton") as Button;
            m_AddButton.clickable.clicked += () => {
                if (addItemRequested != null)
                {
                    addItemRequested(this);
                }
            };

            m_TitleLabel       = m_MainContainer.Q <Label>(name: "titleLabel");
            m_SubTitleLabel    = m_MainContainer.Q <Label>(name: "subTitleLabel");
            m_ContentContainer = m_MainContainer.Q(name: "contentContainer");

            hierarchy.Add(m_MainContainer);

            capabilities  |= Capabilities.Movable | Capabilities.Resizable;
            style.overflow = Overflow.Hidden;

            ClearClassList();
            AddToClassList("blackboard");

            m_Dragger = new Dragger {
                clampToParentEdges = true
            };
            this.AddManipulator(m_Dragger);

            scrollable = false;

            hierarchy.Add(new Resizer());

            RegisterCallback <DragUpdatedEvent>(e =>
            {
                e.StopPropagation();
            });

            // event interception to prevent GraphView manipulators from being triggered
            // when working with the blackboard

            // prevent Zoomer manipulator
            RegisterCallback <WheelEvent>(e =>
            {
                e.StopPropagation();
            });

            RegisterCallback <MouseDownEvent>(e =>
            {
                if (e.button == (int)MouseButton.LeftMouse)
                {
                    ClearSelection();
                }
                // prevent ContentDragger manipulator
                e.StopPropagation();
            });

            RegisterCallback <ValidateCommandEvent>(OnValidateCommand);
            RegisterCallback <ExecuteCommandEvent>(OnExecuteCommand);

            m_GraphView = associatedGraphView;
            focusable   = true;
        }
        public Node(string uiFile)
        {
            var tpl = GraphElementsHelper.LoadUXML(uiFile);

            tpl.CloneTree(this);

            VisualElement main            = this;
            VisualElement borderContainer = main.Q(name: "node-border");

            if (borderContainer != null)
            {
                borderContainer.style.overflow = Overflow.Hidden;
                mainContainer = borderContainer;
                var selection = main.Q(name: "selection-border");
                if (selection != null)
                {
                    selection.style.overflow = Overflow.Visible; //fixes issues with selection border being clipped when zooming out
                }
            }
            else
            {
                mainContainer = main;
            }

            titleContainer = main.Q(name: "title");
            inputContainer = main.Q(name: "input");

            if (inputContainer != null)
            {
                m_InputContainerParent = inputContainer.hierarchy.parent;
            }

            m_CollapsibleArea  = main.Q(name: "collapsible-area");
            extensionContainer = main.Q("extension");
            VisualElement output = main.Q(name: "output");

            outputContainer = output;

            if (outputContainer != null)
            {
                m_OutputContainerParent = outputContainer.hierarchy.parent;
                topContainer            = output.parent;
            }

            m_TitleLabel         = main.Q <Label>(name: "title-label");
            titleButtonContainer = main.Q(name: "title-button-container");
            m_CollapseButton     = main.Q(name: "collapse-button");
            m_CollapseButton.AddManipulator(new Clickable(ToggleCollapse));

            elementTypeColor = new Color(0.9f, 0.9f, 0.9f, 0.5f);

            if (main != this)
            {
                Add(main);
            }

            AddToClassList("node");

            capabilities |= Capabilities.Selectable | Capabilities.Movable | Capabilities.Deletable | Capabilities.Ascendable | Capabilities.Copiable;
            usageHints    = UsageHints.DynamicTransform;

            m_Expanded = true;
            UpdateExpandedButtonState();
            UpdateCollapsibleAreaVisibility();

            this.AddManipulator(new ContextualMenuManipulator(BuildContextualMenu));

            style.position = Position.Absolute;
        }