Example #1
0
        protected override void performLayout()
        {
            int rows    = this.rows;
            int columns = this.columns;

            D.assert(this._children.Count == rows * columns);
            if (rows * columns == 0)
            {
                this.size = this.constraints.constrain(new Size(0.0f, 0.0f));
                return;
            }

            List <float> widths     = this._computeColumnWidths(this.constraints);
            List <float> positions  = new List <float>();
            float        tableWidth = 0.0f;

            positions.Add(0.0f);
            for (int x = 1; x < columns; x++)
            {
                positions.Add(positions[x - 1] + widths[x - 1]);
            }

            this._columnLefts = positions;
            tableWidth        = positions.Last() + widths.Last();

            D.assert(!positions.Any((float value) => { return(value == null); }));
            this._rowTops.Clear();
            this._baselineDistance = null;

            float rowTop = 0.0f;

            for (int y = 0; y < rows; y++)
            {
                this._rowTops.Add(rowTop);
                float         rowHeight              = 0.0f;
                bool          haveBaseline           = false;
                float         beforeBaselineDistance = 0.0f;
                float         afterBaselineDistance  = 0.0f;
                List <float?> baselines              = new List <float?>();
                for (int i = 0; i < columns; i++)
                {
                    baselines.Add(null);
                }

                for (int x = 0; x < columns; x++)
                {
                    int       xy    = x + y * columns;
                    RenderBox child = this._children[xy];
                    if (child != null)
                    {
                        TableCellParentData childParentData = (TableCellParentData)child.parentData;
                        D.assert(childParentData != null);
                        childParentData.x = x;
                        childParentData.y = y;
                        switch (childParentData.verticalAlignment ?? this.defaultVerticalAlignment)
                        {
                        case TableCellVerticalAlignment.baseline: {
                            D.assert(this.textBaseline != null);
                            child.layout(BoxConstraints.tightFor(width: widths[x]), parentUsesSize: true);
                            float?childBaseline =
                                child.getDistanceToBaseline(this.textBaseline.Value, onlyReal: true);
                            if (childBaseline != null)
                            {
                                beforeBaselineDistance = Mathf.Max(beforeBaselineDistance, childBaseline.Value);
                                afterBaselineDistance  = Mathf.Max(afterBaselineDistance,
                                                                   child.size.height - childBaseline.Value);
                                baselines[x] = childBaseline.Value;
                                haveBaseline = true;
                            }
                            else
                            {
                                rowHeight = Mathf.Max(rowHeight, child.size.height);
                                childParentData.offset = new Offset(positions[x], rowTop);
                            }

                            break;
                        }

                        case TableCellVerticalAlignment.top:
                        case TableCellVerticalAlignment.middle:
                        case TableCellVerticalAlignment.bottom: {
                            child.layout(BoxConstraints.tightFor(width: widths[x]), parentUsesSize: true);
                            rowHeight = Mathf.Max(rowHeight, child.size.height);
                            break;
                        }

                        case TableCellVerticalAlignment.fill: {
                            break;
                        }
                        }
                    }
                }

                if (haveBaseline)
                {
                    if (y == 0)
                    {
                        this._baselineDistance = beforeBaselineDistance;
                    }

                    rowHeight = Mathf.Max(rowHeight, beforeBaselineDistance + afterBaselineDistance);
                }

                for (int x = 0; x < columns; x++)
                {
                    int       xy    = x + y * columns;
                    RenderBox child = this._children[xy];
                    if (child != null)
                    {
                        TableCellParentData childParentData = (TableCellParentData)child.parentData;
                        switch (childParentData.verticalAlignment ?? this.defaultVerticalAlignment)
                        {
                        case TableCellVerticalAlignment.baseline: {
                            if (baselines[x] != null)
                            {
                                childParentData.offset = new Offset(positions[x],
                                                                    rowTop + beforeBaselineDistance - baselines[x].Value);
                            }

                            break;
                        }

                        case TableCellVerticalAlignment.top: {
                            childParentData.offset = new Offset(positions[x], rowTop);
                            break;
                        }

                        case TableCellVerticalAlignment.middle: {
                            childParentData.offset = new Offset(positions[x],
                                                                rowTop + (rowHeight - child.size.height) / 2.0f);
                            break;
                        }

                        case TableCellVerticalAlignment.bottom: {
                            childParentData.offset =
                                new Offset(positions[x], rowTop + rowHeight - child.size.height);
                            break;
                        }

                        case TableCellVerticalAlignment.fill: {
                            child.layout(BoxConstraints.tightFor(width: widths[x], height: rowHeight));
                            childParentData.offset = new Offset(positions[x], rowTop);
                            break;
                        }
                        }
                    }
                }

                rowTop += rowHeight;
            }

            this._rowTops.Add(rowTop);
            this.size = this.constraints.constrain(new Size(tableWidth, rowTop));
            D.assert(this._rowTops.Count == rows + 1);
        }
Example #2
0
 static float _boxBaseline(RenderBox box, TextBaseline baseline)
 {
     return(box.getDistanceToBaseline(baseline) ?? 0.0f);
 }
Example #3
0
 static double _boxBaseline(RenderBox box, TextBaseline baseline)
 {
     return(box.getDistanceToBaseline(baseline) ?? 0.0);
 }