/// <inheritdoc/> protected override Measurement Measure(RenderContext context, int maxWidth) { if (context is null) { throw new ArgumentNullException(nameof(context)); } var measurer = new TableMeasurer(this, context); // Calculate the total cell width var totalCellWidth = measurer.CalculateTotalCellWidth(maxWidth); // Calculate the minimum and maximum table width var measurements = _columns.Select(column => measurer.MeasureColumn(column, totalCellWidth)); var minTableWidth = measurements.Sum(x => x.Min) + measurer.GetNonColumnWidth(); var maxTableWidth = Width ?? measurements.Sum(x => x.Max) + measurer.GetNonColumnWidth(); return(new Measurement(minTableWidth, maxTableWidth)); }
/// <inheritdoc/> protected override IEnumerable <Segment> Render(RenderContext context, int maxWidth) { if (context is null) { throw new ArgumentNullException(nameof(context)); } var measurer = new TableMeasurer(this, context); // Calculate the column and table width var totalCellWidth = measurer.CalculateTotalCellWidth(maxWidth); var columnWidths = measurer.CalculateColumnWidths(totalCellWidth); var tableWidth = columnWidths.Sum() + measurer.GetNonColumnWidth(); // Get the rows to render var rows = GetRenderableRows(); // Render the table return(TableRenderer.Render( new TableRendererContext(this, context, rows, tableWidth, maxWidth), columnWidths)); }