Example #1
0
        protected void SetChildrenAlongAxis(int axis, bool isVertical)
        {
            float num = base.rectTransform.rect.size[axis];

            if (isVertical ^ (axis == 1))
            {
                float num2 = num - ((axis != 0) ? ((float)base.padding.vertical) : ((float)base.padding.horizontal));
                for (int i = 0; i < base.rectChildren.Count; i++)
                {
                    RectTransform rect          = base.rectChildren[i];
                    float         minSize       = LayoutUtility.GetMinSize(rect, axis);
                    float         preferredSize = LayoutUtility.GetPreferredSize(rect, axis);
                    float         flexibleSize  = LayoutUtility.GetFlexibleSize(rect, axis);
                    if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth)
                    {
                        flexibleSize = Mathf.Max(flexibleSize, 1f);
                    }
                    float requiredSpaceWithoutPadding = Mathf.Clamp(num2, minSize, (flexibleSize <= 0f) ? preferredSize : num);
                    float startOffset = base.GetStartOffset(axis, requiredSpaceWithoutPadding);
                    base.SetChildAlongAxis(rect, axis, startOffset, requiredSpaceWithoutPadding);
                }
            }
            else
            {
                float pos = (axis != 0) ? ((float)base.padding.top) : ((float)base.padding.left);
                if ((base.GetTotalFlexibleSize(axis) == 0f) && (base.GetTotalPreferredSize(axis) < num))
                {
                    pos = base.GetStartOffset(axis, base.GetTotalPreferredSize(axis) - ((axis != 0) ? ((float)base.padding.vertical) : ((float)base.padding.horizontal)));
                }
                float t = 0f;
                if (base.GetTotalMinSize(axis) != base.GetTotalPreferredSize(axis))
                {
                    t = Mathf.Clamp01((num - base.GetTotalMinSize(axis)) / (base.GetTotalPreferredSize(axis) - base.GetTotalMinSize(axis)));
                }
                float num11 = 0f;
                if ((num > base.GetTotalPreferredSize(axis)) && (base.GetTotalFlexibleSize(axis) > 0f))
                {
                    num11 = (num - base.GetTotalPreferredSize(axis)) / base.GetTotalFlexibleSize(axis);
                }
                for (int j = 0; j < base.rectChildren.Count; j++)
                {
                    RectTransform transform2 = base.rectChildren[j];
                    float         a          = LayoutUtility.GetMinSize(transform2, axis);
                    float         b          = LayoutUtility.GetPreferredSize(transform2, axis);
                    float         num15      = LayoutUtility.GetFlexibleSize(transform2, axis);
                    if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth)
                    {
                        num15 = Mathf.Max(num15, 1f);
                    }
                    float size = Mathf.Lerp(a, b, t) + (num15 * num11);
                    base.SetChildAlongAxis(transform2, axis, pos, size);
                    pos += size + this.spacing;
                }
            }
        }
