CheckOnGUI() static private method

static private CheckOnGUI ( ) : void
return void
Example #1
0
        private static Rect DoGetRect(GUIContent content, GUIStyle style, GUILayoutOption[] options)
        {
            GUIUtility.CheckOnGUI();
            EventType type      = Event.current.type;
            EventType eventType = type;
            Rect      rect;

            if (eventType != EventType.Layout)
            {
                if (eventType != EventType.Used)
                {
                    GUILayoutEntry next = GUILayoutUtility.current.topLevel.GetNext();
                    GUIDebugger.LogLayoutEntry(next.rect, next.marginLeft, next.marginRight, next.marginTop, next.marginBottom, next.style);
                    rect = next.rect;
                }
                else
                {
                    rect = GUILayoutUtility.kDummyRect;
                }
            }
            else
            {
                bool isHeightDependantOnWidth = style.isHeightDependantOnWidth;
                if (isHeightDependantOnWidth)
                {
                    GUILayoutUtility.current.topLevel.Add(new GUIWordWrapSizer(style, content, options));
                }
                else
                {
                    Vector2 constraints = new Vector2(0f, 0f);
                    bool    flag        = options != null;
                    if (flag)
                    {
                        for (int i = 0; i < options.Length; i++)
                        {
                            GUILayoutOption      gUILayoutOption = options[i];
                            GUILayoutOption.Type type2           = gUILayoutOption.type;
                            GUILayoutOption.Type type3           = type2;
                            if (type3 != GUILayoutOption.Type.maxWidth)
                            {
                                if (type3 == GUILayoutOption.Type.maxHeight)
                                {
                                    constraints.y = (float)gUILayoutOption.value;
                                }
                            }
                            else
                            {
                                constraints.x = (float)gUILayoutOption.value;
                            }
                        }
                    }
                    Vector2 vector = style.CalcSizeWithConstraints(content, constraints);
                    vector.x = Mathf.Ceil(vector.x);
                    vector.y = Mathf.Ceil(vector.y);
                    GUILayoutUtility.current.topLevel.Add(new GUILayoutEntry(vector.x, vector.x, vector.y, vector.y, style, options));
                }
                rect = GUILayoutUtility.kDummyRect;
            }
            return(rect);
        }
Example #2
0
        // Begin an automatically laid out scrollview.
        public static Vector2 BeginScrollView(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical, GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options)
        {
            GUIUtility.CheckOnGUI();

            GUIScrollGroup g = (GUIScrollGroup)GUILayoutUtility.BeginLayoutGroup(background, null, typeof(GUIScrollGroup));

            switch (Event.current.type)
            {
            case EventType.Layout:
                g.resetCoords              = true;
                g.isVertical               = true;
                g.stretchWidth             = 1;
                g.stretchHeight            = 1;
                g.verticalScrollbar        = verticalScrollbar;
                g.horizontalScrollbar      = horizontalScrollbar;
                g.needsVerticalScrollbar   = alwaysShowVertical;
                g.needsHorizontalScrollbar = alwaysShowHorizontal;
                g.ApplyOptions(options);
                break;

            default:
                break;
            }
            return(GUI.BeginScrollView(g.rect, scrollPosition, new Rect(0, 0, g.clientWidth, g.clientHeight), alwaysShowHorizontal, alwaysShowVertical, horizontalScrollbar, verticalScrollbar, background));
        }
Example #3
0
        // Make an auto-sized draggable window...
        static Rect DoWindow(int id, Rect screenRect, GUI.WindowFunction func, GUIContent content, GUIStyle style, GUILayoutOption[] options)
        {
            GUIUtility.CheckOnGUI();
            LayoutedWindow lw = new LayoutedWindow(func, screenRect, content, options, style);

            return(GUI.Window(id, screenRect, lw.DoWindow, content, style));
        }
