namespace Spectre.Console;
///
/// Represents padding.
///
public struct Padding : IEquatable
{
///
/// Gets the left padding.
///
public int Left { get; }
///
/// Gets the top padding.
///
public int Top { get; }
///
/// Gets the right padding.
///
public int Right { get; }
///
/// Gets the bottom padding.
///
public int Bottom { get; }
///
/// Initializes a new instance of the struct.
///
/// The padding for all sides.
public Padding(int size)
: this(size, size, size, size)
{
}
///
/// Initializes a new instance of the struct.
///
/// The left and right padding.
/// The top and bottom padding.
public Padding(int horizontal, int vertical)
: this(horizontal, vertical, horizontal, vertical)
{
}
///
/// Initializes a new instance of the struct.
///
/// The left padding.
/// The top padding.
/// The right padding.
/// The bottom padding.
public Padding(int left, int top, int right, int bottom)
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
///
public override bool Equals(object? obj)
{
return obj is Padding padding && Equals(padding);
}
///
public override int GetHashCode()
{
unchecked
{
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;
}
}
///
public bool Equals(Padding other)
{
return Left == other.Left
&& Top == other.Top
&& Right == other.Right
&& Bottom == other.Bottom;
}
///
/// Checks if two instances are equal.
///
/// The first instance to compare.
/// The second instance to compare.
/// true if the two instances are equal, otherwise false.
public static bool operator ==(Padding left, Padding right)
{
return left.Equals(right);
}
///
/// Checks if two instances are not equal.
///
/// The first instance to compare.
/// The second instance to compare.
/// true if the two instances are not equal, otherwise false.
public static bool operator !=(Padding left, Padding right)
{
return !(left == right);
}
///
/// Gets the padding width.
///
/// The padding width.
public int GetWidth()
{
return Left + Right;
}
///
/// Gets the padding height.
///
/// The padding height.
public int GetHeight()
{
return Top + Bottom;
}
}