[WiFi] Remove ArgumentException (2) (#322)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / XamlBinding / Thickness.cs
1 using System.Diagnostics;
2 using System.ComponentModel;
3
4 namespace Tizen.NUI.Binding
5 {
6     /// <summary>
7     /// Struct defining thickness around the edges of a Rectangle using doubles.
8     /// </summary>
9         [DebuggerDisplay("Left={Left}, Top={Top}, Right={Right}, Bottom={Bottom}, HorizontalThickness={HorizontalThickness}, VerticalThickness={VerticalThickness}")]
10         [TypeConverter(typeof(ThicknessTypeConverter))]
11     [EditorBrowsable(EditorBrowsableState.Never)]
12     public struct Thickness
13         {
14         /// <summary>
15         /// The thickness of the left side of a rectangle.
16         /// </summary>
17                 public double Left { get; set; }
18
19         /// <summary>
20         /// The thickness of the top of a rectangle.
21         /// </summary>
22                 public double Top { get; set; }
23
24         /// <summary>
25         /// The thickness of the right side of a rectangle.
26         /// </summary>
27                 public double Right { get; set; }
28
29         /// <summary>
30         /// The thickness of the bottom of a rectangle.
31         /// </summary>
32                 public double Bottom { get; set; }
33
34         /// <summary>
35         /// The sum of Left and Right.
36         /// </summary>
37                 public double HorizontalThickness
38                 {
39                         get { return Left + Right; }
40                 }
41
42         /// <summary>
43         /// The sum of Top and Bottom.
44         /// </summary>
45                 public double VerticalThickness
46                 {
47                         get { return Top + Bottom; }
48                 }
49
50                 internal bool IsDefault
51                 {
52                         get { return Left == 0 && Top == 0 && Right == 0 && Bottom == 0; }
53                 }
54
55         /// <summary>
56         /// Creates a new Thickness object that represents a uniform thickness of size uniformSize.
57         /// </summary>
58         /// <param name="uniformSize">The uniform size of all edges in the new thickness.</param>
59                 public Thickness(double uniformSize) : this(uniformSize, uniformSize, uniformSize, uniformSize)
60                 {
61                 }
62
63         /// <summary>
64         /// Creates a new Thickness object that has a horizontal thickness of horizontalSize and a vertical thickness of verticalSize.
65         /// </summary>
66         /// <param name="horizontalSize">The width of the left and right thicknesses.</param>
67         /// <param name="verticalSize">The height of the top and bottom thicknesses.</param>
68                 public Thickness(double horizontalSize, double verticalSize) : this(horizontalSize, verticalSize, horizontalSize, verticalSize)
69                 {
70                 }
71
72         /// <summary>
73         /// Creates a new Thickness object with thicknesses defined by left, top, right, and bottom.
74         /// </summary>
75         /// <param name="left">The width of the left thickness.</param>
76         /// <param name="top">The height of the top thickness.</param>
77         /// <param name="right">The width of the right thickness.</param>
78         /// <param name="bottom">The height of the bottom thickness.</param>
79                 public Thickness(double left, double top, double right, double bottom) : this()
80                 {
81                         Left = left;
82                         Top = top;
83                         Right = right;
84                         Bottom = bottom;
85                 }
86
87         /// <summary>
88         /// Converts a Size into a Thickness.
89         /// </summary>
90         /// <param name="size">A Size to convert to a Thickness</param>
91                 public static implicit operator Thickness(Size size)
92                 {
93                         return new Thickness(size.Width, size.Height, size.Width, size.Height);
94                 }
95
96         /// <summary>
97         /// Implicit cast operator from Double.
98         /// </summary>
99         /// <param name="uniformSize">The value for the uniform Thickness.</param>
100                 public static implicit operator Thickness(double uniformSize)
101                 {
102                         return new Thickness(uniformSize);
103                 }
104
105         /// <summary>
106         /// Whether the other has equivalent values.
107         /// </summary>
108         /// <param name="other">A Thickness to be compared.</param>
109         /// <returns>true if other has equivalent values.</returns>
110                 bool Equals(Thickness other)
111                 {
112                         return Left.Equals(other.Left) && Top.Equals(other.Top) && Right.Equals(other.Right) && Bottom.Equals(other.Bottom);
113                 }
114
115         /// <summary>
116         /// Whether the obj has equivalent values.
117         /// </summary>
118         /// <param name="obj">A Thickness to be compared.</param>
119         /// <returns>true if obj is a Thickness and has equivalent values.</returns>
120                 public override bool Equals(object obj)
121                 {
122                         if (ReferenceEquals(null, obj))
123                                 return false;
124                         return obj is Thickness && Equals((Thickness)obj);
125                 }
126
127         /// <summary>
128         /// A hash value for this Thickness.
129         /// </summary>
130         /// <returns>The hash value</returns>
131                 public override int GetHashCode()
132                 {
133                         unchecked
134                         {
135                                 int hashCode = Left.GetHashCode();
136                                 hashCode = (hashCode * 397) ^ Top.GetHashCode();
137                                 hashCode = (hashCode * 397) ^ Right.GetHashCode();
138                                 hashCode = (hashCode * 397) ^ Bottom.GetHashCode();
139                                 return hashCode;
140                         }
141                 }
142
143         /// <summary>
144         /// Whether two Thicknesses have identical values.
145         /// </summary>
146         /// <param name="left">A Thickness to be compared.</param>
147         /// <param name="right">A Thickness to be compared.</param>
148         /// <returns>true if left and right have identical values for Left,Right, Top, and Bottom.</returns>
149                 public static bool operator ==(Thickness left, Thickness right)
150                 {
151                         return left.Equals(right);
152                 }
153
154         /// <summary>
155         /// Whether the values of two Thickness's have at least one difference.
156         /// </summary>
157         /// <param name="left">A Thickness to be compared.</param>
158         /// <param name="right">A Thickness to be compared.</param>
159         /// <returns>true if any of the Left,Right, Top, and Bottom values differ between left and right.</returns>
160                 public static bool operator !=(Thickness left, Thickness right)
161                 {
162                         return !left.Equals(right);
163                 }
164
165         /// <summary>
166         /// Stores the components of the thickness in the corresponding arguments.
167         /// </summary>
168         /// <param name="left">Variable in which to store the left thickness of thickness object.</param>
169         /// <param name="top">Variable in which to store the top thickness of thickness object.</param>
170         /// <param name="right">Variable in which to store the right thickness of thickness object.</param>
171         /// <param name="bottom">Variable in which to store the bottom thickness of thickness object.</param>
172                 public void Deconstruct(out double left, out double top, out double right, out double bottom)
173                 {
174                         left = Left;
175                         top = Top;
176                         right = Right;
177                         bottom = Bottom;
178                 }
179         }
180 }