Add Layout widget (#1041)

* Add width to panels
* Add height to panels
* Replace RenderContext with RenderOptions
* Remove exclusivity from alternative buffer
* Add Layout widget
* Add Align widget
This commit is contained in:
Patrik Svensson
2022-11-15 10:12:17 +01:00
committed by GitHub
parent 9ce3b99cd6
commit c3ec6a7363
137 changed files with 2651 additions and 387 deletions

View File

@ -187,7 +187,9 @@ public sealed class TableTests
// Given
var console = new TestConsole();
var table = new Table();
#pragma warning disable CS0618 // Type or member is obsolete
table.Alignment = Justify.Left;
#pragma warning restore CS0618 // Type or member is obsolete
table.AddColumns("Foo", "Bar", "Baz");
table.AddRow("Qux", "Corgi", "Waldo");
table.AddRow("Grault", "Garply", "Fred");
@ -199,6 +201,24 @@ public sealed class TableTests
return Verifier.Verify(console.Output);
}
[Fact]
[Expectation("Render_LeftAligned", "Align_Widget")]
public Task Should_Left_Align_Table_Correctly_When_Wrapped_In_Align_Widget()
{
// Given
var console = new TestConsole();
var table = new Table();
table.AddColumns("Foo", "Bar", "Baz");
table.AddRow("Qux", "Corgi", "Waldo");
table.AddRow("Grault", "Garply", "Fred");
// When
console.Write(Align.Left(table));
// Then
return Verifier.Verify(console.Output);
}
[Fact]
[Expectation("Render_Centered")]
public Task Should_Center_Table_Correctly()
@ -206,7 +226,9 @@ public sealed class TableTests
// Given
var console = new TestConsole();
var table = new Table();
#pragma warning disable CS0618 // Type or member is obsolete
table.Alignment = Justify.Center;
#pragma warning restore CS0618 // Type or member is obsolete
table.AddColumns("Foo", "Bar", "Baz");
table.AddRow("Qux", "Corgi", "Waldo");
table.AddRow("Grault", "Garply", "Fred");
@ -218,6 +240,24 @@ public sealed class TableTests
return Verifier.Verify(console.Output);
}
[Fact]
[Expectation("Render_Centered", "Align_Widget")]
public Task Should_Center_Table_Correctly_When_Wrapped_In_Align_Widget()
{
// Given
var console = new TestConsole();
var table = new Table();
table.AddColumns("Foo", "Bar", "Baz");
table.AddRow("Qux", "Corgi", "Waldo");
table.AddRow("Grault", "Garply", "Fred");
// When
console.Write(Align.Center(table));
// Then
return Verifier.Verify(console.Output);
}
[Fact]
[Expectation("Render_RightAligned")]
public Task Should_Right_Align_Table_Correctly()
@ -225,7 +265,9 @@ public sealed class TableTests
// Given
var console = new TestConsole();
var table = new Table();
#pragma warning disable CS0618 // Type or member is obsolete
table.Alignment = Justify.Right;
#pragma warning restore CS0618 // Type or member is obsolete
table.AddColumns("Foo", "Bar", "Baz");
table.AddRow("Qux", "Corgi", "Waldo");
table.AddRow("Grault", "Garply", "Fred");
@ -237,6 +279,24 @@ public sealed class TableTests
return Verifier.Verify(console.Output);
}
[Fact]
[Expectation("Render_RightAligned", "Align_Widget")]
public Task Should_Right_Align_Table_Correctly_When_Wrapped_In_Align_Widget()
{
// Given
var console = new TestConsole();
var table = new Table();
table.AddColumns("Foo", "Bar", "Baz");
table.AddRow("Qux", "Corgi", "Waldo");
table.AddRow("Grault", "Garply", "Fred");
// When
console.Write(Align.Right(table));
// Then
return Verifier.Verify(console.Output);
}
[Fact]
[Expectation("Render_Nested")]
public Task Should_Render_Table_Nested_In_Panels_Correctly()
@ -380,7 +440,7 @@ public sealed class TableTests
table.AddColumn(new TableColumn(new Panel("[u]DEF[/]").BorderColor(Color.Green)));
table.AddColumn(new TableColumn(new Panel("[u]GHI[/]").BorderColor(Color.Blue)));
table.AddRow(new Text("Hello").Centered(), new Markup("[red]World[/]"), Text.Empty);
table.AddRow(second, new Text("Whaat"), new Text("Lol").RightAligned());
table.AddRow(second, new Text("Whaat"), new Text("Lol").RightJustified());
table.AddRow(new Markup("[blue]Hej[/]"), new Markup("[yellow]Världen[/]"), Text.Empty);
// When