Make styles composable

Also adds some new extension methods and make some APIs a bit more consistent.

Closes #64
This commit is contained in:
Patrik Svensson
2020-09-03 21:18:52 +02:00
committed by Patrik Svensson
parent bcaaa6b2d3
commit e946289bd9
12 changed files with 296 additions and 97 deletions

View File

@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Spectre.Console.Internal;
using Spectre.Console.Rendering;
namespace Spectre.Console
@@ -13,6 +11,16 @@ namespace Spectre.Console
{
private readonly Table _table;
/// <summary>
/// Gets the number of columns in the table.
/// </summary>
public int ColumnCount => _table.ColumnCount;
/// <summary>
/// Gets the number of rows in the table.
/// </summary>
public int RowCount => _table.RowCount;
/// <summary>
/// Initializes a new instance of the <see cref="Grid"/> class.
/// </summary>
@@ -20,7 +28,7 @@ namespace Spectre.Console
{
_table = new Table
{
Border = BorderKind.None,
BorderKind = BorderKind.None,
ShowHeaders = false,
IsGrid = true,
PadRightCell = false,
@@ -75,45 +83,6 @@ namespace Spectre.Console
});
}
/// <summary>
/// Adds a column to the grid.
/// </summary>
/// <param name="count">The number of columns to add.</param>
public void AddColumns(int count)
{
for (var index = 0; index < count; index++)
{
AddColumn(new GridColumn());
}
}
/// <summary>
/// Adds a column to the grid.
/// </summary>
/// <param name="columns">The columns to add.</param>
public void AddColumns(params GridColumn[] columns)
{
if (columns is null)
{
throw new ArgumentNullException(nameof(columns));
}
foreach (var column in columns)
{
AddColumn(column);
}
}
/// <summary>
/// Adds an empty row to the grid.
/// </summary>
public void AddEmptyRow()
{
var columns = new IRenderable[_table.ColumnCount];
Enumerable.Range(0, _table.ColumnCount).ForEach(index => columns[index] = Text.Empty);
AddRow(columns);
}
/// <summary>
/// Adds a new row to the grid.
/// </summary>