Example #4
0
        public static void FlexibleSpace()
        {
            GUIUtility.CheckOnGUI();
            bool            isVertical = GUILayoutUtility.current.topLevel.isVertical;
            GUILayoutOption gUILayoutOption;

            if (isVertical)
            {
                gUILayoutOption = GUILayout.ExpandHeight(true);
            }
            else
            {
                gUILayoutOption = GUILayout.ExpandWidth(true);
            }
            gUILayoutOption.value = 10000;
            GUILayoutUtility.GetRect(0f, 0f, GUILayoutUtility.spaceStyle, new GUILayoutOption[]
            {
                gUILayoutOption
            });
            bool flag = Event.current.type == EventType.Layout;

            if (flag)
            {
                GUILayoutUtility.current.topLevel.entries[GUILayoutUtility.current.topLevel.entries.Count - 1].consideredForMargin = false;
            }
        }
Example #5
0
        public static void Space(float pixels)
        {
            GUIUtility.CheckOnGUI();
            bool isVertical = GUILayoutUtility.current.topLevel.isVertical;

            if (isVertical)
            {
                GUILayoutUtility.GetRect(0f, pixels, GUILayoutUtility.spaceStyle, new GUILayoutOption[]
                {
                    GUILayout.Height(pixels)
                });
            }
            else
            {
                GUILayoutUtility.GetRect(pixels, 0f, GUILayoutUtility.spaceStyle, new GUILayoutOption[]
                {
                    GUILayout.Width(pixels)
                });
            }
            bool flag = Event.current.type == EventType.Layout;

            if (flag)
            {
                GUILayoutUtility.current.topLevel.entries[GUILayoutUtility.current.topLevel.entries.Count - 1].consideredForMargin = false;
            }
        }
Example #6
0
 public static void EndArea()
 {
     GUIUtility.CheckOnGUI();
     if (Event.current.type != EventType.Used)
     {
         GUILayoutUtility.current.layoutGroups.Pop();
         GUILayoutUtility.current.topLevel = (GUILayoutGroup)GUILayoutUtility.current.layoutGroups.Peek();
         GUI.EndGroup();
     }
 }
Example #7
0
        private static Rect DoGetRect(GUIContent content, GUIStyle style, GUILayoutOption[] options)
        {
            GUIUtility.CheckOnGUI();
            EventType type = Event.current.type;
            Rect      rect;

            if (type != EventType.Layout)
            {
                if (type != EventType.Used)
                {
                    GUILayoutEntry next = GUILayoutUtility.current.topLevel.GetNext();
                    rect = next.rect;
                }
                else
                {
                    rect = GUILayoutUtility.kDummyRect;
                }
            }
            else
            {
                if (style.isHeightDependantOnWidth)
                {
                    GUILayoutUtility.current.topLevel.Add(new GUIWordWrapSizer(style, content, options));
                }
                else
                {
                    Vector2 constraints = new Vector2(0f, 0f);
                    if (options != null)
                    {
                        foreach (GUILayoutOption guilayoutOption in options)
                        {
                            GUILayoutOption.Type type2 = guilayoutOption.type;
                            if (type2 != GUILayoutOption.Type.maxHeight)
                            {
                                if (type2 == GUILayoutOption.Type.maxWidth)
                                {
                                    constraints.x = (float)guilayoutOption.value;
                                }
                            }
                            else
                            {
                                constraints.y = (float)guilayoutOption.value;
                            }
                        }
                    }
                    Vector2 vector = style.CalcSizeWithConstraints(content, constraints);
                    GUILayoutUtility.current.topLevel.Add(new GUILayoutEntry(vector.x, vector.x, vector.y, vector.y, style, options));
                }
                rect = GUILayoutUtility.kDummyRect;
            }
            return(rect);
        }
Example #8
0
 public static void Space(float pixels)
 {
     GUIUtility.CheckOnGUI();
     if (GUILayoutUtility.current.topLevel.isVertical)
     {
         GUILayoutOption[] options = new GUILayoutOption[] { Height(pixels) };
         GUILayoutUtility.GetRect(0f, pixels, GUILayoutUtility.spaceStyle, options);
     }
     else
     {
         GUILayoutOption[] optionArray2 = new GUILayoutOption[] { Width(pixels) };
         GUILayoutUtility.GetRect(pixels, 0f, GUILayoutUtility.spaceStyle, optionArray2);
     }
 }
