summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core/GridLength.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 13:02:25 -0700
committerJason Smith <jason.smith@xamarin.com>2016-03-22 16:13:41 -0700
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Core/GridLength.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
Initial import
Diffstat (limited to 'Xamarin.Forms.Core/GridLength.cs')
-rw-r--r--Xamarin.Forms.Core/GridLength.cs74
1 files changed, 74 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/GridLength.cs b/Xamarin.Forms.Core/GridLength.cs
new file mode 100644
index 00000000..5d569d08
--- /dev/null
+++ b/Xamarin.Forms.Core/GridLength.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Diagnostics;
+
+namespace Xamarin.Forms
+{
+ [TypeConverter(typeof(GridLengthTypeConverter))]
+ [DebuggerDisplay("{Value}.{GridUnitType}")]
+ public struct GridLength
+ {
+ public static GridLength Auto
+ {
+ get { return new GridLength(1, GridUnitType.Auto); }
+ }
+
+ public double Value { get; }
+
+ public GridUnitType GridUnitType { get; }
+
+ public bool IsAbsolute
+ {
+ get { return GridUnitType == GridUnitType.Absolute; }
+ }
+
+ public bool IsAuto
+ {
+ get { return GridUnitType == GridUnitType.Auto; }
+ }
+
+ public bool IsStar
+ {
+ get { return GridUnitType == GridUnitType.Star; }
+ }
+
+ public GridLength(double value) : this(value, GridUnitType.Absolute)
+ {
+ }
+
+ public GridLength(double value, GridUnitType type)
+ {
+ if (value < 0 || double.IsNaN(value))
+ throw new ArgumentException("value is less than 0 or is not a number", "value");
+ if ((int)type < (int)GridUnitType.Absolute || (int)type > (int)GridUnitType.Auto)
+ throw new ArgumentException("type is not a valid GridUnitType", "type");
+
+ Value = value;
+ GridUnitType = type;
+ }
+
+ public override bool Equals(object obj)
+ {
+ return obj != null && obj is GridLength && Equals((GridLength)obj);
+ }
+
+ bool Equals(GridLength other)
+ {
+ return GridUnitType == other.GridUnitType && Math.Abs(Value - other.Value) < double.Epsilon;
+ }
+
+ public override int GetHashCode()
+ {
+ return GridUnitType.GetHashCode() * 397 ^ Value.GetHashCode();
+ }
+
+ public static implicit operator GridLength(double absoluteValue)
+ {
+ return new GridLength(absoluteValue);
+ }
+
+ public override string ToString()
+ {
+ return string.Format("{0}.{1}", Value, GridUnitType);
+ }
+ }
+} \ No newline at end of file