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,4 +1,5 @@
using Spectre.Console;
using Spectre.Console.Rendering;
namespace PanelExample
{
@@ -13,35 +14,28 @@ namespace PanelExample
AnsiConsole.Render(
new Panel(
new Panel(content)
{
Border = BorderKind.Rounded,
}));
.SetBorderKind(BorderKind.Rounded)));
// Left adjusted panel with text
AnsiConsole.Render(new Panel(
new Text("Left adjusted\nLeft").LeftAligned())
{
Expand = true,
Header = new Header("Left", new Style(foreground: Color.Red)).LeftAligned(),
});
AnsiConsole.Render(
new Panel(new Text("Left adjusted\nLeft").LeftAligned())
.Expand()
.SquareBorder()
.SetHeader("Left", Style.WithForeground(Color.Red)));
// Centered ASCII panel with text
AnsiConsole.Render(new Panel(
new Text("Centered\nCenter").Centered())
{
Expand = true,
Border = BorderKind.Ascii,
Header = new Header("Center", new Style(foreground: Color.Green)).Centered(),
});
AnsiConsole.Render(
new Panel(new Text("Centered\nCenter").Centered())
.Expand()
.AsciiBorder()
.SetHeader("Center", Style.WithForeground(Color.Green), Justify.Center));
// Right adjusted, rounded panel with text
AnsiConsole.Render(new Panel(
new Text("Right adjusted\nRight").RightAligned())
{
Expand = true,
Border = BorderKind.Rounded,
Header = new Header("Right", new Style(foreground: Color.Blue)).RightAligned(),
});
AnsiConsole.Render(
new Panel(new Text("Right adjusted\nRight").RightAligned())
.Expand()
.RoundedBorder()
.SetHeader("Right", Style.WithForeground(Color.Blue), Justify.Right));
}
}
}