示例#1
0
        /// <summary>
        /// Renders the current instance in the specified <see cref="ITablePrinter"/>.
        /// </summary>
        /// <param name="tablePrinter">The <see cref="ITablePrinter"/> instance that will display the rendered title row.</param>
        /// <param name="size">The minimum width into which the current instance must be rendered.</param>
        public void Render(ITablePrinter tablePrinter, Size size)
        {
            BorderTemplate borderTemplate = ParentDataGrid?.BorderTemplate;

            bool displayBorder = borderTemplate != null && ParentDataGrid?.DisplayBorder == true;

            Size cellSize = displayBorder
                ? size.InflateWidth(-2)
                : size;

            IEnumerable <string> cellContents = TitleCell.Render(cellSize);

            // Write title
            foreach (string line in cellContents)
            {
                if (displayBorder)
                {
                    tablePrinter.WriteBorder(borderTemplate.Left);
                }

                tablePrinter.WriteTitle(line);

                if (displayBorder)
                {
                    tablePrinter.WriteBorder(borderTemplate.Right);
                }

                tablePrinter.WriteLine();
            }
        }
示例#2
0
        /// <summary>
        /// Renders the row containing the column headers.
        /// </summary>
        /// <param name="tablePrinter">The destination where the current instance must be rendered.</param>
        /// <param name="cellWidths">The widths of each header cell that must be rendered.</param>
        /// <param name="rowHeight">The height of the row to be rendered. If there are not enough text lines
        /// in the content of a cell, spaces are written instead.</param>
        public void RenderHeaderRow(ITablePrinter tablePrinter, List <int> cellWidths, int rowHeight)
        {
            // Get cells content.
            List <List <string> > cellContents = columns
                                                 .Select((x, i) =>
            {
                Size size = new Size(cellWidths[i], rowHeight);
                return(x.HeaderCell.Render(size).ToList());
            })
                                                 .ToList();

            bool           displayBorder  = parentDataGrid?.DisplayBorder ?? true;
            BorderTemplate borderTemplate = parentDataGrid?.BorderTemplate;

            for (int headerLineIndex = 0; headerLineIndex < rowHeight; headerLineIndex++)
            {
                // Write left border.
                if (displayBorder && borderTemplate != null)
                {
                    tablePrinter.WriteBorder(borderTemplate.Left);
                }

                for (int columnIndex = 0; columnIndex < columns.Count; columnIndex++)
                {
                    // Write cell content.
                    string content = cellContents[columnIndex][headerLineIndex];
                    tablePrinter.WriteHeader(content);

                    // Write intermediate or right border.
                    if (displayBorder && borderTemplate != null)
                    {
                        char cellBorderRight = columnIndex < columns.Count - 1
                            ? borderTemplate.Vertical
                            : borderTemplate.Right;

                        tablePrinter.WriteBorder(cellBorderRight);
                    }
                }

                tablePrinter.WriteLine();
            }
        }
示例#3
0
        /// <summary>
        /// Renders the row current row.
        /// </summary>
        /// <param name="tablePrinter">The destination where the current instance must be rendered.</param>
        /// <param name="cellWidths">The widths of each cell that must be rendered.</param>
        /// <param name="height">The height of the row to be rendered. If there are not enough text lines
        /// in the content of a cell, spaces are written instead.</param>
        public void Render(ITablePrinter tablePrinter, List <int> cellWidths, int height)
        {
            List <List <string> > cellContents = cells
                                                 .Select((x, i) =>
            {
                Size size = new Size(cellWidths[i], height);
                return(x.Render(size).ToList());
            })
                                                 .ToList();

            BorderTemplate borderTemplate = ParentDataGrid?.BorderTemplate;

            bool displayBorder = borderTemplate != null && ParentDataGrid?.DisplayBorder == true;

            for (int rowLineIndex = 0; rowLineIndex < height; rowLineIndex++)
            {
                if (displayBorder)
                {
                    tablePrinter.WriteBorder(borderTemplate.Left);
                }

                for (int columnIndex = 0; columnIndex < cells.Count; columnIndex++)
                {
                    string content = cellContents[columnIndex][rowLineIndex];
                    tablePrinter.WriteNormal(content);

                    if (displayBorder)
                    {
                        char cellBorderRight = columnIndex < cells.Count - 1
                            ? borderTemplate.Vertical
                            : borderTemplate.Right;

                        tablePrinter.WriteBorder(cellBorderRight);
                    }
                }

                tablePrinter.WriteLine();
            }
        }