Ejemplo n.º 1
0
        /// <summary>
        /// Calculates the final height of this component and applies it to the component.
        /// </summary>
        /// <param name="component">The component to calculate.</param>
        /// <param name="rowY">The row locations from GetRowHeights.</param>
        /// <returns>true if the height was applied, or false if the component was not laid out
        /// due to being disposed or set to ignore layout.</returns>
        private static bool SetFinalHeight(SizedGridComponent component, float[] rowY)
        {
            var  margin = component.Margin;
            var  sizes  = component.VerticalSize;
            var  target = sizes.source;
            bool ok     = !sizes.ignore && target != null;

            if (ok)
            {
                int rows = rowY.Length - 1;
                // Clamp first and last row occupied by this object
                int first = component.Row, last = first + component.RowSpan;
                first = first.InRange(0, rows - 1);
                last  = last.InRange(1, rows);
                // Align correctly in the cell box
                float y = rowY[first], rowHeight = rowY[last] - y;
                if (margin != null)
                {
                    float border = margin.top + margin.bottom;
                    y               += margin.top;
                    rowHeight       -= border;
                    sizes.min       -= border;
                    sizes.preferred -= border;
                }
                float actualHeight = PUIUtils.GetProperSize(sizes, rowHeight);
                // Take alignment into account
                y += PUIUtils.GetOffset(component.Alignment, PanelDirection.Vertical,
                                        rowHeight - actualHeight);
                target.rectTransform().SetInsetAndSizeFromParentEdge(RectTransform.Edge.
                                                                     Top, y, actualHeight);
            }
            return(ok);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculates the final width of this component and applies it to the component.
        /// </summary>
        /// <param name="component">The component to calculate.</param>
        /// <param name="colX">The column locations from GetColumnWidths.</param>
        /// <returns>true if the width was applied, or false if the component was not laid out
        /// due to being disposed or set to ignore layout.</returns>
        private static bool SetFinalWidth(SizedGridComponent component, float[] colX)
        {
            var  margin = component.Margin;
            var  sizes  = component.HorizontalSize;
            var  target = sizes.source;
            bool ok     = !sizes.ignore && target != null;

            if (ok)
            {
                int columns = colX.Length - 1;
                // Clamp first and last column occupied by this object
                int first = component.Column, last = first + component.ColumnSpan;
                first = first.InRange(0, columns - 1);
                last  = last.InRange(1, columns);
                // Align correctly in the cell box
                float x = colX[first], colWidth = colX[last] - x;
                if (margin != null)
                {
                    float border = margin.left + margin.right;
                    x               += margin.left;
                    colWidth        -= border;
                    sizes.min       -= border;
                    sizes.preferred -= border;
                }
                float actualWidth = PUIUtils.GetProperSize(sizes, colWidth);
                // Take alignment into account
                x += PUIUtils.GetOffset(component.Alignment, PanelDirection.Horizontal,
                                        colWidth - actualWidth);
                target.rectTransform().SetInsetAndSizeFromParentEdge(RectTransform.Edge.
                                                                     Left, x, actualWidth);
            }
            return(ok);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Lays out components in the card layout container.
        /// </summary>
        /// <param name="margin">The margin to allow around the components.</param>
        /// <param name="required">The calculated minimum and preferred sizes.</param>
        /// <param name="size">The total available size in this dimension.</param>
        private static void DoLayout(RectOffset margin, CardLayoutResults required, float size)
        {
            if (required == null)
            {
                throw new ArgumentNullException("required");
            }
            var direction  = required.direction;
            var components = ListPool <ILayoutController, BoxLayoutGroup> .Allocate();

            // Compensate for margins
            if (direction == PanelDirection.Horizontal)
            {
                size -= margin.left + margin.right;
            }
            else
            {
                size -= margin.top + margin.bottom;
            }
            foreach (var child in required.children)
            {
                var obj = child.source;
                if (obj != null)
                {
                    float compSize = PUIUtils.GetProperSize(child, size);
                    // Place and size component
                    var transform = obj.AddOrGet <RectTransform>();
                    if (direction == PanelDirection.Horizontal)
                    {
                        transform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left,
                                                                margin.left, compSize);
                    }
                    else
                    {
                        transform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top,
                                                                margin.top, compSize);
                    }
                    // Invoke SetLayout on dependents
                    components.Clear();
                    obj.GetComponents(components);
                    foreach (var component in components)
                    {
                        if (direction == PanelDirection.Horizontal)
                        {
                            component.SetLayoutHorizontal();
                        }
                        else                         // if (direction == PanelDirection.Vertical)
                        {
                            component.SetLayoutVertical();
                        }
                    }
                }
            }
            components.Recycle();
        }