Exemple #1
0
            public TableCellModel(
                int cellArrayIndex,
                int rowIndex,
                int actualColumnIndex,
                string content,
                int colSpan,
                int rowSpan,
                VerticalCellAlign verticalAlign,
                HorizontalCellAlign horizontalCellAlign)
            {
                CellRowIndex = cellArrayIndex;

                RenderStartRowIndex = rowIndex;
                RenderEndRowIndex   = rowIndex + (rowSpan - 1);

                RenderStartColumnIndex = actualColumnIndex;
                RenderEndColumnIndex   = RenderStartColumnIndex + (colSpan - 1);

                ColSpan = colSpan;
                RowSpan = rowSpan;

                Content = content;

                VerticalAlign   = verticalAlign;
                HorizontalAlign = horizontalCellAlign;

                if (VerticalAlign == VerticalCellAlign.Top)
                {
                    RenderContentRowIndex = RenderStartRowIndex;
                }
                else if (VerticalAlign == VerticalCellAlign.Bottom)
                {
                    RenderContentRowIndex = RenderEndRowIndex;
                }
                else if (VerticalAlign == VerticalCellAlign.Middle)
                {
                    if (RenderStartRowIndex == RenderEndRowIndex || RowSpan < 3)
                    {
                        RenderContentRowIndex = RenderStartRowIndex;
                    }
                    else
                    {
                        var halfSize = RowSpan / 2;
                        RenderContentRowIndex = RenderStartRowIndex + halfSize;
                    }
                }
            }
Exemple #2
0
        private static string PadCellContent(string contentToPrint, int cellCharWidth, HorizontalCellAlign horizontalCellAlign)
        {
            if (horizontalCellAlign == HorizontalCellAlign.Left)
            {
                return(contentToPrint.PadRight(cellCharWidth, ' '));
            }

            if (horizontalCellAlign == HorizontalCellAlign.Right)
            {
                return(contentToPrint.PadLeft(cellCharWidth, ' '));
            }

            var availablePadding = cellCharWidth - contentToPrint.Length;

            if (availablePadding > 0)
            {
                var leftPadding        = availablePadding / 2;
                var leftPaddingString  = new string(' ', leftPadding);
                var rightPaddingString = new string(' ', availablePadding - leftPadding);
                return($"{leftPaddingString}{contentToPrint}{rightPaddingString}");
            }

            return(contentToPrint);
        }