Exemple #1
0
        public static DropdownWindow Create(SelectionTree selectionTree, int windowHeight, Vector2 windowPosition)
        {
            var window = CreateInstance <DropdownWindow>();

            window.OnCreate(selectionTree, windowHeight, windowPosition);
            return(window);
        }
        /// <summary>
        /// This is basically a constructor. Since ScriptableObjects cannot have constructors,
        /// this one is called from a factory method.
        /// </summary>
        /// <param name="selectionTree">Tree that contains the dropdown items to show.</param>
        /// <param name="windowHeight">Height of the window. If set to 0, it will be auto-adjusted.</param>
        /// <param name="windowPosition">Position of the window to set.</param>
        private void OnCreate(SelectionTree selectionTree, float windowHeight, Vector2 windowPosition, DropdownWindowType windowType)
        {
            ResetControl();
            wantsMouseMove = true;
            _selectionTree = selectionTree;
            _selectionTree.SelectionChanged += Close;
            _optimalWidth           = CalculateOptimalWidth(_selectionTree.SelectionPaths);
            _preventExpandingHeight = new PreventExpandingHeight(windowHeight == 0f);

            _positionOnCreation = GetWindowRect(windowPosition, windowHeight);

            if (windowType == DropdownWindowType.Dropdown)
            {
                // ShowAsDropDown usually shows the window under a button, but since we don't need to align the window to
                // any button, we set buttonRect.height to 0f.
                Rect buttonRect = new Rect(_positionOnCreation)
                {
                    height = 0f
                };
                ShowAsDropDown(buttonRect, _positionOnCreation.size);
            }
            else if (windowType == DropdownWindowType.Popup)
            {
                position = _positionOnCreation;
                ShowPopup();
            }
            else
            {
                throw new Exception("Unknown window type");
            }
        }
Exemple #3
0
 /// <summary>Constructor of a root node that does not have a parent and does not show up in the popup.</summary>
 /// <param name="parentTree">The tree this node belongs to.</param>
 private SelectionNode(SelectionTree parentTree)
 {
     ParentNode   = null;
     _parentTree  = parentTree;
     _name        = string.Empty;
     Type         = null;
     FullTypeName = null;
 }
Exemple #4
0
        public static NoneElement Create(SelectionTree parentTree)
        {
            SelectionNode root  = CreateRoot(parentTree);
            var           child = new NoneElement(root, parentTree);

            root.ChildNodes.Add(child);
            return(child);
        }
Exemple #5
0
        /// <summary>
        /// Default constructor that creates a child node of another parent node.
        /// </summary>
        /// <param name="name">Name that will show up in the popup.</param>
        /// <param name="parentNode">Parent node of this node.</param>
        /// <param name="parentTree">The tree this node belongs to.</param>
        /// <param name="type"><see cref="System.Type"/>> this node represents.</param>
        /// <param name="fullTypeName">
        /// Full name of the type. It will show up instead of the short name when performing search.
        /// </param>
        protected SelectionNode(
            string name,
            SelectionNode parentNode,
            SelectionTree parentTree,
            Type type,
            string fullTypeName)
        {
            Assert.IsNotNull(name);

            _name        = name;
            ParentNode   = parentNode;
            _parentTree  = parentTree;
            Type         = type;
            FullTypeName = fullTypeName;
        }
        /// <summary>
        /// This is basically a constructor. Since ScriptableObjects cannot have constructors,
        /// this one is called from a factory method.
        /// </summary>
        /// <param name="selectionTree">Tree that contains the dropdown items to show.</param>
        /// <param name="windowHeight">Height of the window. If set to 0, it will be auto-adjusted.</param>
        private void OnCreate(SelectionTree selectionTree, float windowHeight)
        {
            ResetControl();
            wantsMouseMove = true;
            _selectionTree = selectionTree;
            _selectionTree.SelectionChanged += Close;

            float windowWidth = CalculateOptimalWidth();

            _preventExpandingHeight = new PreventExpandingHeight(windowHeight == 0f);

            Vector2 windowPosition = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
            var     windowSize     = new Vector2(windowWidth, windowHeight);

            // ShowAsDropDown usually shows the window under a button, but since we don't need to align the window to
            // any button, we set buttonRect.height to 0f.
            var buttonRect = new Rect(windowPosition, new Vector2(windowSize.x, 0f));

            ShowAsDropDown(buttonRect, windowSize);
        }
Exemple #7
0
        /// <summary>
        /// This is basically a constructor. Since ScriptableObjects cannot have constructors,
        /// this one is called from a factory method.
        /// </summary>
        /// <param name="selectionTree">Tree that contains the dropdown items to show.</param>
        /// <param name="windowHeight">Height of the window. If set to 0, it will be auto-adjusted.</param>
        private void OnCreate(SelectionTree selectionTree, float windowHeight)
        {
            ResetControl();
            wantsMouseMove = true;
            _selectionTree = selectionTree;
            _selectionTree.SelectionChanged += Close;

            _optimalWidth = CalculateOptimalWidth();

            _preventExpandingHeight = new PreventExpandingHeight(windowHeight == 0f);

            Vector2 windowPosition = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);

            // If the window width is smaller than the distance from cursor to the right border of the window, the
            // window will not appear because the cursor is outside of the window and OnGUI will never be called.
            float distanceToRightBorder = Screen.currentResolution.width - windowPosition.x + 8f;
            var   windowSize            = new Vector2(Mathf.Max(distanceToRightBorder, _optimalWidth), windowHeight);

            // ShowAsDropDown usually shows the window under a button, but since we don't need to align the window to
            // any button, we set buttonRect.height to 0f.
            var buttonRect = new Rect(windowPosition, new Vector2(distanceToRightBorder, 0f));

            ShowAsDropDown(buttonRect, windowSize);
        }
        public static void Create(SelectionTree selectionTree, int windowHeight)
        {
            var window = CreateInstance <DropdownWindow>();

            window.OnCreate(selectionTree, windowHeight);
        }
Exemple #9
0
 private NoneElement(SelectionNode root, SelectionTree parentTree)
     : base(TypeReference.NoneElement, root, parentTree, null, null)
 {
 }
 /// <summary>Creates a root node that does not have a parent and does not show up in the popup.</summary>
 /// <param name="parentTree">The tree this node belongs to.</param>
 /// <returns>The root node.</returns>
 public static SelectionNode CreateRoot(SelectionTree parentTree) => new SelectionNode(parentTree);