Example #2
0
        /// <summary>
        ///
        /// <para>
        /// Set the positions and sizes of the child layout elements for the given axis.
        /// </para>
        ///
        /// </summary>
        /// <param name="axis">The axis to handle. 0 is horizontal and 1 is vertical.</param><param name="isVertical">Is this group a vertical group?</param>
        protected void SetChildrenAlongAxis(int axis, bool isVertical)
        {
            float num1 = this.rectTransform.rect.size[axis];

            if (isVertical ^ axis == 1)
            {
                float num2 = num1 - (axis != 0 ? (float)this.padding.vertical : (float)this.padding.horizontal);
                for (int index = 0; index < this.rectChildren.Count; ++index)
                {
                    RectTransform rect          = this.rectChildren[index];
                    float         minSize       = LayoutUtility.GetMinSize(rect, axis);
                    float         preferredSize = LayoutUtility.GetPreferredSize(rect, axis);
                    float         a             = LayoutUtility.GetFlexibleSize(rect, axis);
                    if ((axis != 0 ? (this.childForceExpandHeight ? 1 : 0) : (this.childForceExpandWidth ? 1 : 0)) != 0)
                    {
                        a = Mathf.Max(a, 1f);
                    }
                    float num3        = Mathf.Clamp(num2, minSize, (double)a <= 0.0 ? preferredSize : num1);
                    float startOffset = this.GetStartOffset(axis, num3);
                    this.SetChildAlongAxis(rect, axis, startOffset, num3);
                }
            }
            else
            {
                float pos = axis != 0 ? (float)this.padding.top : (float)this.padding.left;
                if ((double)this.GetTotalFlexibleSize(axis) == 0.0 && (double)this.GetTotalPreferredSize(axis) < (double)num1)
                {
                    pos = this.GetStartOffset(axis, this.GetTotalPreferredSize(axis) - (axis != 0 ? (float)this.padding.vertical : (float)this.padding.horizontal));
                }
                float t = 0.0f;
                if ((double)this.GetTotalMinSize(axis) != (double)this.GetTotalPreferredSize(axis))
                {
                    t = Mathf.Clamp01((float)(((double)num1 - (double)this.GetTotalMinSize(axis)) / ((double)this.GetTotalPreferredSize(axis) - (double)this.GetTotalMinSize(axis))));
                }
                float num2 = 0.0f;
                if ((double)num1 > (double)this.GetTotalPreferredSize(axis) && (double)this.GetTotalFlexibleSize(axis) > 0.0)
                {
                    num2 = (num1 - this.GetTotalPreferredSize(axis)) / this.GetTotalFlexibleSize(axis);
                }
                for (int index = 0; index < this.rectChildren.Count; ++index)
                {
                    RectTransform rect          = this.rectChildren[index];
                    float         minSize       = LayoutUtility.GetMinSize(rect, axis);
                    float         preferredSize = LayoutUtility.GetPreferredSize(rect, axis);
                    float         a             = LayoutUtility.GetFlexibleSize(rect, axis);
                    if ((axis != 0 ? (this.childForceExpandHeight ? 1 : 0) : (this.childForceExpandWidth ? 1 : 0)) != 0)
                    {
                        a = Mathf.Max(a, 1f);
                    }
                    float size = Mathf.Lerp(minSize, preferredSize, t) + a * num2;
                    this.SetChildAlongAxis(rect, axis, pos, size);
                    pos += size + this.spacing;
                }
            }
        }
        protected void CalcAlongAxisExtended(int axis, bool isVertical)
        {
            float padding        = (float)((axis != 0) ? base.padding.vertical : base.padding.horizontal);
            float totalMin       = padding;
            float totalPreffered = padding;
            float totalFlexible  = 0f;

            bool notOrderingAxis = isVertical ^ axis == 1;

            for (int i = 0; i < base.rectChildren.Count; i++)
            {
                RectTransform rect          = base.rectChildren[i];
                float         minSize       = LayoutUtility.GetMinSize(rect, axis);
                float         preferredSize = LayoutUtility.GetPreferredSize(rect, axis);
                float         flexibleSize  = LayoutUtility.GetFlexibleSize(rect, axis);
                RectOffset    margins       = LayoutUtilityExtended.GetMargin(rect);
                float         margin        = (float)((axis != 0) ? margins.vertical : margins.horizontal);

                if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth)
                {
                    flexibleSize = Mathf.Max(flexibleSize, 1f);
                }

                if (notOrderingAxis)
                {
                    totalMin       = Mathf.Max(minSize + padding + margin, totalMin);
                    totalPreffered = Mathf.Max(preferredSize + padding + margin, totalPreffered);
                    totalFlexible  = Mathf.Max(flexibleSize, totalFlexible);
                }
                else
                {
                    totalMin       += minSize + this.spacing + margin;
                    totalPreffered += preferredSize + this.spacing + margin;
                    totalFlexible  += flexibleSize;
                }
            }

            if (!notOrderingAxis && base.rectChildren.Count > 0)
            {
                totalMin       -= this.spacing;
                totalPreffered -= this.spacing;
            }

            totalPreffered = Mathf.Max(totalMin, totalPreffered);

            base.SetLayoutInputForAxis(totalMin, totalPreffered, totalFlexible, axis);
        }
