/// <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(); } }
/// <summary> /// Initializes a new instance of the <see cref="TitleRow"/> class with /// a <see cref="MultilineText"/> content. /// </summary> public TitleRow(MultilineText title) { TitleCell = new TitleCell { ParentRow = this, Content = title ?? MultilineText.Empty }; }
/// <summary> /// Initializes a new instance of the <see cref="TitleRow"/> class with /// empty content. /// </summary> public TitleRow() { TitleCell = new TitleCell { ParentRow = this, Content = MultilineText.Empty }; }
/// <summary> /// Initializes a new instance of the <see cref="TitleRow"/> class with /// an <see cref="object"/> representing the content. /// </summary> public TitleRow(object title) { TitleCell = new TitleCell { ParentRow = this, Content = title?.ToString() ?? MultilineText.Empty }; }
/// <summary> /// Initializes a new instance of the <see cref="TitleRow"/> class with /// the text content. /// </summary> public TitleRow(string title) { TitleCell = new TitleCell { ParentRow = this, Content = title == null ? MultilineText.Empty : new MultilineText(title) }; }
/// <summary> /// Calculates the space (in characters) the current instance ocupies without other restrictions. /// </summary> public Size CalculatePreferedSize() { bool displayBorder = ParentDataGrid?.DisplayBorder ?? false; int titleRowWidth = 0; if (displayBorder) { titleRowWidth += 1; } Size cellSize = TitleCell.CalculatePreferedSize(); titleRowWidth += cellSize.Width; if (displayBorder) { titleRowWidth += 1; } return(new Size(titleRowWidth, cellSize.Height)); }