private void SectionGUI(float anim, BaseGroupElement parent, BaseGroupElement grandParent)
        {
            anim = Mathf.Floor(anim) + Mathf.SmoothStep(0f, 1f, Mathf.Repeat(anim, 1f));
            Rect rectArea = position;

            rectArea.x       = position.width * (1f - anim) + 1f;
            rectArea.y       = config.UseSearch ? 30f : 0;
            rectArea.height -= config.UseSearch ? 30f : 0;
            rectArea.width  -= 2f;
            GUILayout.BeginArea(rectArea);
            {
                var rectHeader = GUILayoutUtility.GetRect(10f, 25f);
                var nameHeader = parent.Title;
                GUI.Label(rectHeader, nameHeader, Styles.Header);
                if (grandParent != null)
                {
                    var evt = Event.current;
                    var rectHeaderBackArrow = new Rect(rectHeader.x + 4f, rectHeader.y + 7f, 13f, 13f);
                    if (evt.type == EventType.Repaint)
                    {
                        Styles.LeftArrow.Draw(rectHeaderBackArrow, false, false, false, false);
                    }
                    if (evt.type == EventType.MouseDown && rectHeader.Contains(Event.current.mousePosition))
                    {
                        GoToParent();
                        evt.Use();
                    }
                }

                ListGUI(new Rect(0, 0, rectArea.width, rectArea.height), parent);
            }
            GUILayout.EndArea();
        }
Example #2
0
 public void Goto(BaseGroupElement groupElement, bool clearOldContext)
 {
     if (window)
     {
         window.SetContext(groupElement, clearOldContext);
     }
 }
        private void CalcSizeRecursion(BaseGroupElement groupElement,
                                       ref float width,
                                       ref float height)
        {
            float sum = 0f;

            for (int i = 0; i < groupElement.Children.Count; i++)
            {
                var child = groupElement.Children[i];
                if (child.IsVisible)
                {
                    sum += child.GetHeight();

                    var w = child.GetWidth();
                    if (width < w)
                    {
                        width = w;
                    }
                }
            }
            if (height < sum)
            {
                height = sum;
            }
            for (int i = 0; i < groupElement.Children.Count; i++)
            {
                var child = groupElement.Children[i] as BaseGroupElement;
                if (child != null && child.IsVisible)
                {
                    CalcSizeRecursion(child, ref width, ref height);
                }
            }
        }
        public override void Draw(Rect rect, Popup popup, BaseGroupElement parent, int index)
        {
            if (Event.current.type == EventType.Repaint)
            {
                var isSelected = parent.SelectedIndex == index;

                s_Content.text  = Title;
                s_Content.image = Icon;
                Styles.GroupItem.Draw(rect, s_Content, false, false, isSelected, isSelected);

                var rectElementForwardArrow = new Rect(rect.xMax - 13f, rect.center.y - 7f, 13f, 13f);
                Styles.RightArrow.Draw(rectElementForwardArrow, false, false, false, false);
            }
        }
Example #5
0
        public override void Draw(Rect rect, Popup popup, BaseGroupElement parent, int index)
        {
            if (Event.current.type == EventType.Repaint)
            {
                var isSelected = parent.SelectedIndex == index;
                s_Content.text  = Title;
                s_Content.image = Icon;


                Styles.CallItem.normal.textColor   = IsEnabled ? new Color(0, 0, 0) : new Color(0.41f, 0.41f, 0.41f);
                Styles.CallItem.onNormal.textColor = IsEnabled ? new Color(1, 1, 1) : new Color(0.8f, 0.8f, 0.8f);

                Styles.CallItem.Draw(rect, s_Content, false, false, isSelected, isSelected && IsEnabled);
            }
        }
