예제 #1
0
        public static bool PrefixLabel(string label)
        {
            var isLong = false;

            if (!string.IsNullOrEmpty(label))
            {
                var style = GUI.skin.label;
                isLong = PrefixLabelSetting.width > 0f && style.CalcSize(RGUIUtility.TempContent(label)).x > PrefixLabelSetting.width;

                if (isLong)
                {
                    GUILayout.Label(label);
                }
                else
                {
                    GUILayout.Label(label, GUILayout.Width(PrefixLabelSetting.width));
                }
            }

            return(isLong);
        }
예제 #2
0
        public static int Popup(Rect launchRect, int mouseButton, int selectionIndex, string[] displayOptions, string label = "")
        {
            var ret       = selectionIndex;
            var controlId = GUIUtility.GetControlID(FocusType.Passive);

            // not Popup Owner
            if (popupControlId != controlId)
            {
                var ev  = Event.current;
                var pos = ev.mousePosition;

                if ((ev.type == EventType.MouseUp) &&
                    ((mouseButton < 0) || (ev.button == mouseButton)) &&
                    launchRect.Contains(pos) &&
                    displayOptions != null &&
                    displayOptions.Any()
                    )
                {
                    popupWindow.pos = RGUIUtility.GetMouseScreenPos(Vector2.one * 150f);
                    popupControlId  = controlId;
                    ev.Use();
                }
            }
            // Active
            else
            {
                var type = Event.current.type;

                var result = popupWindow.result;
                if (result.HasValue && type == EventType.Layout)
                {
                    if (result.Value >= 0) // -1 when the popup is closed by clicking outside the window
                    {
                        ret = result.Value;
                    }
                    popupWindow.result = null;
                    popupControlId     = 0;
                }
                else
                {
                    if ((type == EventType.Layout) || (type == EventType.Repaint))
                    {
                        var buttonStyle = RGUIStyle.popupFlatButton;
                        var contentSize = Vector2.zero;
                        for (var i = 0; i < displayOptions.Length; ++i)
                        {
                            var textSize = buttonStyle.CalcSize(RGUIUtility.TempContent(displayOptions[i]));
                            contentSize.x  = Mathf.Max(contentSize.x, textSize.x);
                            contentSize.y += textSize.y;
                        }

                        var margin = buttonStyle.margin;
                        contentSize.y += Mathf.Max(0, displayOptions.Length - 1) * Mathf.Max(margin.top, margin.bottom); // is this right?

                        var vbarSkin   = GUI.skin.verticalScrollbar;
                        var vbarSize   = vbarSkin.CalcScreenSize(Vector2.zero);
                        var vbarMargin = vbarSkin.margin;

                        var hbarSkin   = GUI.skin.horizontalScrollbar;
                        var hbarSize   = hbarSkin.CalcScreenSize(Vector2.zero);
                        var hbarMargin = hbarSkin.margin;

                        const float offset = 5f;
                        contentSize += new Vector2(vbarSize.x + vbarMargin.horizontal, hbarSize.y + hbarMargin.vertical) + Vector2.one * offset;
                        var size    = RGUIStyle.popup.CalcScreenSize(contentSize);
                        var maxSize = new Vector2(Screen.width, Screen.height) - popupWindow.pos;

                        popupWindow.size = Vector2.Min(size, maxSize);
                    }

                    popupWindow.label          = label;
                    popupWindow.displayOptions = displayOptions;
                    WindowInvoker.Add(popupWindow);
                }
            }

            return(ret);
        }
예제 #3
0
        public static int SearchablePopup(Rect launchRect, int mouseButton, int selectionIndex, string[] displayOptions, ref string searchTerms, string label = "")
        {
            var ret       = selectionIndex;
            var controlId = GUIUtility.GetControlID(FocusType.Passive);

            // not Popup Owner
            if (s_popupControlId != controlId)
            {
                var ev  = Event.current;
                var pos = ev.mousePosition;

                if ((ev.type == EventType.MouseUp) &&
                    ((mouseButton < 0) || (ev.button == mouseButton)) &&
                    launchRect.Contains(pos) &&
                    displayOptions != null &&
                    displayOptions.Length > 0
                    )
                {
                    s_searchablePopupWindow.pos = RGUIUtility.GetMouseScreenPos(Vector2.one * 150f);
                    s_popupControlId            = controlId;
                    ev.Use();
                }
            }
            // Active
            else
            {
                var type = Event.current.type;

                var result = s_searchablePopupWindow.result;
                if (s_searchablePopupWindow._searchTerms != null)
                {
                    if (!searchTerms.Equals(s_searchablePopupWindow._searchTerms))
                    {
                        ret = -1;
                    }
                    searchTerms = s_searchablePopupWindow._searchTerms;
                }
                if (result.HasValue && type == EventType.Layout)
                {
                    if (result.Value >= 0) // -1 when the popup is closed by clicking outside the window
                    {
                        ret = result.Value;
                    }
                    s_searchablePopupWindow.result = null;
                    s_popupControlId = 0;
                }
                else
                {
                    if ((type == EventType.Layout) || (type == EventType.Repaint))
                    {
                        var buttonStyle = new GUIStyle(InterfaceMaker.CustomSkin.button)
                        {
                            padding = new RectOffset(24, 48, 2, 2)
                        };
                        var textfieldStyle = InterfaceMaker.CustomSkin.textField;
                        var contentSize    = Vector2.zero;

                        for (var i = 0; i < displayOptions.Length; ++i)
                        {
                            var textSize = buttonStyle.CalcSize(RGUIUtility.TempContent(displayOptions[i]));
                            contentSize.x  = Mathf.Max(contentSize.x, textSize.x);
                            contentSize.y += textSize.y;
                        }

                        if (displayOptions.Length == 0)
                        {
                            contentSize.x += 150;
                        }

                        var margin = buttonStyle.margin;
                        contentSize.y += Mathf.Max(0, displayOptions.Length - 1) * Mathf.Max(margin.top, margin.bottom); // is this right?

                        var vbarSkin   = InterfaceMaker.CustomSkin.verticalScrollbar;
                        var vbarSize   = vbarSkin.CalcScreenSize(Vector2.zero);
                        var vbarMargin = vbarSkin.margin;

                        var hbarSkin   = InterfaceMaker.CustomSkin.horizontalScrollbar;
                        var hbarSize   = hbarSkin.CalcScreenSize(Vector2.zero);
                        var hbarMargin = hbarSkin.margin;

                        const float offset = 5f;
                        contentSize += new Vector2(vbarSize.x + vbarMargin.horizontal, hbarSize.y + hbarMargin.vertical) + Vector2.one * offset;

                        contentSize.y += textfieldStyle.CalcHeight(RGUIUtility.TempContent("t"), contentSize.x);

                        var size    = InterfaceMaker.CustomSkin.GetStyle("popup").CalcScreenSize(contentSize);
                        var maxSize = new Vector2(Screen.width, Screen.height) - s_searchablePopupWindow.pos;

                        s_searchablePopupWindow.size = Vector2.Min(size, maxSize);
                    }

                    s_searchablePopupWindow.SetSearchTerms(searchTerms);
                    s_searchablePopupWindow.label          = label;
                    s_searchablePopupWindow.displayOptions = displayOptions;
                    WindowInvoker.Add(s_searchablePopupWindow);
                }
            }

            return(ret);
        }