src/Tables/GridTable.cs
/// <summary>
/// Calculate the width of each column
/// </summary>
/// <returns></returns>
Calculate the width of each column
Calculate the width of each column
private int[] CalculateWidths()
        {
            int columnCount = ColumnWidths.Length;
            int[] widths = new int[columnCount];
            int childMaxWidth = Children.Max(c => c.Sum(cl => (cl?.Content?.ToString()??"").Length) + c.Count*3);
            int maxWidth = Math.Min(childMaxWidth, MaxWidth);
            for (int i = 0; i < columnCount; i++)
            {
                if (ColumnWidths[i] == 0)
                {
                    int width = Children.Max(c => c.Count > i ? (c[i]?.Content?.ToString() ?? "").Length : 0);
                    if (width > maxWidth)
                        width = maxWidth / columnCount;
                    widths[i] = width;
                }
            }
            int remainder = maxWidth - widths.Sum();
            for (int i = 0; i < columnCount; i++)
            {
                if (ColumnWidths[i] > 0)
                    widths[i] = (int) (remainder * ColumnWidths[i]);
                else if (widths[i] == 0)
                    widths[i] = remainder / columnCount + 3;
            }
            return widths;
        }
private int [ ] CalculateWidths ( ) { int columnCount = ColumnWidths . Length ; int [ ] widths = new int [ columnCount ] ; int childMaxWidth = Children . Max ( c => c . Sum ( cl => ( cl ? . Content ? . ToString ( ) ?? " " ) . Length ) + c . Count * 3 ) ; int maxWidth = Math . Min ( childMaxWidth , MaxWidth ) ; for ( int i = 0 ; i < columnCount ; i ++ ) { if ( ColumnWidths [ i ] == 0 ) { int width = Children . Max ( c => c . Count > i ? ( c [ i ] ? . Content ? . ToString ( ) ?? " " ) . Length : 0 ) ; if ( width > maxWidth ) width = maxWidth / columnCount ; widths [ i ] = width ; } } int remainder = maxWidth - widths . Sum ( ) ; for ( int i = 0 ; i < columnCount ; i ++ ) { if ( ColumnWidths [ i ] > 0 ) widths [ i ] = ( int ) ( remainder * ColumnWidths [ i ] ) ; else if ( widths [ i ] == 0 ) widths [ i ] = remainder / columnCount + 3 ; } return widths ; }
Calculate the width of each column
Calculate the width of each column
None