Browse Source

Add equality comparison support for most common Dims (#278)

Specifically factor, fill and absolute now support making comparisons.
Daniel Cazzulino 5 years ago
parent
commit
369e305871
1 changed files with 15 additions and 1 deletions
  1. 15 1
      Terminal.Gui/Types/PosDim.cs

+ 15 - 1
Terminal.Gui/Types/PosDim.cs

@@ -311,6 +311,11 @@ namespace Terminal.Gui {
 			{
 			{
 				return $"Dim.Factor({factor})";
 				return $"Dim.Factor({factor})";
 			}
 			}
+
+			public override int GetHashCode () => factor.GetHashCode();
+
+			public override bool Equals (object other) => other is DimFactor f && f.factor == factor;
+
 		}
 		}
 
 
 		/// <summary>
 		/// <summary>
@@ -339,6 +344,11 @@ namespace Terminal.Gui {
 			{
 			{
 				return n;
 				return n;
 			}
 			}
+
+			public override int GetHashCode () => n.GetHashCode();
+
+			public override bool Equals (object other) => other is DimAbsolute abs && abs.n == n;
+
 		}
 		}
 
 
 		class DimFill : Dim {
 		class DimFill : Dim {
@@ -353,7 +363,11 @@ namespace Terminal.Gui {
 			internal override int Anchor (int width)
 			internal override int Anchor (int width)
 			{
 			{
 				return width-margin;
 				return width-margin;
-			}			
+			}
+
+			public override int GetHashCode () => margin.GetHashCode();
+
+			public override bool Equals (object other) => other is DimFill fill && fill.margin == margin;
 		}
 		}
 
 
 		static DimFill zeroMargin;
 		static DimFill zeroMargin;