Example #4
0
        protected void CalcAlongAxis(int axis, bool isVertical)
        {
            float combinedPadding = (axis == 0 ? padding.horizontal : padding.vertical);


            float totalMin       = combinedPadding;
            float totalPreferred = combinedPadding;
            float totalFlexible  = 0;

            bool alongOtherAxis = (isVertical ^ (axis == 1));

            for (int i = 0; i < rectChildren.Count; i++)
            {
                RectTransform child     = rectChildren[i];
                float         min       = LayoutUtility.GetMinSize(child, axis);
                float         preferred = LayoutUtility.GetPreferredSize(child, axis);
                float         flexible  = LayoutUtility.GetFlexibleSize(child, axis);
                if ((axis == 0 ? childForceExpandWidth : childForceExpandHeight))
                {
                    flexible = Mathf.Max(flexible, 1);
                }

                if (alongOtherAxis)
                {
                    totalMin       = Mathf.Max(min + combinedPadding, totalMin);
                    totalPreferred = Mathf.Max(preferred + combinedPadding, totalPreferred);
                    totalFlexible  = Mathf.Max(flexible, totalFlexible);
                }
                else
                {
                    totalMin       += min + spacing;
                    totalPreferred += preferred + spacing;

                    // Increment flexible size with element's flexible size.
                    totalFlexible += flexible;
                }
            }

            if (!alongOtherAxis && rectChildren.Count > 0)
            {
                totalMin       -= spacing;
                totalPreferred -= spacing;
            }
            totalPreferred = Mathf.Max(totalMin, totalPreferred);
            SetLayoutInputForAxis(totalMin, totalPreferred, totalFlexible, axis);
        }
 private void GetChildSizes(RectTransform child, int axis, bool controlSize, bool childForceExpand, out float min, out float preferred, out float flexible)
 {
     if (!controlSize)
     {
         min       = child.sizeDelta[axis];
         preferred = min;
         flexible  = 0f;
     }
     else
     {
         min       = LayoutUtility.GetMinSize(child, axis);
         preferred = LayoutUtility.GetPreferredSize(child, axis);
         flexible  = LayoutUtility.GetFlexibleSize(child, axis);
     }
     if (childForceExpand)
     {
         flexible = Mathf.Max(flexible, 1f);
     }
 }
Example #6
0
        /// <summary>
        ///
        /// <para>
        /// Calculate the layout element properties for this layout element along the given axis.
        /// </para>
        ///
        /// </summary>
        /// <param name="axis">The axis to calculate for. 0 is horizontal and 1 is vertical.</param><param name="isVertical">Is this group a vertical group?</param>
        protected void CalcAlongAxis(int axis, bool isVertical)
        {
            float num1 = axis != 0 ? (float)this.padding.vertical : (float)this.padding.horizontal;
            float num2 = num1;
            float b    = num1;
            float num3 = 0.0f;
            bool  flag = isVertical ^ axis == 1;

            for (int index = 0; index < this.rectChildren.Count; ++index)
            {
                RectTransform rect          = this.rectChildren[index];
                float         minSize       = LayoutUtility.GetMinSize(rect, axis);
                float         preferredSize = LayoutUtility.GetPreferredSize(rect, axis);
                float         a             = LayoutUtility.GetFlexibleSize(rect, axis);
                if ((axis != 0 ? (this.childForceExpandHeight ? 1 : 0) : (this.childForceExpandWidth ? 1 : 0)) != 0)
                {
                    a = Mathf.Max(a, 1f);
                }
                if (flag)
                {
                    num2 = Mathf.Max(minSize + num1, num2);
                    b    = Mathf.Max(preferredSize + num1, b);
                    num3 = Mathf.Max(a, num3);
                }
                else
                {
                    num2 += minSize + this.spacing;
                    b    += preferredSize + this.spacing;
                    num3 += a;
                }
            }
            if (!flag && this.rectChildren.Count > 0)
            {
                num2 -= this.spacing;
                b    -= this.spacing;
            }
            float totalPreferred = Mathf.Max(num2, b);

            this.SetLayoutInputForAxis(num2, totalPreferred, num3, axis);
        }
