Esempio n. 1
0
        /// <summary>
        /// Recursively calculate the minimum size.
        /// </summary>
        /// <param name="dp">
        /// The properties with the minium size information of leaf nodes.</param>
        /// <returns>The calculated minimum size. It also takes into account
        /// the size needed for sashes.</returns>
        private Vector2 CalculateMinsizeImpl(DockProps dp, bool cache = true)
        {
            switch (dockType)
            {
            case Type.Horizontal:
            {
                Vector2 reth = Vector2.zero;
                bool    alo  = false;     // At least once
                foreach (Dock d in this.children)
                {
                    Vector2 vd = d.CalculateMinsize(dp, cache);
                    reth.x += vd.x;
                    reth.y  = Mathf.Max(reth.y, vd.y);

                    if (alo == false)
                    {
                        alo = true;
                    }
                    else
                    {
                        reth.x += dp.sashWidth;
                    }
                }
                return(reth);
            }

            case Type.Vertical:
            {
                Vector2 retv = Vector2.zero;
                bool    alo  = false;
                foreach (Dock d in this.children)
                {
                    Vector2 vd = d.CalculateMinsize(dp, cache);
                    retv.x  = Mathf.Max(retv.x, vd.x);
                    retv.y += vd.y;

                    if (alo == false)
                    {
                        alo = true;
                    }
                    else
                    {
                        retv.y += dp.sashWidth;
                    }
                }
                return(retv);
            }

            case Type.Tab:
                return(dp.minsizeTabs);

            case Type.Window:
                return(dp.minsizeWindow);
            }

            return(Vector2.zero);
        }
Esempio n. 2
0
        public Vector2 CalculateMinsize(DockProps dp, bool cache = true)
        {
            Vector2 ret = this.CalculateMinsizeImpl(dp, cache);

            if (cache == true)
            {
                this.minSize = ret;
            }

            return(ret);
        }