Example #9
0
        public static void BeginArea(Rect screenRect, GUIContent content, GUIStyle style)
        {
            GUIUtility.CheckOnGUI();
            GUILayoutGroup gUILayoutGroup = GUILayoutUtility.BeginLayoutArea(style, typeof(GUILayoutGroup));

            if (Event.current.type == EventType.Layout)
            {
                gUILayoutGroup.resetCoords = true;
                gUILayoutGroup.minWidth    = (gUILayoutGroup.maxWidth = screenRect.width);
                gUILayoutGroup.minHeight   = (gUILayoutGroup.maxHeight = screenRect.height);
                gUILayoutGroup.rect        = Rect.MinMaxRect(screenRect.xMin, screenRect.yMin, gUILayoutGroup.rect.xMax, gUILayoutGroup.rect.yMax);
            }
            GUI.BeginGroup(gUILayoutGroup.rect, content, style);
        }
        static Rect DoGetRect(GUIContent content, GUIStyle style, GUILayoutOption[] options)
        {
            GUIUtility.CheckOnGUI();

            switch (Event.current.type)
            {
            case EventType.Layout:
                if (style.isHeightDependantOnWidth)
                {
                    current.topLevel.Add(new GUIWordWrapSizer(style, content, options));
                }
                else
                {
                    Vector2 sizeConstraints = new Vector2(0, 0);
                    if (options != null)
                    {
                        foreach (var option in options)
                        {
                            switch (option.type)
                            {
                            case GUILayoutOption.Type.maxHeight:
                                sizeConstraints.y = (float)option.value;
                                break;

                            case GUILayoutOption.Type.maxWidth:
                                sizeConstraints.x = (float)option.value;
                                break;
                            }
                        }
                    }

                    Vector2 size = style.CalcSizeWithConstraints(content, sizeConstraints);
                    // This is needed on non-integer scale ratios to avoid errors to accumulate in further layout calculations
                    size.x = Mathf.Ceil(size.x);
                    size.y = Mathf.Ceil(size.y);
                    current.topLevel.Add(new GUILayoutEntry(size.x, size.x, size.y, size.y, style, options));
                }
                return(kDummyRect);

            case EventType.Used:
                return(kDummyRect);

            default:
                var entry = current.topLevel.GetNext();
                GUIDebugger.LogLayoutEntry(entry.rect, entry.marginLeft, entry.marginRight, entry.marginTop, entry.marginBottom, entry.style);
                return(entry.rect);
            }
        }
Example #11
0
        public static void FlexibleSpace()
        {
            GUILayoutOption option;

            GUIUtility.CheckOnGUI();
            if (GUILayoutUtility.current.topLevel.isVertical)
            {
                option = ExpandHeight(true);
            }
            else
            {
                option = ExpandWidth(true);
            }
            option.value = 0x2710;
            GUILayoutOption[] options = new GUILayoutOption[] { option };
            GUILayoutUtility.GetRect(0f, 0f, GUILayoutUtility.spaceStyle, options);
        }
Example #12
0
        static Rect DoGetRect(GUIContent content, GUIStyle style, GUILayoutOption[] options)
        {
            GUIUtility.CheckOnGUI();

            switch (Event.current.type)
            {
            case EventType.Layout:
                if (style.isHeightDependantOnWidth)
                {
                    current.topLevel.Add(new GUIWordWrapSizer(style, content, options));
                }
                else
                {
                    Vector2 sizeConstraints = new Vector2(0, 0);
                    if (options != null)
                    {
                        foreach (var option in options)
                        {
                            switch (option.type)
                            {
                            case GUILayoutOption.Type.maxHeight:
                                sizeConstraints.y = (float)option.value;
                                break;

                            case GUILayoutOption.Type.maxWidth:
                                sizeConstraints.x = (float)option.value;
                                break;
                            }
                        }
                    }

                    Vector2 size = style.CalcSizeWithConstraints(content, sizeConstraints);
                    current.topLevel.Add(new GUILayoutEntry(size.x, size.x, size.y, size.y, style, options));
                }
                return(kDummyRect);

            case EventType.Used:
                return(kDummyRect);

            default:
                var entry = current.topLevel.GetNext();
                GUIDebugger.LogLayoutEntry(entry.rect, entry.margin, entry.style);
                return(entry.rect);
            }
        }
