Пример #1
0
        public void CalculateLayoutInputHorizontal()
        {
            results = new GridLayoutResults(rows, columns, children);
            var elements = ListPool <Component, PGridLayoutGroup> .Allocate();

            foreach (var component in results.Components)
            {
                // Cache size of children
                var obj    = component.HorizontalSize.source;
                var margin = component.Margin;
                elements.Clear();
                obj.GetComponents(elements);
                var sz = PUIUtils.CalcSizes(obj, PanelDirection.Horizontal, elements);
                if (!sz.ignore)
                {
                    // Add borders
                    int border = (margin == null) ? 0 : margin.left + margin.right;
                    sz.min       += border;
                    sz.preferred += border;
                }
                component.HorizontalSize = sz;
            }
            elements.Recycle();
            // Calculate columns sizes and our size
            results.CalcBaseWidths();
            float width = results.MinWidth;

            if (Margin != null)
            {
                width += Margin.left + Margin.right;
            }
            minWidth      = preferredWidth = width;
            flexibleWidth = (results.TotalFlexWidth > 0.0f) ? 1.0f : 0.0f;
        }
Пример #2
0
 internal PGridLayoutGroup()
 {
     children       = new List <GridComponent <GameObject> >(16);
     columns        = new List <GridColumnSpec>(16);
     rows           = new List <GridRowSpec>(16);
     layoutPriority = 1;
     Margin         = null;
     results        = null;
 }
Пример #3
0
        /// <summary>
        /// Calculates all row heights.
        /// </summary>
        /// <param name="results">The results from layout.</param>
        /// <param name="obj">The object to lay out.</param>
        /// <param name="margin">The margins within the borders.</param>
        /// <returns>The row heights.</returns>
        private static float[] GetRowHeights(GridLayoutResults results, GameObject obj,
                                             RectOffset margin)
        {
            int rows = results.Rows;
            // Find out how much flexible size can be given out
            float position = margin?.bottom ?? 0, top = margin?.top ?? 0;
            float actualWidth = obj.rectTransform().rect.height - position - top,
                  totalFlex = results.TotalFlexHeight, excess = (totalFlex > 0.0f) ?
                                                                (actualWidth - results.MinHeight) / totalFlex : 0.0f;

            float[] rowY = new float[rows + 1];
            // Determine start of rows
            for (int i = 0; i < rows; i++)
            {
                var spec = results.ComputedRowSpecs[i];
                rowY[i]   = position;
                position += spec.Height + spec.FlexHeight * excess;
            }
            rowY[rows] = position;
            return(rowY);
        }
Пример #4
0
        /// <summary>
        /// Calculates all column widths.
        /// </summary>
        /// <param name="results">The results from layout.</param>
        /// <param name="obj">The object to lay out.</param>
        /// <param name="margin">The margins within the borders.</param>
        /// <returns>The column widths.</returns>
        private static float[] GetColumnWidths(GridLayoutResults results, GameObject obj,
                                               RectOffset margin)
        {
            int columns = results.Columns;
            // Find out how much flexible size can be given out
            float position = margin?.left ?? 0, right = margin?.right ?? 0;
            float actualWidth = obj.rectTransform().rect.width - position - right,
                  totalFlex = results.TotalFlexWidth, excess = (totalFlex > 0.0f) ?
                                                               (actualWidth - results.MinWidth) / totalFlex : 0.0f;

            float[] colX = new float[columns + 1];
            // Determine start of columns
            for (int i = 0; i < columns; i++)
            {
                var spec = results.ComputedColumnSpecs[i];
                colX[i]   = position;
                position += spec.Width + spec.FlexWidth * excess;
            }
            colX[columns] = position;
            return(colX);
        }
Пример #5
0
 protected override void OnEnable()
 {
     base.OnEnable();
     SetDirty();
     results = null;
 }
Пример #6
0
 protected override void OnDidApplyAnimationProperties()
 {
     base.OnDidApplyAnimationProperties();
     SetDirty();
     results = null;
 }
Пример #7
0
 protected override void OnDisable()
 {
     base.OnDisable();
     results = null;
 }