Esempio n. 3
0
        /// <summary>
        /// Retrieve a cached TabAssets for a specific window in the tab system - or
        /// create and store a new one if none currently exist.
        /// </summary>
        /// <param name="tabbedWin">The window to retrive the assets for.</param>
        /// <param name="rt">The RectTransform to put parent the assets in if they're being created. </param>
        /// <param name="props">The properties used to give the assets if they're being created.</param>
        /// <returns></returns>
        public TabsAssets GetTabAssets(Dock tabbedWin, RectTransform parent, DockProps props)
        {
            TabsAssets ret;

            if (this.assetLookup.TryGetValue(tabbedWin, out ret) == true)
            {
                return(ret);
            }

            ret = new TabsAssets();

            GameObject goTab = new GameObject("Tab asset");

            goTab.transform.SetParent(parent);
            ret.notebookTab        = goTab.AddComponent <UnityEngine.UI.Image>();
            ret.notebookTab.sprite = props.tabs.tabPlate;
            ret.notebookTab.type   = UnityEngine.UI.Image.Type.Sliced;
            RectTransform rtTab = ret.notebookTab.rectTransform;

            rtTab.anchorMin = new Vector2(0.0f, 1.0f);
            rtTab.anchorMax = new Vector2(0.0f, 1.0f);
            rtTab.pivot     = new Vector2(0.0f, 1.0f);
            goTab.AddComponent <UnityEngine.UI.Mask>();

            ret.notebookButton = goTab.AddComponent <UnityEngine.UI.Button>();
            ret.notebookButton.onClick.AddListener(
                () =>
            {
                this.dock.activeTab = tabbedWin;
                this.HandleDock();
            });

            // Prevent locked windows from being ripped from the tab system. The issue here is
            // that if it's ripped, then it should turn to a floating window, which locked windows
            // can't.
            if (tabbedWin.window.Locked == false)
            {
                // If the tag is being dragged, redirect it to the window to
                // initiate a pull-off.
                UnityEngine.EventSystems.EventTrigger etTab = goTab.AddComponent <UnityEngine.EventSystems.EventTrigger>();
                etTab.triggers = new List <UnityEngine.EventSystems.EventTrigger.Entry>();
                UnityEngine.EventSystems.EventTrigger.Entry dragEnt = new UnityEngine.EventSystems.EventTrigger.Entry();
                dragEnt.eventID = UnityEngine.EventSystems.EventTriggerType.BeginDrag;
                dragEnt.callback.AddListener(
                    (x) =>
                {
                    UnityEngine.EventSystems.PointerEventData evt =
                        x as UnityEngine.EventSystems.PointerEventData;

                    // Transform the point from the tab, to the window about to be ripped.
                    Vector2 mouseInTab = goTab.transform.worldToLocalMatrix.MultiplyPoint(evt.position);
                    evt.position       = tabbedWin.window.transform.localToWorldMatrix.MultiplyPoint(mouseInTab);

                    // Make sure it's active before handoff. Will be inactive if not the main tab.
                    tabbedWin.window.gameObject.SetActive(true);

                    // Do handoff
                    evt.dragging    = true;
                    evt.pointerDrag = tabbedWin.window.gameObject;

                    // Force titlebar drag state
                    Window._StartOutsideDrag(Window.FrameDrag.Position, tabbedWin.window, Vector2.zero);

                    // Make sure it handles OnBeginDrag - certain important drag things are
                    // initialized there.
                    UnityEngine.EventSystems.IBeginDragHandler dragBegin = tabbedWin.window;
                    dragBegin.OnBeginDrag(evt);
                    // Reset styles + shadow
                    this.root.UndockWindow(tabbedWin.window);
                });
                etTab.triggers.Add(dragEnt);
            }

            if (tabbedWin.window.Closable == true &&
                tabbedWin.window.Locked == false)
            {
                GameObject goCloseBtn = new GameObject("CloseButton");
                goCloseBtn.transform.SetParent(rtTab);
                ret.closeButton        = goCloseBtn.AddComponent <UnityEngine.UI.Image>();
                ret.closeButton.sprite = props.tabs.innerTabBtn;
                ret.closeButton.type   = UnityEngine.UI.Image.Type.Sliced;
                RectTransform rtCloseBtn = ret.closeButton.rectTransform;
                rtCloseBtn.anchorMin = new Vector2(1.0f, 0.0f);
                rtCloseBtn.anchorMax = new Vector2(1.0f, 1.0f);
                rtCloseBtn.offsetMin =
                    new Vector2(
                        -this.root.props.tabs.closeBorderRight - this.root.props.tabs.closeWidth,
                        this.root.props.tabs.closeBorderVert);
                rtCloseBtn.offsetMax =
                    new Vector2(
                        -this.root.props.tabs.closeBorderRight,
                        -this.root.props.tabs.closeBorderVert);

                UnityEngine.UI.Button closeBtn = goCloseBtn.AddComponent <UnityEngine.UI.Button>();
                closeBtn.onClick.AddListener(
                    () =>
                {
                    this.root.CloseWindow(tabbedWin.window);
                });

                if (props.tabs.closeWindowIcon != null)
                {
                    GameObject goCloseIco = new GameObject("Close");
                    goCloseIco.transform.SetParent(rtCloseBtn);
                    UnityEngine.UI.Image imgCloseIco = goCloseIco.AddComponent <UnityEngine.UI.Image>();
                    RectTransform        rtClIco     = imgCloseIco.rectTransform;
                    imgCloseIco.sprite       = props.tabs.closeWindowIcon;
                    rtClIco.anchorMin        = new Vector2(0.5f, 0.5f);
                    rtClIco.anchorMax        = new Vector2(0.5f, 0.5f);
                    rtClIco.pivot            = new Vector2(0.5f, 0.5f);
                    rtClIco.anchoredPosition = Vector2.zero;
                    rtClIco.sizeDelta        = props.tabs.closeWindowIcon.rect.size;
                }
            }

            GameObject goText = new GameObject("Text");

            goText.transform.SetParent(rtTab);
            ret.label                    = goText.AddComponent <UnityEngine.UI.Text>();
            ret.label.text               = tabbedWin.window.TitlebarText;
            ret.label.color              = props.tabs.tabFontColor;
            ret.label.fontSize           = props.tabs.tabFontSize;
            ret.label.verticalOverflow   = VerticalWrapMode.Truncate;
            ret.label.horizontalOverflow = HorizontalWrapMode.Wrap;
            ret.label.alignment          = TextAnchor.MiddleCenter;
            ret.label.font               = props.tabs.tabFont;
            RectTransform rtLabel = ret.label.rectTransform;

            rtLabel.anchorMin = Vector2.zero;
            rtLabel.anchorMax = Vector2.one;
            rtLabel.offsetMin = Vector2.zero;
            rtLabel.offsetMax = new Vector2(-this.root.props.tabs.closeBorderRight - this.root.props.tabs.closeWidth, 0.0f);
            rtLabel.pivot     = new Vector2(0.5f, 0.5f);

            this.assetLookup.Add(tabbedWin, ret);
            return(ret);
        }