示例#1
0
 public static T OnGUI <T>(T t, GUIStyle buttonStyle, GUI.ToolbarButtonSize buttonSize) where T : Enum
 {
     using (new EditorGUILayout.HorizontalScope())
     {
         GUILayout.FlexibleSpace();
         // タブを描画する
         var value = GUILayout.Toolbar((int)(object)t, TabCache <T> .TabToggles, buttonStyle, buttonSize);
         GUILayout.FlexibleSpace();
         return((T)(object)value);
     }
 }
示例#2
0
 public static IRectGUI Toolbar(this IRectGUI self, Rect position, ref int selected, GUIContent[] contents, GUIStyle style, GUI.ToolbarButtonSize buttonSize)
 {
     selected = GUI.Toolbar(position, selected, contents, style, buttonSize); return(self);
 }
 public static ILayoutGUIDrawer Toolbar(this ILayoutGUIDrawer self, ref int selected, GUIContent[] contents, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
 {
     selected = GUILayout.Toolbar(selected, contents, style, buttonSize, options); return(self);
 }
示例#4
0
        public static int Toolbar(int selected, GUIContent[] contents, bool[] enabled, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
        {
            GUIStyle firstStyle, midStyle, lastStyle;

            GUI.FindStyles(ref style, out firstStyle, out midStyle, out lastStyle, "left", "mid", "right");

            Vector2  size         = new Vector2();
            int      count        = contents.Length;
            GUIStyle currentStyle = count > 1 ? firstStyle : style;
            GUIStyle nextStyle    = count > 1 ? midStyle : style;
            GUIStyle endStyle     = count > 1 ? lastStyle : style;
            float    margins      = 0;

            for (int i = 0; i < contents.Length; i++)
            {
                if (i == count - 2)
                {
                    nextStyle = endStyle;
                }

                Vector2 thisSize = currentStyle.CalcSize(contents[i]);
                switch (buttonSize)
                {
                case GUI.ToolbarButtonSize.Fixed:
                    if (thisSize.x > size.x)
                    {
                        size.x = thisSize.x;
                    }
                    break;

                case GUI.ToolbarButtonSize.FitToContents:
                    size.x += thisSize.x;
                    break;
                }

                if (thisSize.y > size.y)
                {
                    size.y = thisSize.y;
                }

                // add spacing
                if (i == count - 1)
                {
                    margins += currentStyle.margin.right;
                }
                else
                {
                    margins += Mathf.Max(currentStyle.margin.right, nextStyle.margin.left);
                }

                currentStyle = nextStyle;
            }

            switch (buttonSize)
            {
            case GUI.ToolbarButtonSize.Fixed:
                size.x = size.x * contents.Length + margins;
                break;

            case GUI.ToolbarButtonSize.FitToContents:
                size.x += margins;
                break;
            }

            return(GUI.Toolbar(GUILayoutUtility.GetRect(size.x, size.y, style, options), selected, contents, null, style, buttonSize, enabled));
        }
示例#5
0
 public static int Toolbar(int selected, GUIContent[] contents, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
 {
     return(Toolbar(selected, contents, null, style, buttonSize, options));
 }
示例#6
0
 public static int Toolbar(int selected, Texture[] images, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
 {
     return(Toolbar(selected, GUIContent.Temp(images), style, buttonSize, options));
 }
示例#7
0
 public static int Toolbar(int selected, string[] texts, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
 {
     return(Toolbar(selected, GUIContent.Temp(texts), style, buttonSize, options));
 }
示例#8
0
        public static int Toolbar(string toolbarId, Object targetId, string[] titles, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
        {
            string key = "DustEngine.DustGUI.Toolbar." + toolbarId;

            if (targetId != null)
            {
                key += "." + targetId.GetInstanceID();
            }

            int selectedTab = SessionState.GetInt(key, 0);

            selectedTab = GUILayout.Toolbar(selectedTab, titles);
            SessionState.SetInt(key, selectedTab);

            return(selectedTab);
        }
示例#9
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        public static int Toolbar(string toolbarId, string[] titles, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
        => Toolbar(toolbarId, null, titles, style, buttonSize, options);
示例#10
0
 public static int Toolbar(int selectedTab, string[] titles, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
 {
     return(GUILayout.Toolbar(selectedTab, titles));
 }
示例#11
0
 public static ILayoutGUI Toolbar(this ILayoutGUI self, ref int selected, Texture[] images, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
 {
     selected = GUILayout.Toolbar(selected, images, style, buttonSize, options); return(self);
 }
示例#12
0
        public static int Toolbar(int selected, GUIContent[] contents, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
        {
            GUIStyle gUIStyle;
            GUIStyle gUIStyle2;
            GUIStyle gUIStyle3;

            GUI.FindStyles(ref style, out gUIStyle, out gUIStyle2, out gUIStyle3, "left", "mid", "right");
            Vector2  vector    = default(Vector2);
            int      num       = contents.Length;
            GUIStyle gUIStyle4 = (num <= 1) ? style : gUIStyle;
            GUIStyle gUIStyle5 = (num <= 1) ? style : gUIStyle2;
            GUIStyle gUIStyle6 = (num <= 1) ? style : gUIStyle3;
            float    num2      = 0f;

            for (int i = 0; i < contents.Length; i++)
            {
                if (i == num - 2)
                {
                    gUIStyle5 = gUIStyle6;
                }
                Vector2 vector2 = gUIStyle4.CalcSize(contents[i]);
                if (buttonSize != GUI.ToolbarButtonSize.Fixed)
                {
                    if (buttonSize == GUI.ToolbarButtonSize.FitToContents)
                    {
                        vector.x += vector2.x;
                    }
                }
                else if (vector2.x > vector.x)
                {
                    vector.x = vector2.x;
                }
                if (vector2.y > vector.y)
                {
                    vector.y = vector2.y;
                }
                if (i == num - 1)
                {
                    num2 += (float)gUIStyle4.margin.right;
                }
                else
                {
                    num2 += (float)Mathf.Max(gUIStyle4.margin.right, gUIStyle5.margin.left);
                }
                gUIStyle4 = gUIStyle5;
            }
            if (buttonSize != GUI.ToolbarButtonSize.Fixed)
            {
                if (buttonSize == GUI.ToolbarButtonSize.FitToContents)
                {
                    vector.x += num2;
                }
            }
            else
            {
                vector.x = vector.x * (float)contents.Length + num2;
            }
            return(GUI.Toolbar(GUILayoutUtility.GetRect(vector.x, vector.y, style, options), selected, contents, style, buttonSize));
        }
示例#13
0
        // Helper function: Get all mouse rects
        private static Rect[] CalcMouseRects(Rect position, GUIContent[] contents, int xCount, float elemWidth, float elemHeight, GUIStyle style, GUIStyle firstStyle, GUIStyle midStyle, GUIStyle lastStyle, bool addBorders, GUI.ToolbarButtonSize buttonSize)
        {
            int      count = contents.Length;
            int      x = 0;
            float    xPos = position.xMin, yPos = position.yMin;
            GUIStyle currentStyle = style;

            Rect[] retval = new Rect[count];
            if (count > 1)
            {
                currentStyle = firstStyle;
            }
            for (int i = 0; i < count; i++)
            {
                float w = 0;
                switch (buttonSize)
                {
                case GUI.ToolbarButtonSize.Fixed:
                    w = elemWidth;
                    break;

                case GUI.ToolbarButtonSize.FitToContents:
                    w = currentStyle.CalcSize(contents[i]).x;
                    break;
                }

                if (!addBorders)
                {
                    retval[i] = new Rect(xPos, yPos, w, elemHeight);
                }
                else
                {
                    retval[i] = currentStyle.margin.Add(new Rect(xPos, yPos, w, elemHeight));
                }

                //we round the values to the dpi-aware pixel grid
                retval[i] = GUIUtility.AlignRectToDevice(retval[i]);

                GUIStyle nextStyle = midStyle;
                if (i == count - 2 || i == xCount - 2)
                {
                    nextStyle = lastStyle;
                }

                xPos = retval[i].xMax + Mathf.Max(currentStyle.margin.right, nextStyle.margin.left);

                x++;
                if (x >= xCount)
                {
                    x         = 0;
                    yPos     += elemHeight + Mathf.Max(style.margin.top, style.margin.bottom);
                    xPos      = position.xMin;
                    nextStyle = firstStyle;
                }

                currentStyle = nextStyle;
            }
            return(retval);
        }
示例#14
0
        // Make a button grid
        private static int DoButtonGrid(Rect position, int selected, GUIContent[] contents, string[] controlNames, int xCount, GUIStyle style, GUIStyle firstStyle, GUIStyle midStyle, GUIStyle lastStyle, GUI.ToolbarButtonSize buttonSize, bool[] contentsEnabled = null)
        {
            int count = contents.Length;

            if (count == 0)
            {
                return(selected);
            }
            if (xCount <= 0)
            {
                Debug.LogWarning("You are trying to create a SelectionGrid with zero or less elements to be displayed in the horizontal direction. Set xCount to a positive value.");
                return(selected);
            }

            if (contentsEnabled != null && contentsEnabled.Length != count)
            {
                throw new ArgumentException("contentsEnabled");
            }

            // Figure out how large each element should be
            int rows = count / xCount;

            if (count % xCount != 0)
            {
                rows++;
            }

            float totalHorizSpacing    = CalcTotalHorizSpacing(xCount, style, firstStyle, midStyle, lastStyle);
            float totalVerticalSpacing = Mathf.Max(style.margin.top, style.margin.bottom) * (rows - 1);
            float elemWidth            = (position.width - totalHorizSpacing) / xCount;
            float elemHeight           = (position.height - totalVerticalSpacing) / rows;

            if (style.fixedWidth != 0)
            {
                elemWidth = style.fixedWidth;
            }
            if (style.fixedHeight != 0)
            {
                elemHeight = style.fixedHeight;
            }

            Rect[]   buttonRects         = CalcMouseRects(position, contents, xCount, elemWidth, elemHeight, style, firstStyle, midStyle, lastStyle, false, buttonSize);
            GUIStyle selectedButtonStyle = null;
            int      selectedButtonID    = 0;

            for (int buttonIndex = 0; buttonIndex < count; ++buttonIndex)
            {
                bool wasEnabled = GUI.enabled;
                GUI.enabled &= (contentsEnabled == null || contentsEnabled[buttonIndex]);
                var buttonRect = buttonRects[buttonIndex];
                var content    = contents[buttonIndex];

                if (controlNames != null)
                {
                    GUI.SetNextControlName(controlNames[buttonIndex]);
                }
                var id = GUIUtility.GetControlID("ButtonGrid".GetHashCode(), FocusType.Passive, buttonRect);
                if (buttonIndex == selected)
                {
                    selectedButtonID = id;
                }

                switch (Event.current.GetTypeForControl(id))
                {
                case EventType.MouseDown:
                    if (buttonRect.Contains(Event.current.mousePosition))
                    {
                        GUIUtility.hotControl = id;
                        Event.current.Use();
                    }
                    break;

                case EventType.MouseDrag:
                    if (GUIUtility.hotControl == id)
                    {
                        Event.current.Use();
                    }
                    break;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == id)
                    {
                        GUIUtility.hotControl = 0;
                        Event.current.Use();

                        GUI.changed = true;
                        return(buttonIndex);
                    }
                    break;

                case EventType.Repaint:
                    var buttonStyle = count == 1 ? style : (buttonIndex == 0 ? firstStyle : (buttonIndex == count - 1 ? lastStyle : midStyle));
                    var isSelected  = selected == buttonIndex;

                    if (!isSelected)
                    {
                        GUI.DrawTexture(buttonRect, content.image, ScaleMode.ScaleToFit, true);
                        GUI.Label(new Rect(buttonRect.x, buttonRect.y, 32, 32), buttonIndex.ToString());
                    }
                    else
                    {
                        selectedButtonStyle = buttonStyle;
                    }
                    break;
                }

                GUI.enabled = wasEnabled;
            }

            // draw selected button at the end so it overflows nicer
            if (selectedButtonStyle != null)
            {
                var buttonRect = buttonRects[selected];
                var content    = contents[selected];
                var wasEnabled = GUI.enabled;
                GUI.enabled &= (contentsEnabled == null || contentsEnabled[selected]);

                GUI.DrawTexture(new Rect(buttonRect.x + 4, buttonRect.y + 4, buttonRect.width - 8, buttonRect.height - 8), content.image, ScaleMode.ScaleToFit, true);
                DrawRectangleOutline(buttonRect, GUI.skin.settings.selectionColor);
                GUI.Label(new Rect(buttonRect.x, buttonRect.y, 32, 32), selected.ToString());
                GUI.enabled = wasEnabled;
            }

            return(selected);
        }
示例#15
0
 public static int Toolbar(int selected, GUIContent[] contents, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params /* 0x00000001800D4E50-0x00000001800D4E60 */ GUILayoutOption[] options) => default;                 // 0x0000000180A25C60-0x0000000180A25C90
 public static int Toolbar(int selected, GUIContent[] contents, bool[] enabled, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params /* 0x00000001800D4E50-0x00000001800D4E60 */ GUILayoutOption[] options) => default; // 0x0000000180A257F0-0x0000000180A25C60