namespace Spectre.Console; /// /// Contains extension methods for . /// public static class PaddableExtensions { /// /// Sets the left padding. /// /// An object implementing . /// The paddable object instance. /// The left padding. /// The same instance so that multiple calls can be chained. public static T PadLeft(this T obj, int left) where T : class, IPaddable { if (obj is null) { throw new ArgumentNullException(nameof(obj)); } return Padding(obj, new Padding(left, obj.Padding.GetTopSafe(), obj.Padding.GetRightSafe(), obj.Padding.GetBottomSafe())); } /// /// Sets the top padding. /// /// An object implementing . /// The paddable object instance. /// The top padding. /// The same instance so that multiple calls can be chained. public static T PadTop(this T obj, int top) where T : class, IPaddable { if (obj is null) { throw new ArgumentNullException(nameof(obj)); } return Padding(obj, new Padding(obj.Padding.GetLeftSafe(), top, obj.Padding.GetRightSafe(), obj.Padding.GetBottomSafe())); } /// /// Sets the right padding. /// /// An object implementing . /// The paddable object instance. /// The right padding. /// The same instance so that multiple calls can be chained. public static T PadRight(this T obj, int right) where T : class, IPaddable { if (obj is null) { throw new ArgumentNullException(nameof(obj)); } return Padding(obj, new Padding(obj.Padding.GetLeftSafe(), obj.Padding.GetTopSafe(), right, obj.Padding.GetBottomSafe())); } /// /// Sets the bottom padding. /// /// An object implementing . /// The paddable object instance. /// The bottom padding. /// The same instance so that multiple calls can be chained. public static T PadBottom(this T obj, int bottom) where T : class, IPaddable { if (obj is null) { throw new ArgumentNullException(nameof(obj)); } return Padding(obj, new Padding(obj.Padding.GetLeftSafe(), obj.Padding.GetTopSafe(), obj.Padding.GetRightSafe(), bottom)); } /// /// Sets the left, top, right and bottom padding. /// /// An object implementing . /// The paddable object instance. /// The left padding to apply. /// The top padding to apply. /// The right padding to apply. /// The bottom padding to apply. /// The same instance so that multiple calls can be chained. public static T Padding(this T obj, int left, int top, int right, int bottom) where T : class, IPaddable { 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. /// /// An object implementing . /// The paddable object instance. /// The padding to apply. /// The same instance so that multiple calls can be chained. public static T Padding(this T obj, Padding padding) where T : class, IPaddable { if (obj is null) { throw new ArgumentNullException(nameof(obj)); } obj.Padding = padding; return obj; } }