/// <summary>
        /// Ends the group.
        /// </summary>
        public void EndGroup()
        {
            EditorGUILayout.EndHorizontal();
            GUIHelper.PushGUIEnabled(false);
            GUILayout.EndScrollView();
            GUIHelper.PopGUIEnabled();

            EditorGUILayout.EndVertical();

            if (this.targetPage != this.currentPage)
            {
                GUIHelper.RequestRepaint();
            }

            if (this.currentPage != null && Event.current.type == EventType.Repaint)
            {
                if (this.isAnimating && this.targetPage != null && this.targetPage != this.currentPage)
                {
                    this.t = this.t + this.time.DeltaTime * this.AnimationSpeed;
                    this.scrollPosition.x = Mathf.Lerp(this.currentPage.Rect.x, this.targetPage.Rect.x, Mathf.Min(1f, MathUtilities.Hermite01(t)));
                    this.currentHeight    = Mathf.Lerp(this.currentPage.Rect.height, this.targetPage.Rect.height, Mathf.Min(1f, MathUtilities.Hermite01(t)));

                    if (this.t >= 1f)
                    {
                        this.currentPage.IsVisible = false;
                        this.currentPage           = this.targetPage;
                        this.targetPage            = null;
                        this.scrollPosition.x      = 0f;
                        this.currentHeight         = this.currentPage.Rect.height;
                        this.t = 1f;
                    }
                }
                else
                {
                    this.t                = 0f;
                    this.isAnimating      = false;
                    this.scrollPosition.x = this.currentPage.Rect.x;
                    this.currentHeight    = this.currentPage.Rect.height;
                    if (this.targetPage != null && this.targetPage != this.currentPage && this.targetPage.IsVisible)
                    {
                        this.isAnimating      = true;
                        this.scrollPosition.x = this.targetPage.Order > this.currentPage.Order ? 0 : this.scrollPosition.x = this.OuterRect.width;
                        this.t = 0;
                    }
                }
            }

            foreach (var page in this.pages.GFValueIterator())
            {
                page.OnEndGroup();
            }
            this.time.Update();

            if (this.isAnimating == false && this.nextPage != null)
            {
                this.targetPage = this.nextPage;
                this.nextPage   = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sets the current page.
        /// </summary>
        /// <param name="page">The page to switch to.</param>
        public void SetCurrentPage(GUITabPage page)
        {
            if (!this.pages.ContainsValue(page))
            {
                throw new InvalidOperationException("Page is not part of TabGroup");
            }

            this.currentPage = page;
            this.targetPage  = null;
        }
Beispiel #3
0
 /// <summary>
 /// Goes to next page.
 /// </summary>
 public void GoToNextPage()
 {
     if (this.currentPage != null)
     {
         bool takeNext = false;
         var  ordered  = this.OrderedPages.ToList();
         for (int i = 0; i < ordered.Count; i++)
         {
             if (takeNext && ordered[i].IsActive)
             {
                 this.nextPage = ordered[i];
                 break;
             }
             if (ordered[i] == (this.nextPage ?? this.CurrentPage))
             {
                 takeNext = true;
             }
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Goes to previous page.
        /// </summary>
        public void GoToPreviousPage()
        {
            if (this.currentPage != null)
            {
                var ordered = this.OrderedPages.ToList();
                int prevIdx = -1;
                for (int i = 0; i < ordered.Count; i++)
                {
                    if (ordered[i] == (this.nextPage ?? this.CurrentPage))
                    {
                        if (prevIdx >= 0)
                        {
                            this.nextPage = ordered[prevIdx];
                        }
                        break;
                    }

                    if (ordered[i].IsActive)
                    {
                        prevIdx = i;
                    }
                }
            }
        }
Beispiel #5
0
        private void DrawToolbar()
        {
            if (Event.current.type == EventType.Layout)
            {
                this.toolbarRect        = this.OuterRect;
                this.toolbarRect.height = this.toolbarHeight;
                this.toolbarRect.x     += 1;
                this.toolbarRect.width -= 1;
            }

            //if (Event.current.OnRepaint())
            //{
            //    AllEditorGUI.DrawBorders(new Rect(GUILayoutUtility.GetLastRect()) { height = this.toolbarHeight }, 1);
            //}

            AllEditorGUI.BeginHorizontalToolbar(this.toolbarHeight);
            foreach (var page in this.OrderedPages)
            {
                if (page.IsActive)
                {
                    if (AllEditorGUI.ToolbarTab(page == (this.nextPage ?? this.CurrentPage), page.Title))
                    {
                        this.nextPage = page;
                    }
                }
            }
            AllEditorGUI.EndHorizontalToolbar();

            if (Event.current.OnRepaint())
            {
                AllEditorGUI.DrawBorders(new Rect(GUILayoutUtility.GetLastRect())
                {
                    height = this.toolbarHeight
                }, 1, 1, 0, 0);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Begins the group.
        /// </summary>
        /// <param name="drawToolbar">if set to <c>true</c> a tool-bar for changing pages is drawn.</param>
        /// <param name="style">The style.</param>
        public void BeginGroup(bool drawToolbar = true, GUIStyle style = null)
        {
            LabelWidth = EditorGUIUtility.labelWidth;

            if (Event.current.type == EventType.Layout)
            {
                this.drawToolbar = drawToolbar;
            }

            style = style ?? SirenixGUIStyles.ToggleGroupBackground;

            this.InnerContainerWidth = this.OuterRect.width - (
                style.padding.left +
                style.padding.right +
                style.margin.left +
                style.margin.right
                );

            if (this.currentPage == null && this.pages.Count > 0)
            {
                this.currentPage = this.pages.Select(x => x.Value).OrderBy(x => x.Order).First();
            }

            if (this.currentPage != null && this.pages.ContainsKey(this.currentPage.Name) == false)
            {
                if (this.pages.Count > 0)
                {
                    this.currentPage = this.OrderedPages.First();
                }
                else
                {
                    this.currentPage = null;
                }
            }

            float maxHeight = 0;

            foreach (var page in this.pages.GFValueIterator())
            {
                page.OnBeginGroup();
                maxHeight = Mathf.Max(page.Rect.height, maxHeight);
                if (Event.current.type == EventType.Layout)
                {
                    if (page.IsVisible != (page.IsVisible = page == this.targetPage || page == this.currentPage))
                    {
                        if (this.targetPage == null)
                        {
                            this.scrollPosition.x = 0f;
                            this.currentHeight    = this.currentPage.Rect.height;
                        }
                        else
                        {
                            this.scrollPosition.x = this.targetPage.Order >= this.currentPage.Order ? 0 : this.scrollPosition.x = this.OuterRect.width;
                            this.currentHeight    = this.currentPage.Rect.height;
                        }
                    }
                }
            }

            var outerRect = EditorGUILayout.BeginVertical(style, GUILayoutOptions.ExpandWidth(true).ExpandHeight(false));

            if (this.drawToolbar)
            {
                this.DrawToolbar();
            }
            if (this.InnerRect.width > 0)
            {
                if (this.options.Length == 2)
                {
                    if (this.currentPage != null)
                    {
                        this.currentHeight = this.currentPage.Rect.height;
                    }
                    this.options = GUILayoutOptions.ExpandWidth(true).ExpandHeight(false).Height(this.currentHeight);
                }
                if (this.FixedHeight)
                {
                    this.options[2] = GUILayout.Height(maxHeight);
                }
                else
                {
                    this.options[2] = GUILayout.Height(this.currentHeight);
                }
            }

            GUIHelper.PushGUIEnabled(false);
            GUILayout.BeginScrollView(this.scrollPosition, false, false, GUIStyle.none, GUIStyle.none, this.options);
            GUIHelper.PopGUIEnabled();
            var innerRect = EditorGUILayout.BeginHorizontal(GUILayoutOptions.ExpandHeight(false));

            if (Event.current.type == EventType.Repaint)
            {
                this.OuterRect = outerRect;
                this.InnerRect = innerRect;
            }
        }
Beispiel #7
0
 public Page(T @object, GUITabPage tab, string name)
 {
     this.Value = @object;
     this.Name  = name;
     this.Tab   = tab;
 }
Beispiel #8
0
 /// <summary>
 /// Goes to page.
 /// </summary>
 public void GoToPage(GUITabPage page)
 {
     this.nextPage = page;
 }