예제 #1
0
        public static bool BorderedRectButton(SelectionStyleContent content, ref bool isActiveSelection, ref bool isPressed)
        {
            bool wasPressed = false;
            //var image = content.image;
            //var text = content.text;
            //var tooltip = content.tooltip;

            Color currentColor = content.background;

            GUILayout.Box(GUIContent.none, GUIStyle.none, GUILayout.Height(content.height));

            var fullRect = GUILayoutUtility.GetLastRect();

            if (fullRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    isPressed = true;
                }
                else
                {
                    if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
                    {
                        wasPressed = true;
                        isPressed  = false;
                    }
                }

                if (isPressed)
                {
                    currentColor      = content.pressed;
                    isActiveSelection = true;
                }
                else
                {
                    currentColor = content.active;
                }
            }
            else
            {
                if (isActiveSelection)
                {
                    currentColor = content.active;
                }
            }

            UtilityGUI.BorderRect(fullRect, content.borderThickness, currentColor, content.border, UtilityGUI.BorderDrawPlacement.Outside);

            return(wasPressed);
        }
예제 #2
0
        public void Draw(GUIStyle backgroundStyle)
        {
            EditorGUILayout.BeginVertical();

            EditorGUILayout.BeginHorizontal(backgroundStyle);

            EditorGUILayout.BeginVertical();

            EditorGUILayout.BeginVertical(backgroundStyle);

            scrollPosition = GUILayout.BeginScrollView(scrollPosition, backgroundStyle, GUILayout.MaxHeight(300));

            for (int i = 0; i < items.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();

                var styleContent = new SelectionStyleContent();
                styleContent.borderThickness = 2;
                styleContent.pressed         = new Color(0.6f, 0.6f, 0.6f);
                styleContent.active          = new Color(0.7f, 0.7f, 0.7f);
                styleContent.background      = Color.grey;
                styleContent.border          = Color.black;
                styleContent.height          = 20;
                styleContent.text            = items[i].name;

                if (items[i] != null)
                {
                    items[i].Draw(styleContent);
                }

                var textStyle = new GUIStyle(EditorStyles.whiteBoldLabel);
                textStyle.alignment = TextAnchor.MiddleCenter;
                textStyle.fontSize  = 12;
                GUI.Label(GUILayoutUtility.GetLastRect(), styleContent.text, textStyle);

                EditorGUILayout.EndHorizontal();
            }

            GUILayout.EndScrollView();

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
        }
예제 #3
0
        public void Draw(SelectionStyleContent content)
        {
            var activeSelection = isActiveSelection;

            UtilityGUILayout.BorderedRectButton(content, ref isActiveSelection, ref isPressed);
            if (!activeSelection)
            {
                if (isActiveSelection)
                {
                    activeSelection = true;
                }
            }

            if (activeSelection && onSelected != null)
            {
                onSelected((TType)@object);
            }
        }
예제 #4
0
        /// <summary>
        /// Draws a bordered rect that can be hovered and pressed as a button.
        /// </summary>
        /// <param name="isPressed"></param>
        /// <param name="fullRect"></param>
        /// <param name="borderThickness"></param>
        /// <param name="background"></param>
        /// <param name="border"></param>
        /// <param name="highlight"></param>
        /// <param name="pressed"></param>
        /// <returns></returns>
        public static bool BorderedRectButton(ref bool isPressed, Rect fullRect, SelectionStyleContent content)
        {
            bool wasPressed = false;

            if (Event.current.type == EventType.MouseDown)
            {
                if (Event.current.button == 0)
                {
                    isPressed = true;
                }
            }
            else
            {
                if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
                {
                    isPressed  = false;
                    wasPressed = true;
                }
            }

            if (fullRect.Contains(Event.current.mousePosition))
            {
                if (isPressed)
                {
                    BorderRect(fullRect, content.borderThickness, content.pressed, content.border, BorderDrawPlacement.Outside);
                }
                else
                {
                    BorderRect(fullRect, content.borderThickness, content.active, content.border, BorderDrawPlacement.Outside);
                }
            }
            else
            {
                BorderRect(fullRect, content.borderThickness, content.background, content.border, BorderDrawPlacement.Outside);
            }

            return(wasPressed);
        }