Example #13
0
        private static Rect DoGetRect(GUIContent content, GUIStyle style, GUILayoutOption[] options)
        {
            GUIUtility.CheckOnGUI();
            switch (Event.current.type)
            {
            case EventType.Layout:
                if (style.isHeightDependantOnWidth)
                {
                    current.topLevel.Add(new GUIWordWrapSizer(style, content, options));
                }
                else
                {
                    Vector2 constraints = new Vector2(0f, 0f);
                    if (options != null)
                    {
                        foreach (GUILayoutOption gUILayoutOption in options)
                        {
                            switch (gUILayoutOption.type)
                            {
                            case GUILayoutOption.Type.maxHeight:
                                constraints.y = (float)gUILayoutOption.value;
                                break;

                            case GUILayoutOption.Type.maxWidth:
                                constraints.x = (float)gUILayoutOption.value;
                                break;
                            }
                        }
                    }
                    Vector2 vector = style.CalcSizeWithConstraints(content, constraints);
                    current.topLevel.Add(new GUILayoutEntry(vector.x, vector.x, vector.y, vector.y, style, options));
                }
                return(kDummyRect);

            case EventType.Used:
                return(kDummyRect);

            default:
            {
                GUILayoutEntry next = current.topLevel.GetNext();
                return(next.rect);
            }
            }
        }
Example #14
0
        // Insert a space in the current layout group.
        static public void Space(float pixels)
        {
            GUIUtility.CheckOnGUI();
            if (GUILayoutUtility.current.topLevel.isVertical)
            {
                GUILayoutUtility.GetRect(0, pixels, GUILayoutUtility.spaceStyle, GUILayout.Height(pixels));
            }
            else
            {
                GUILayoutUtility.GetRect(pixels, 0, GUILayoutUtility.spaceStyle, GUILayout.Width(pixels));
            }
            // Instead of handling margins normally, we just want to insert the size.
            // This ensures that Space(1) adds ONE space, and doesn't prevent margin collapse.

            if (Event.current.type == EventType.Layout)
            {
                GUILayoutUtility.current.topLevel.entries[GUILayoutUtility.current.topLevel.entries.Count - 1].consideredForMargin = false;
            }
        }
Example #15
0
        public static void FlexibleSpace()
        {
            GUIUtility.CheckOnGUI();
            GUILayoutOption gUILayoutOption;

            if (GUILayoutUtility.current.topLevel.isVertical)
            {
                gUILayoutOption = GUILayout.ExpandHeight(true);
            }
            else
            {
                gUILayoutOption = GUILayout.ExpandWidth(true);
            }
            gUILayoutOption.value = 10000;
            GUILayoutUtility.GetRect(0f, 0f, GUILayoutUtility.spaceStyle, new GUILayoutOption[]
            {
                gUILayoutOption
            });
        }
Example #16
0
        private static Rect DoGetRect(GUIContent content, GUIStyle style, GUILayoutOption[] options)
        {
            GUIUtility.CheckOnGUI();
            EventType type = Event.current.type;

            if (type == EventType.Layout)
            {
                if (style.isHeightDependantOnWidth)
                {
                    GUILayoutUtility.current.topLevel.Add(new GUIWordWrapSizer(style, content, options));
                }
                else
                {
                    Vector2 constraints = new Vector2(0f, 0f);
                    if (options != null)
                    {
                        for (int i = 0; i < options.Length; i++)
                        {
                            GUILayoutOption gUILayoutOption = options[i];
                            switch (gUILayoutOption.type)
                            {
                            case GUILayoutOption.Type.maxWidth:
                                constraints.x = (float)gUILayoutOption.value;
                                break;

                            case GUILayoutOption.Type.maxHeight:
                                constraints.y = (float)gUILayoutOption.value;
                                break;
                            }
                        }
                    }
                    Vector2 vector = style.CalcSizeWithConstraints(content, constraints);
                    GUILayoutUtility.current.topLevel.Add(new GUILayoutEntry(vector.x, vector.x, vector.y, vector.y, style, options));
                }
                return(GUILayoutUtility.kDummyRect);
            }
            if (type != EventType.Used)
            {
                return(GUILayoutUtility.current.topLevel.GetNext().rect);
            }
            return(GUILayoutUtility.kDummyRect);
        }