Example #7
0
        protected void CalcAlongAxis(int axis, bool isVertical)
        {
            float num  = (axis != 0) ? ((float)base.padding.vertical) : ((float)base.padding.horizontal);
            float b    = num;
            float num3 = num;
            float num4 = 0f;
            bool  flag = isVertical ^ (axis == 1);

            for (int i = 0; i < base.rectChildren.Count; i++)
            {
                RectTransform rect          = base.rectChildren[i];
                float         minSize       = LayoutUtility.GetMinSize(rect, axis);
                float         preferredSize = LayoutUtility.GetPreferredSize(rect, axis);
                float         flexibleSize  = LayoutUtility.GetFlexibleSize(rect, axis);
                if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth)
                {
                    flexibleSize = Mathf.Max(flexibleSize, 1f);
                }
                if (flag)
                {
                    b    = Mathf.Max(minSize + num, b);
                    num3 = Mathf.Max(preferredSize + num, num3);
                    num4 = Mathf.Max(flexibleSize, num4);
                }
                else
                {
                    b    += minSize + this.spacing;
                    num3 += preferredSize + this.spacing;
                    num4 += flexibleSize;
                }
            }
            if (!flag && (base.rectChildren.Count > 0))
            {
                b    -= this.spacing;
                num3 -= this.spacing;
            }
            num3 = Mathf.Max(b, num3);
            base.SetLayoutInputForAxis(b, num3, num4, axis);
        }
        protected void SetChildrenAlongAxisExtended(int axis, bool isVertical)
        {
            float axisSize        = base.rectTransform.rect.size[axis];
            bool  notOrderingAxis = isVertical ^ axis == 1;

            if (notOrderingAxis)
            {
                float axisSize2 = axisSize - (float)((axis != 0) ? base.padding.vertical : base.padding.horizontal);

                for (int i = 0; i < base.rectChildren.Count; i++)
                {
                    RectTransform rect          = base.rectChildren[i];
                    float         minSize       = LayoutUtility.GetMinSize(rect, axis);
                    float         preferredSize = LayoutUtility.GetPreferredSize(rect, axis);
                    float         flexibleSize  = LayoutUtility.GetFlexibleSize(rect, axis);
                    RectOffset    margin        = LayoutUtilityExtended.GetMargin(rect);

                    if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth)
                    {
                        flexibleSize = Mathf.Max(flexibleSize, 1f);
                    }

                    float elementSize = Mathf.Clamp(axisSize2, minSize, (flexibleSize <= 0f) ? preferredSize : axisSize);

                    // Subtract margins
                    if (axis == 0 && this.m_SubtractMarginHorizontal)
                    {
                        elementSize -= margin.horizontal;
                        elementSize  = Mathf.Clamp(elementSize, minSize, elementSize);
                    }
                    else if (axis != 0 && this.m_SubtractMarginVertical)
                    {
                        elementSize -= margin.vertical;
                        elementSize  = Mathf.Clamp(elementSize, minSize, elementSize);
                    }

                    float startOffset = ((axis != 0) ? margin.top : margin.left) + base.GetStartOffset(axis, elementSize);

                    base.SetChildAlongAxis(rect, axis, startOffset, elementSize);
                }
            }
            else
            {
                float offset = (float)((axis != 0) ? base.padding.top : base.padding.left);

                if (base.GetTotalFlexibleSize(axis) == 0f && base.GetTotalPreferredSize(axis) < axisSize)
                {
                    offset = base.GetStartOffset(axis, base.GetTotalPreferredSize(axis) - (float)((axis != 0) ? base.padding.vertical : base.padding.horizontal));
                }

                float axisSize6 = 0f;

                if (base.GetTotalMinSize(axis) != base.GetTotalPreferredSize(axis))
                {
                    axisSize6 = Mathf.Clamp01((axisSize - base.GetTotalMinSize(axis)) / (base.GetTotalPreferredSize(axis) - base.GetTotalMinSize(axis)));
                }

                float axisSize7 = 0f;

                if (axisSize > base.GetTotalPreferredSize(axis) && base.GetTotalFlexibleSize(axis) > 0f)
                {
                    axisSize7 = (axisSize - base.GetTotalPreferredSize(axis)) / base.GetTotalFlexibleSize(axis);
                }

                for (int j = 0; j < base.rectChildren.Count; j++)
                {
                    RectTransform rect2          = base.rectChildren[j];
                    float         minSize2       = LayoutUtility.GetMinSize(rect2, axis);
                    float         preferredSize2 = LayoutUtility.GetPreferredSize(rect2, axis);
                    float         flexibleSize   = LayoutUtility.GetFlexibleSize(rect2, axis);
                    RectOffset    margin         = LayoutUtilityExtended.GetMargin(rect2);

                    if ((axis != 0) ? this.childForceExpandHeight : this.childForceExpandWidth)
                    {
                        flexibleSize = Mathf.Max(flexibleSize, 1f);
                    }

                    float elementSize = Mathf.Lerp(minSize2, preferredSize2, axisSize6);
                    elementSize += flexibleSize * axisSize7;

                    offset += ((axis != 0) ? margin.top : margin.left);
                    base.SetChildAlongAxis(rect2, axis, offset, elementSize);

                    offset += elementSize + this.spacing + ((axis != 0) ? margin.bottom : margin.right);
                }
            }
        }