Example #6
0
        public BaseGroupElement GetOrCreateGroup(string path)
        {
            if (path == "")
            {
                return(Root);
            }

            s_Separators[0] = config.Separator;
            var parts = path.Split(s_Separators, StringSplitOptions.None);
            BaseGroupElement groupElement = Root;

            string currentPath = "";

            for (int i = 0; i < parts.Length; i++)
            {
                var title = parts[i];
                currentPath += title;

                groupElement.OnBeforeContentNeeded(this);
                bool any = false;
                for (int j = 0; j < groupElement.Children.Count; j++)
                {
                    var child = groupElement.Children[j];
                    if (child.Title == title && child is BaseGroupElement)
                    {
                        groupElement = (BaseGroupElement)child;
                        any          = true;
                        break;
                    }
                }

                if (!any)
                {
                    var g = new GroupElement(title, null);
                    groupElement.Children.Add(g);
                    groupElement = g;
                }

                currentPath += config.Separator;
            }

            return(groupElement);
        }
        public void SetContext(BaseGroupElement groupElement, bool clearOldContext)
        {
            if (mPopup.Search == groupElement)
            {
                mContexts.Clear();
                mContexts.Add(groupElement);
                return;
            }

            if (HasSearch)
            {
                mSearchText = "";

                //exit from search
                var lastContext = mContexts[mContexts.Count - 1];
                if (lastContext == mPopup.Search)
                {
                    mContexts.Clear();
                    mContexts.Add(mPopup.Root);
                }
                mFinishLastContextOffset = 1;
                mContexts.Add(groupElement);
                return;
            }

            if (mFinishLastContextOffset == 0)
            {
                mFinishLastContextOffset = 1;
            }

            if (mCurrentLastContextOffset == 1f)
            {
                mCurrentLastContextOffset = 0f;
            }

            if (clearOldContext)
            {
                mContexts.Clear();
                mContexts.Add(mPopup.Root);
            }

            mContexts.Add(groupElement);
        }
 public abstract void Draw(Rect rect, Popup popup, BaseGroupElement parent, int index);
Example #9
0
        public bool Goto(string path)
        {
            s_Separators[0] = config.Separator;
            var parts = path.Split(s_Separators, StringSplitOptions.None);

            BaseGroupElement groupElement = Root;

            if (groupElement == null)
            {
                Debug.LogError("Not found root");
                return(false);
            }

            string currentPath = "";

            for (int i = 0; i < parts.Length - 1; i++)
            {
                var p = parts[i];
                currentPath += p;

                groupElement.OnBeforeContentNeeded(this);
                bool any = false;
                for (int j = 0; j < groupElement.Children.Count; j++)
                {
                    var child = groupElement.Children[j];
                    if (child.Title == p && child is BaseGroupElement)
                    {
                        groupElement = (BaseGroupElement)child;
                        any          = true;
                        break;
                    }
                }

                if (!any)
                {
                    Debug.LogError("Not found element in path: " + currentPath);
                    return(false);
                }

                currentPath += config.Separator;
            }

//            currentPath += parts[parts.Length - 1];

            bool             anyFound    = false;
            BaseGroupElement gotoElement = groupElement;

            for (int i = 0; i < groupElement.Children.Count; i++)
            {
                var child = groupElement.Children[i];
                if (child.Title == parts[parts.Length - 1])
                {
                    anyFound = true;
                    if (child is BaseGroupElement)
                    {
                        gotoElement = (BaseGroupElement)child;
                    }
                    else
                    {
                        gotoElement.SelectedIndex = i;
                    }
                    break;
                }
            }

            if (anyFound)
            {
                Goto(gotoElement, false);
            }

            return(anyFound);
        }
        private void ListGUI(Rect listRect, BaseGroupElement parent)
        {
            parent.Scroll = GUILayout.BeginScrollView(parent.Scroll);
            EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
            var children = parent.Children;
            var rect     = new Rect();

            for (int i = 0; i < children.Count; i++)
            {
                var element = children[i];
                if (element.IsVisible)
                {
                    var options     = new[] { GUILayout.ExpandWidth(true) };
                    var rectElement = GUILayoutUtility.GetRect(16f, element.GetHeight(), options);
                    if ((Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDown) &&
                        parent.SelectedIndex != i && rectElement.Contains(Event.current.mousePosition))
                    {
                        parent.SelectedIndex = i;
                        Repaint();
                    }

                    if (i == parent.SelectedIndex)
                    {
                        rect = rectElement;
                    }

                    if (Event.current.type == EventType.Repaint && listRect.Overlaps(rectElement))
                    {
                        element.Draw(rectElement, mPopup, parent, i);
                    }

                    if (Event.current.type == EventType.MouseDown && rectElement.Contains(Event.current.mousePosition))
                    {
                        Event.current.Use();
                        parent.SelectedIndex = i;
                        GoToChild(element, false);
                    }
                }
            }

            EditorGUIUtility.SetIconSize(Vector2.zero);
            GUILayout.EndScrollView();
            if (mScrollToSelected && Event.current.type == EventType.Repaint)
            {
                mScrollToSelected = false;
                var lastRect = GUILayoutUtility.GetLastRect();

                var parentScroll = parent.Scroll;
                if ((rect.yMax - lastRect.height) > parentScroll.y)
                {
                    parentScroll.y = rect.yMax - lastRect.height;
                    Repaint();
                }

                if (rect.y < parentScroll.y)
                {
                    parentScroll.y = rect.y;
                    Repaint();
                }
                parent.Scroll = parentScroll;
            }
        }
 public override void Draw(Rect rect, Popup popup, BaseGroupElement parent, int index)
 {
 }