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:
Patrik Svensson
2020-09-14 23:34:02 +02:00
committed by Patrik Svensson
parent 314456ca17
commit 7d6104ace4
13 changed files with 366 additions and 55 deletions

View File

@@ -3,7 +3,7 @@ using System;
namespace Spectre.Console
{
/// <summary>
/// Represents a measurement.
/// Represents padding.
/// </summary>
public struct Padding : IEquatable<Padding>
{
@@ -12,20 +12,53 @@ namespace Spectre.Console
/// </summary>
public int Left { get; }
/// <summary>
/// Gets the top padding.
/// </summary>
public int Top { get; }
/// <summary>
/// Gets the right padding.
/// </summary>
public int Right { get; }
/// <summary>
/// Gets the bottom padding.
/// </summary>
public int Bottom { get; }
/// <summary>
/// Initializes a new instance of the <see cref="Padding"/> struct.
/// </summary>
/// <param name="size">The padding for all sides.</param>
public Padding(int size)
: this(size, size, size, size)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Padding"/> struct.
/// </summary>
/// <param name="horizontal">The left and right padding.</param>
/// <param name="vertical">The top and bottom padding.</param>
public Padding(int horizontal, int vertical)
: this(horizontal, vertical, horizontal, vertical)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Padding"/> struct.
/// </summary>
/// <param name="left">The left padding.</param>
/// <param name="top">The top padding.</param>
/// <param name="right">The right padding.</param>
public Padding(int left, int right)
/// <param name="bottom">The bottom padding.</param>
public Padding(int left, int top, int right, int bottom)
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
/// <inheritdoc/>
@@ -41,7 +74,9 @@ namespace Spectre.Console
{
var hash = (int)2166136261;
hash = (hash * 16777619) ^ Left.GetHashCode();
hash = (hash * 16777619) ^ Top.GetHashCode();
hash = (hash * 16777619) ^ Right.GetHashCode();
hash = (hash * 16777619) ^ Bottom.GetHashCode();
return hash;
}
}
@@ -49,7 +84,10 @@ namespace Spectre.Console
/// <inheritdoc/>
public bool Equals(Padding other)
{
return Left == other.Left && Right == other.Right;
return Left == other.Left
&& Top == other.Top
&& Right == other.Right
&& Bottom == other.Bottom;
}
/// <summary>
@@ -75,12 +113,21 @@ namespace Spectre.Console
}
/// <summary>
/// Gets the horizontal padding.
/// Gets the padding width.
/// </summary>
/// <returns>The horizontal padding.</returns>
public int GetHorizontalPadding()
/// <returns>The padding width.</returns>
public int GetWidth()
{
return Left + Right;
}
/// <summary>
/// Gets the padding height.
/// </summary>
/// <returns>The padding height.</returns>
public int GetHeight()
{
return Top + Bottom;
}
}
}