Ejemplo n.º 1
0
            public static bool Prefix(GUIContent content, GUIStyle style, Il2CppReferenceArray <GUILayoutOption> options, ref Rect __result)
            {
                GUIUtility.CheckOnGUI();
                var type = Event.current.type;

                if (type != EventType.Layout)
                {
                    if (type != EventType.Used)
                    {
                        var next = GUILayoutUtility.current.topLevel.GetNext();
                        __result = next.rect;
                    }
                    else
                    {
                        __result = GUILayoutUtility.kDummyRect;
                    }
                }
                else
                {
                    var isHeightDependantOnWidth = style.isHeightDependantOnWidth;
                    if (isHeightDependantOnWidth)
                    {
                        GUILayoutUtility.current.topLevel.Add(new GUIWordWrapSizer(style, content, options));
                    }
                    else
                    {
                        var constraints = new Vector2(0f, 0f);
                        if (options != null)
                        {
                            foreach (var guilayoutOption in options)
                            {
                                var type2 = guilayoutOption.type;
                                if (type2 != GUILayoutOption.Type.maxWidth)
                                {
                                    if (type2 == GUILayoutOption.Type.maxHeight)
                                    {
                                        constraints.y = guilayoutOption.value.Unbox <float>();
                                    }
                                }
                                else
                                {
                                    constraints.x = guilayoutOption.value.Unbox <float>();
                                }
                            }
                        }

                        var 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));
                    }

                    __result = GUILayoutUtility.kDummyRect;
                }

                return(false);
            }
Ejemplo n.º 2
0
        static Rect DoGetRect(GUIContent content, GUIStyle style, GUILayoutOption[] options)
        {
            switch (Event.current.type)
            {
            case EventType.Layout:
                if (style.isHeightDependantOnWidth)
                {
                    GUILayoutUtility.current.topLevel.Add(new GUIWordWrapSizer(style, content, options));
                }
                else
                {
                    Vector2 sizeConstraints = new Vector2(0, 0);
                    if (options != null)
                    {
                        foreach (var option in options)
                        {
                            if (float.TryParse(option.value.ToString(), out float f))
                            {
                                switch (option.type)
                                {
                                case GUILayoutOption.Type.maxHeight:
                                    sizeConstraints.y = f;
                                    break;

                                case GUILayoutOption.Type.maxWidth:
                                    sizeConstraints.x = f;
                                    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);
                    GUILayoutUtility.current.topLevel.Add(new GUILayoutEntry(size.x, size.x, size.y, size.y, style, options));
                }
                return(GUILayoutUtility.kDummyRect);

            case EventType.Used:
                return(GUILayoutUtility.kDummyRect);

            default:
                var entry = GUILayoutUtility.current.topLevel.GetNext();
                //GUIDebugger.LogLayoutEntry(entry.rect, entry.marginLeft, entry.marginRight, entry.marginTop, entry.marginBottom, entry.style);
                return(entry.rect);
            }
        }
        static Rect GetBreadcrumbLayoutRect(GUIContent content, GUIStyle style)
        {
            // the image makes the button far too big compared to non-image versions
            var image = content.image;

            content.image = null;
            var size = style.CalcSizeWithConstraints(content, Vector2.zero);

            content.image = image;
            if (image != null)
            {
                size.x += size.y; // assumes square image, constrained by height
            }
            return(GUILayoutUtility.GetRect(content, style, GUILayout.MaxWidth(size.x)));
        }