Ejemplo n.º 1
0
 public float GetMinSize(RectTransform rect, int axis)
 {
     if (axis == 0)
     {
         return(LayoutUtility.GetMinWidth(rect));
     }
     return(LayoutUtility.GetMinHeight(rect));
 }
Ejemplo n.º 2
0
        public float GetGreatestMinimumChildWidth()
        {
            var max = 0f;

            for (var i = 0; i < rectChildren.Count; i++)
            {
                var w = LayoutUtility.GetMinWidth(rectChildren[i]);

                max = Mathf.Max(w, max);
            }

            return(max);
        }
Ejemplo n.º 3
0
        public static float GetMinSize(RectTransform rect, int axis)
        {
            float result;

            if (axis == 0)
            {
                result = LayoutUtility.GetMinWidth(rect);
            }
            else
            {
                result = LayoutUtility.GetMinHeight(rect);
            }
            return(result);
        }
Ejemplo n.º 4
0
        //------------------------------------------------------------------------------------------------------
        public override void CalculateLayoutInputHorizontal()
        {
            base.CalculateLayoutInputHorizontal();

            int columns = GetColumnCount();
            int rows    = GetRowCount();

            // Calc it based on all cells in that column
            // Cycle through all cells and store max values for column
            colMinWidths       = new float[columns];
            colPreferredWidths = new float[columns];
//			colFlexibleWidths = new float[columns];
            for (int c = 0; c < columns; c++)
            {
                colMinWidths [c]       = 0;
                colPreferredWidths [c] = 0;
//				colFlexibleWidths [c] = 0;
            }

            for (int i = 0; i < rectChildren.Count; i++)
            {
                var child = rectChildren [i];
                int col   = GetCellColumn(i, columns, rows);
                colMinWidths[col]       = Mathf.Max(colMinWidths[col], LayoutUtility.GetMinWidth(child));
                colPreferredWidths[col] = Mathf.Max(colPreferredWidths[col], LayoutUtility.GetPreferredWidth(child));
//				colFlexibleWidths[col] = Mathf.Max (colFlexibleWidths[col], LayoutUtility.GetFlexibleWidth (child));
            }

            float totalMinWidth       = padding.horizontal;
            float totalPreferredWidth = padding.horizontal;

//			float totalFlexibleWidth = 0;
            for (int c = 0; c < columns; c++)
            {
                totalMinWidth       += colMinWidths [c] + spacing.x;
                totalPreferredWidth += colPreferredWidths [c] + spacing.x;
//				totalFlexibleWidth += colFlexibleWidths [c] + spacing.x;
            }
            totalMinWidth       -= spacing.x;
            totalPreferredWidth -= spacing.x;
//			totalFlexibleWidth -= spacing.x;

            SetLayoutInputForAxis(totalMinWidth, totalPreferredWidth, -1, 0);

            float prefW      = LayoutUtility.GetPreferredWidth(rectTransform);
            float extraSpace = prefW - totalPreferredWidth;

            // Stretch if there is a layout element specifying extra space
            if (extraSpace > 0)
            {
                // Give extra space equally
                bool[] expandColumn    = new bool[columns];
                int    columnsToExpand = 0;

                for (int c = 0; c < columns; c++)
                {
                    expandColumn [c] = false;
                    for (int r = 0; r < rows; r++)
                    {
                        int index = GetCellIndexAtGridRef(c, r, columns, rows);
                        if (index < rectChildren.Count)
                        {
                            var child = rectChildren [index];
                            var cell  = child.GetComponent <VGridCell> ();
                            if (cell == null || cell.doNotExpandWidth == false)
                            {
                                expandColumn [c] = true;
                                columnsToExpand++;
                                break;
                            }
                        }
                    }
                }

                for (int c = 0; c < columns; c++)
                {
                    if (expandColumn[c])
                    {
                        colPreferredWidths [c] += extraSpace / columnsToExpand;
                    }
                }
            }

//			Debug.Log (string.Format ("min {0} pref {1}", LayoutUtility.GetMinWidth(rectTransform), LayoutUtility.GetPreferredWidth(rectTransform)));
        }