add IsEmpty, Equals, ==, and != operators to Padding

This commit is contained in:
Michael Becker 2020-09-02 12:32:49 -04:00
parent 32b2eec3d1
commit 05888e5ec9
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7

View File

@ -7,6 +7,11 @@ namespace MBS.Framework.Drawing
{ {
public struct Padding public struct Padding
{ {
public static Padding Empty;
private bool _IsNotEmpty;
public bool IsEmpty { get { return !_IsNotEmpty; } }
private int mvarLeft; private int mvarLeft;
public int Left { get { return mvarLeft; } set { mvarLeft = value; } } public int Left { get { return mvarLeft; } set { mvarLeft = value; } }
private int mvarTop; private int mvarTop;
@ -16,6 +21,31 @@ namespace MBS.Framework.Drawing
private int mvarBottom; private int mvarBottom;
public int Bottom { get { return mvarBottom; } set { mvarBottom = value; } } public int Bottom { get { return mvarBottom; } set { mvarBottom = value; } }
public override bool Equals(object obj)
{
if (obj is Padding)
{
return (Padding)obj == this;
}
return false;
}
public static bool operator==(Padding left, Padding right)
{
return ((left.IsEmpty == right.IsEmpty)
&& (left.Left == right.Left)
&& (left.Right == right.Right)
&& (left.Top == right.Top)
&& (left.Bottom == right.Bottom));
}
public static bool operator !=(Padding left, Padding right)
{
return (!((left.IsEmpty == right.IsEmpty)
&& (left.Left == right.Left)
&& (left.Right == right.Right)
&& (left.Top == right.Top)
&& (left.Bottom == right.Bottom)));
}
public int All public int All
{ {
get get
@ -38,6 +68,7 @@ namespace MBS.Framework.Drawing
mvarLeft = all; mvarLeft = all;
mvarRight = all; mvarRight = all;
mvarTop = all; mvarTop = all;
_IsNotEmpty = true;
} }
public Padding(int top, int bottom, int left, int right) public Padding(int top, int bottom, int left, int right)
{ {
@ -45,6 +76,7 @@ namespace MBS.Framework.Drawing
mvarLeft = left; mvarLeft = left;
mvarRight = right; mvarRight = right;
mvarTop = top; mvarTop = top;
_IsNotEmpty = true;
} }
} }
} }