예제 #1
0
        /// <summary>
        /// For a multirow component, ratiometrically splits up any excess preferred size
        /// among the rows in its span that have a flexible height.
        /// </summary>
        /// <param name="component">The component to reallocate sizes.</param>
        private void ExpandMultiRow(SizedGridComponent component)
        {
            float need = component.VerticalSize.preferred, totalFlex = 0.0f;
            int   start = component.Row, end = start + component.RowSpan;

            for (int i = start; i < end; i++)
            {
                var spec = ComputedRowSpecs[i];
                if (spec.FlexHeight > 0.0f)
                {
                    totalFlex += spec.FlexHeight;
                }
                need -= spec.Height;
            }
            if (need > 0.0f && totalFlex > 0.0f)
            {
                // No flex = we can do nothing about it
                for (int i = start; i < end; i++)
                {
                    var   spec = ComputedRowSpecs[i];
                    float flex = spec.FlexHeight;
                    if (flex > 0.0f)
                    {
                        ComputedRowSpecs[i] = new GridRowSpec(spec.Height + flex * need /
                                                              totalFlex, flex);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// For a multicolumn component, ratiometrically splits up any excess preferred size
        /// among the columns in its span that have a flexible width.
        /// </summary>
        /// <param name="component">The component to reallocate sizes.</param>
        private void ExpandMultiColumn(SizedGridComponent component)
        {
            float need = component.HorizontalSize.preferred, totalFlex = 0.0f;
            int   start = component.Column, end = start + component.ColumnSpan;

            for (int i = start; i < end; i++)
            {
                var spec = ComputedColumnSpecs[i];
                if (spec.FlexWidth > 0.0f)
                {
                    totalFlex += spec.FlexWidth;
                }
                need -= spec.Width;
            }
            if (need > 0.0f && totalFlex > 0.0f)
            {
                // No flex = we can do nothing about it
                for (int i = start; i < end; i++)
                {
                    var   spec = ComputedColumnSpecs[i];
                    float flex = spec.FlexWidth;
                    if (flex > 0.0f)
                    {
                        ComputedColumnSpecs[i] = new GridColumnSpec(spec.Width + flex * need /
                                                                    totalFlex, flex);
                    }
                }
            }
        }