Example #17
0
        public static Vector2 BeginScrollView(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical, GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options)
        {
            GUIUtility.CheckOnGUI();
            GUIScrollGroup gUIScrollGroup = (GUIScrollGroup)GUILayoutUtility.BeginLayoutGroup(background, null, typeof(GUIScrollGroup));
            EventType      type           = Event.current.type;

            if (type == EventType.Layout)
            {
                gUIScrollGroup.resetCoords              = true;
                gUIScrollGroup.isVertical               = true;
                gUIScrollGroup.stretchWidth             = 1;
                gUIScrollGroup.stretchHeight            = 1;
                gUIScrollGroup.verticalScrollbar        = verticalScrollbar;
                gUIScrollGroup.horizontalScrollbar      = horizontalScrollbar;
                gUIScrollGroup.needsVerticalScrollbar   = alwaysShowVertical;
                gUIScrollGroup.needsHorizontalScrollbar = alwaysShowHorizontal;
                gUIScrollGroup.ApplyOptions(options);
            }
            return(GUI.BeginScrollView(gUIScrollGroup.rect, scrollPosition, new Rect(0f, 0f, gUIScrollGroup.clientWidth, gUIScrollGroup.clientHeight), alwaysShowHorizontal, alwaysShowVertical, horizontalScrollbar, verticalScrollbar, background));
        }
Example #18
0
        // Insert a flexible space element.
        static public void FlexibleSpace()
        {
            GUIUtility.CheckOnGUI();
            GUILayoutOption op;

            if (GUILayoutUtility.current.topLevel.isVertical)
            {
                op = ExpandHeight(true);
            }
            else
            {
                op = ExpandWidth(true);
            }

            op.value = 10000;
            GUILayoutUtility.GetRect(0, 0, GUILayoutUtility.spaceStyle, op);

            if (Event.current.type == EventType.Layout)
            {
                GUILayoutUtility.current.topLevel.entries[GUILayoutUtility.current.topLevel.entries.Count - 1].consideredForMargin = false;
            }
        }
Example #19
0
        private static Rect DoGetRect(GUIContent content, GUIStyle style, GUILayoutOption[] options)
        {
            GUIUtility.CheckOnGUI();
            switch (Event.current.type)
            {
            case EventType.Layout:
                if (style.isHeightDependantOnWidth)
                {
                    current.topLevel.Add(new GUIWordWrapSizer(style, content, options));
                }
                else
                {
                    Vector2 vector = style.CalcSize(content);
                    current.topLevel.Add(new GUILayoutEntry(vector.x, vector.x, vector.y, vector.y, style, options));
                }
                return(kDummyRect);

            case EventType.Used:
                return(kDummyRect);

            default:
                return(current.topLevel.GetNext().rect);
            }
        }
Example #20
0
        private static Rect DoGetRect(GUIContent content, GUIStyle style, GUILayoutOption[] options)
        {
            GUIUtility.CheckOnGUI();
            EventType type = Event.current.type;

            if (type == EventType.Layout)
            {
                if (style.isHeightDependantOnWidth)
                {
                    GUILayoutUtility.current.topLevel.Add(new GUIWordWrapSizer(style, content, options));
                }
                else
                {
                    Vector2 vector = style.CalcSize(content);
                    GUILayoutUtility.current.topLevel.Add(new GUILayoutEntry(vector.x, vector.x, vector.y, vector.y, style, options));
                }
                return(GUILayoutUtility.kDummyRect);
            }
            if (type != EventType.Used)
            {
                return(GUILayoutUtility.current.topLevel.GetNext().rect);
            }
            return(GUILayoutUtility.kDummyRect);
        }
Example #21
0
 private static Rect DoWindow(int id, Rect screenRect, GUI.WindowFunction func, GUIContent content, GUIStyle style, GUILayoutOption[] options)
 {
     GUIUtility.CheckOnGUI();
     GUILayout.LayoutedWindow @object = new GUILayout.LayoutedWindow(func, screenRect, content, options, style);
     return(GUI.Window(id, screenRect, new GUI.WindowFunction(@object.DoWindow), content, style));
 }