Example #9
0
        protected void SetChildrenAlongAxis(int axis, bool isVertical)
        {
            RectTransform rect = gameObject.GetComponent <RectTransform>();

            rect.anchoredPosition = Vector2.zero;

            bool isForceExpand = (isVertical ? childForceExpandHeight : childForceExpandWidth);

            if (isForceExpand)
            {
                rect.anchorMin = Vector2.zero;
                rect.anchorMax = Vector2.one;
                rect.pivot     = new Vector2(0.5f, 0.5f);
                rect.sizeDelta = Vector2.zero;
            }

            float size = rectTransform.rect.size[axis];

            bool  alongOtherAxis = (isVertical ^ (axis == 1));
            float wh             = (axis == 0 ? padding.horizontal : padding.vertical);

            float itemwh;

            if (alongOtherAxis)
            {
                float innerSize = size - (axis == 0 ? padding.horizontal : padding.vertical);
                itemwh = (axis == 1 ? itemWidth : itemHeight);
                float itemsize = (axis == 0 ? itemWidth : itemHeight);
                for (int i = 0; i < rectChildren.Count; i++)
                {
                    RectTransform child         = rectChildren[i];
                    float         requiredSpace = 0;

                    float min       = LayoutUtility.GetMinSize(child, axis);
                    float preferred = LayoutUtility.GetPreferredSize(child, axis);
                    float flexible  = LayoutUtility.GetFlexibleSize(child, axis);

                    if ((axis == 0 ? childForceExpandWidth : childForceExpandHeight))
                    {
                        flexible = Mathf.Max(flexible, 1);
                    }

                    requiredSpace = Mathf.Clamp(innerSize, min, flexible > 0 ? size : preferred);
                    wh           += itemwh + spacing;

                    float startOffset = GetStartOffset(axis, requiredSpace);
                    if ((axis == 1 ? childForceExpandHeight : childForceExpandWidth))
                    {
                        SetChildAlongAxis(child, axis, startOffset, innerSize);
                    }
                    else
                    {
                        SetChildAlongAxis(child, axis, startOffset, itemsize);
                    }
                }
            }
            else
            {
                itemwh = (axis == 0 ? itemWidth : itemHeight);

                float pos = (axis == 0 ? padding.left : padding.top);
                if (GetTotalFlexibleSize(axis) == 0 && GetTotalPreferredSize(axis) < size)
                {
                    pos = GetStartOffset(axis, GetTotalPreferredSize(axis) - (axis == 0 ? padding.horizontal : padding.vertical));
                }

                float minMaxLerp = 0;
                if (GetTotalMinSize(axis) != GetTotalPreferredSize(axis))
                {
                    minMaxLerp = Mathf.Clamp01((size - GetTotalMinSize(axis)) / (GetTotalPreferredSize(axis) - GetTotalMinSize(axis)));
                }

                float itemFlexibleMultiplier = 0;
                if (size > GetTotalPreferredSize(axis))
                {
                    if (GetTotalFlexibleSize(axis) > 0)
                    {
                        itemFlexibleMultiplier = (size - GetTotalPreferredSize(axis)) / GetTotalFlexibleSize(axis);
                    }
                }

                for (int i = 0; i < rectChildren.Count; i++)
                {
                    RectTransform child     = rectChildren[i];
                    float         childSize = 0;
                    if ((axis == 1 ? childForceExpandHeight : childForceExpandWidth))
                    {
                        float min       = LayoutUtility.GetMinSize(child, axis);
                        float preferred = LayoutUtility.GetPreferredSize(child, axis);
                        float flexible  = LayoutUtility.GetFlexibleSize(child, axis);
                        flexible   = Mathf.Max(flexible, 1);
                        childSize  = Mathf.Lerp(min, preferred, minMaxLerp);
                        childSize += flexible * itemFlexibleMultiplier;
                    }
                    else
                    {
                        childSize += itemwh;
                        wh        += childSize + spacing;
                    }

                    SetChildAlongAxis(child, axis, pos, childSize);
                    pos += childSize + spacing;
                }
            }

            if (!isForceExpand)
            {
                if (!isVertical)
                {
                    rect.pivot     = new Vector2(0f, 0.5f);
                    rect.sizeDelta = new Vector2(wh, 0);
                    rect.anchorMin = new Vector2(0f, 0f);
                    rect.anchorMax = new Vector2(0f, 1.0f);
                }
                else
                {
                    rect.pivot     = new Vector2(0.5f, 1.0f);
                    rect.sizeDelta = new Vector2(0, wh);
                    rect.anchorMin = new Vector2(0, 1.0f);
                    rect.anchorMax = new Vector2(1.0f, 1.0f);
                }
            }
        }