2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
25 /// [Draft] A type that represents a layout length. Currently, this implies pixels, but could be extended to handle device dependant sizes, etc.
27 public struct LayoutLength
32 /// [Draft] Constructor from an int
34 /// <param name="value">Int to initialize with.</param>
35 /// <since_tizen> 6 </since_tizen>
36 public LayoutLength(int value)
42 /// [Draft] Constructor from a float
44 /// <param name="value">Float to initialize with.</param>
45 /// <since_tizen> 6 </since_tizen>
46 public LayoutLength(float value)
52 /// [Draft] Constructor from a LayoutLength
54 /// <param name="layoutLength">LayoutLength object to initialize with.</param>
55 /// <since_tizen> 6 </since_tizen>
56 public LayoutLength(LayoutLength layoutLength)
58 _value = layoutLength._value;
62 /// [Draft] Return value as rounded value (whole number), best used as final output
64 /// <returns>The layout length value as a rounded whole number.</returns>
65 /// <since_tizen> 6 </since_tizen>
66 public float AsRoundedValue()
68 return (float)Math.Round((decimal)_value, MidpointRounding.AwayFromZero);
72 /// [Draft] Return value as the raw decimal value, best used for calculations
74 /// <returns>The layout length value as the raw decimal value.</returns>
75 /// <since_tizen> 6 </since_tizen>
76 public float AsDecimal()
82 /// [Draft] The == operator.
84 /// <param name="arg1">The first value.</param>
85 /// <param name="arg2">The second value</param>
86 /// <returns>true if LayoutLengths are equal</returns>
87 /// <since_tizen> 6 </since_tizen>
88 public static bool operator ==(LayoutLength arg1, LayoutLength arg2)
90 return arg1.Equals(arg2);
94 /// [Draft] The != operator.
96 /// <param name="arg1">The first value.</param>
97 /// <param name="arg2">The second value</param>
98 /// <returns>true if LayoutLengths are not equal</returns>
99 /// <since_tizen> 6 </since_tizen>
100 public static bool operator !=(LayoutLength arg1, LayoutLength arg2)
102 return !arg1.Equals(arg2);
106 /// Determines whether the specified object is equal to the current object.
108 /// <param name="obj">The object to compare with the current object.</param>
109 /// <returns>true if equal LayoutLength, else false.</returns>
110 /// <since_tizen> 6 </since_tizen>
111 public override bool Equals(object obj)
113 if (obj is LayoutLength)
115 return this.Equals((LayoutLength)obj);
121 /// Determines whether the specified object is equal to the current object.
123 /// <param name="layoutLength">The LayoutLength to compare with the current LayoutLength.</param>
124 /// <returns>true if equal LayoutLengths, else false.</returns>
125 /// <since_tizen> 6 </since_tizen>
126 public bool Equals(LayoutLength layoutLength)
128 return (Math.Abs(_value - layoutLength._value) <= float.Epsilon);
132 /// A hash code for the current object.
134 /// <returns>Calculated hash code.</returns>
135 /// <since_tizen> 6 </since_tizen>
136 public override int GetHashCode()
138 return (int)Math.Ceiling(_value);
142 /// The addition operator.
144 /// <param name="arg1">The first value.</param>
145 /// <param name="arg2">The second value.</param>
146 /// <returns>The LayoutLength containing the result of the addition.</returns>
147 /// <since_tizen> 6 </since_tizen>
148 public static LayoutLength operator +(LayoutLength arg1, LayoutLength arg2)
150 return new LayoutLength(arg1._value + arg2._value);
154 /// The addition operator.
156 /// <param name="arg1">The first value.</param>
157 /// <param name="arg2">The second value.</param>
158 /// <returns>The LayoutLength containing the result of the addition.</returns>
159 /// <since_tizen> 6 </since_tizen>
160 public static LayoutLength operator +(LayoutLength arg1, int arg2)
162 return new LayoutLength(arg1._value + (float)arg2);
166 /// The subtraction operator.
168 /// <param name="arg1">The first value.</param>
169 /// <param name="arg2">The second value.</param>
170 /// <returns>The LayoutLength containing the result of the subtraction.</returns>
171 /// <since_tizen> 6 </since_tizen>
172 public static LayoutLength operator -(LayoutLength arg1, LayoutLength arg2)
174 return new LayoutLength(arg1._value - arg2._value);
178 /// The subtraction operator.
180 /// <param name="arg1">The first value.</param>
181 /// <param name="arg2">The second value.</param>
182 /// <returns>The LayoutLength containing the result of the subtraction.</returns>
183 /// <since_tizen> 6 </since_tizen>
184 public static LayoutLength operator -(LayoutLength arg1, int arg2)
186 return new LayoutLength(arg1._value - (float)arg2);
190 /// The multiplication operator.
192 /// <param name="arg1">The first value.</param>
193 /// <param name="arg2">The second value.</param>
194 /// <returns>The LayoutLength containing the result of the multiplication.</returns>
195 /// <since_tizen> 6 </since_tizen>
196 public static LayoutLength operator *(LayoutLength arg1, LayoutLength arg2)
198 return new LayoutLength(arg1._value * arg2._value);
202 /// Th multiplication operator.
204 /// <param name="arg1">The first value.</param>
205 /// <param name="arg2">The int value to scale the LayoutLength.</param>
206 /// <returns>The LayoutLength containing the result of the scaling.</returns>
207 /// <since_tizen> 6 </since_tizen>
208 public static LayoutLength operator *(LayoutLength arg1, int arg2)
210 return new LayoutLength(arg1._value * arg2);
214 /// The division operator.
216 /// <param name="arg1">The first value.</param>
217 /// <param name="arg2">The second value.</param>
218 /// <returns>The LayoutLength containing the result of the division.</returns>
219 /// <since_tizen> 6 </since_tizen>
220 public static LayoutLength operator /(LayoutLength arg1, LayoutLength arg2)
222 return new LayoutLength(arg1._value / arg2._value);
226 /// Th division operator.
228 /// <param name="arg1">The first value.</param>
229 /// <param name="arg2">The int value to scale the vector by.</param>
230 /// <returns>The LayoutLength containing the result of the scaling.</returns>
231 /// <since_tizen> 6 </since_tizen>
232 public static LayoutLength operator /(LayoutLength arg1, int arg2)
234 return new LayoutLength(arg1._value / (float)arg2);