Esempio n. 1
0
        private void AdjustSpannedCellWidth(TableCellData cell)
        {
            if (!AdjustSpannedCellsWidth)
            {
                return;
            }

            // check that spanned cell has enough width
            float columnsWidth = 0;

            for (int i = 0; i < cell.ColSpan; i++)
            {
                columnsWidth += Columns[cell.Address.X + i].Width;
            }
            // if cell is bigger than sum of column width, increase the last column width
            float cellWidth = cell.CalcWidth();

            if (columnsWidth < cellWidth)
            {
                Columns[cell.Address.X + cell.ColSpan - 1].Width += cellWidth - columnsWidth;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates and returns the table width, in pixels.
        /// </summary>
        public float CalcWidth()
        {
            // first pass, calc non-spanned cells
            for (int x = 0; x < Columns.Count; x++)
            {
                TableColumn column = Columns[x];
                if (!column.AutoSize)
                {
                    continue;
                }
                float columnWidth = IsDesigning ? 16 : -1;

                // calc the max column width
                for (int y = 0; y < Rows.Count; y++)
                {
                    TableCellData cell = GetCellData(x, y);
                    if (cell.ColSpan == 1)
                    {
                        float cellWidth = cell.CalcWidth();
                        if (cellWidth > columnWidth)
                        {
                            columnWidth = cellWidth;
                        }
                    }
                }

                // update column width
                if (columnWidth != -1)
                {
                    column.Width = columnWidth;
                }
            }

            // second pass, calc spanned cells
            for (int x = 0; x < Columns.Count; x++)
            {
                Columns[x].MinimumBreakWidth = 0;
                for (int y = 0; y < Rows.Count; y++)
                {
                    TableCellData cell = GetCellData(x, y);
                    if (cell.ColSpan > 1)
                    {
                        float cellWidth = cell.CalcWidth();
                        if (AdjustSpannedCellsWidth && cellWidth > Columns[x].MinimumBreakWidth)
                        {
                            Columns[x].MinimumBreakWidth = cellWidth;
                        }

                        // check that spanned columns have enough width
                        float columnsWidth = 0;
                        for (int i = 0; i < cell.ColSpan; i++)
                        {
                            columnsWidth += Columns[x + i].Width;
                        }

                        // if cell is bigger than sum of column width, increase the last column width
                        TableColumn lastColumn = Columns[x + cell.ColSpan - 1];
                        if (columnsWidth < cellWidth && lastColumn.AutoSize)
                        {
                            lastColumn.Width += cellWidth - columnsWidth;
                        }
                    }
                }
            }

            // finally, calculate the table width
            float width = 0;

            for (int i = 0; i < Columns.Count; i++)
            {
                width += Columns[i].Width;
            }

            lockColumnRowChange = true;
            Width = width;
            lockColumnRowChange = false;
            return(width);
        }