diff --git a/docs/input/widgets/table.md b/docs/input/widgets/table.md index 7db0545e..d124287e 100644 --- a/docs/input/widgets/table.md +++ b/docs/input/widgets/table.md @@ -109,12 +109,16 @@ table.Columns[0].RightAligned(); ## Padding ```csharp -// Set left and right padding -table.Columns[0].Padding(left: 3, right: 5); - // Set padding individually table.Columns[0].PadLeft(3); table.Columns[0].PadRight(5); + +// Or chained together +table.Columns[0].PadLeft(3).PadRight(5); + +// Or with the shorthand method if the left and right +// padding are identical. Vertical padding is ignored. +table.Columns[0].Padding(4, 0); ``` ## Disable column wrapping diff --git a/src/Spectre.Console.Tests/Unit/PadderTests.cs b/src/Spectre.Console.Tests/Unit/PadderTests.cs index 5f8cb060..b413dcda 100644 --- a/src/Spectre.Console.Tests/Unit/PadderTests.cs +++ b/src/Spectre.Console.Tests/Unit/PadderTests.cs @@ -77,7 +77,7 @@ namespace Spectre.Console.Tests.Unit table.AddColumn("Bar", c => c.PadLeft(0).PadRight(0)); table.AddRow("Baz", "Qux"); table.AddRow(new Text("Corgi"), new Padder(new Panel("Waldo")) - .Padding(2, 1, 2, 1)); + .Padding(2, 1)); // When console.Render(new Padder(table) diff --git a/src/Spectre.Console/Extensions/PaddableExtensions.cs b/src/Spectre.Console/Extensions/PaddableExtensions.cs index ad1ea739..ca038470 100644 --- a/src/Spectre.Console/Extensions/PaddableExtensions.cs +++ b/src/Spectre.Console/Extensions/PaddableExtensions.cs @@ -80,7 +80,7 @@ namespace Spectre.Console } /// - /// Sets the left and right padding. + /// Sets the left, top, right and bottom padding. /// /// An object implementing . /// The paddable object instance. @@ -95,6 +95,20 @@ namespace Spectre.Console return Padding(obj, new Padding(left, top, right, bottom)); } + /// + /// Sets the horizontal and vertical padding. + /// + /// An object implementing . + /// The paddable object instance. + /// The left and right padding. + /// The top and bottom padding. + /// The same instance so that multiple calls can be chained. + public static T Padding(this T obj, int horizontal, int vertical) + where T : class, IPaddable + { + return Padding(obj, new Padding(horizontal, vertical)); + } + /// /// Sets the padding. ///