mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Add padder widget
This commit adds a padder can be use to pad other IRenderable objects such as tables, panels, grids, text, etc.
This commit is contained in:

committed by
Patrik Svensson

parent
314456ca17
commit
7d6104ace4
@ -12,9 +12,9 @@ namespace Spectre.Console
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="padding">The left padding to apply.</param>
|
||||
/// <param name="left">The left padding.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T PadLeft<T>(this T obj, int padding)
|
||||
public static T PadLeft<T>(this T obj, int left)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
if (obj is null)
|
||||
@ -22,7 +22,25 @@ namespace Spectre.Console
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return SetPadding(obj, new Padding(padding, obj.Padding.Right));
|
||||
return SetPadding(obj, new Padding(left, obj.Padding.Top, obj.Padding.Right, obj.Padding.Bottom));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the top padding.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="top">The top padding.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T PadTop<T>(this T obj, int top)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return SetPadding(obj, new Padding(obj.Padding.Left, top, obj.Padding.Right, obj.Padding.Bottom));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -30,9 +48,9 @@ namespace Spectre.Console
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="padding">The right padding to apply.</param>
|
||||
/// <param name="right">The right padding.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T PadRight<T>(this T obj, int padding)
|
||||
public static T PadRight<T>(this T obj, int right)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
if (obj is null)
|
||||
@ -40,7 +58,25 @@ namespace Spectre.Console
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return SetPadding(obj, new Padding(obj.Padding.Left, padding));
|
||||
return SetPadding(obj, new Padding(obj.Padding.Left, obj.Padding.Top, right, obj.Padding.Bottom));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the bottom padding.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="bottom">The bottom padding.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T PadBottom<T>(this T obj, int bottom)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return SetPadding(obj, new Padding(obj.Padding.Left, obj.Padding.Top, obj.Padding.Right, bottom));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -49,12 +85,14 @@ namespace Spectre.Console
|
||||
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||
/// <param name="obj">The paddable object instance.</param>
|
||||
/// <param name="left">The left padding to apply.</param>
|
||||
/// <param name="top">The top padding to apply.</param>
|
||||
/// <param name="right">The right padding to apply.</param>
|
||||
/// <param name="bottom">The bottom padding to apply.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T SetPadding<T>(this T obj, int left, int right)
|
||||
public static T SetPadding<T>(this T obj, int left, int top, int right, int bottom)
|
||||
where T : class, IPaddable
|
||||
{
|
||||
return SetPadding(obj, new Padding(left, right));
|
||||
return SetPadding(obj, new Padding(left, top, right, bottom));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user