示例#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);
        }
示例#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);
        }