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 internal struct LayoutLength
32 /// [Draft] Constructor from an int
34 /// <param name="value">Int to initialize with.</param>
35 public LayoutLength(int value)
41 /// [Draft] Constructor from a float
43 /// <param name="value">Float to initialize with.</param>
44 public LayoutLength(float value)
50 /// [Draft] Constructor from a LayoutLength
52 /// <param name="layoutLength">LayoutLength object to initialize with.</param>
53 public LayoutLength(LayoutLength layoutLength)
55 _value = layoutLength._value;
59 /// [Draft] Return value as rounded value (whole number), best used as final output
61 /// <returns>The layout length value as a rounded whole number.</returns>
62 public float AsRoundedValue()
64 return (float)Math.Round((decimal)_value, MidpointRounding.AwayFromZero);
68 /// [Draft] Return value as the raw decimal value, best used for calculations
70 /// <returns>The layout length value as the raw decimal value.</returns>
71 public float AsDecimal()
77 /// [Draft] The == operator.
79 /// <param name="arg1">The first value.</param>
80 /// <param name="arg2">The second value</param>
81 /// <returns>true if LayoutLengths are equal</returns>
82 public static bool operator ==(LayoutLength arg1, LayoutLength arg2)
84 return arg1.Equals(arg2);
88 /// [Draft] The != operator.
90 /// <param name="arg1">The first value.</param>
91 /// <param name="arg2">The second value</param>
92 /// <returns>true if LayoutLengths are not equal</returns>
93 public static bool operator !=(LayoutLength arg1, LayoutLength arg2)
95 return !arg1.Equals(arg2);
99 /// Determines whether the specified object is equal to the current object.
101 /// <param name="obj">The object to compare with the current object.</param>
102 /// <returns>true if equal LayoutLength, else false.</returns>
103 public override bool Equals(object obj)
105 if (obj is LayoutLength)
107 return this.Equals((LayoutLength)obj);
113 /// Determines whether the specified object is equal to the current object.
115 /// <param name="layoutLength">The LayoutLength to compare with the current LayoutLength.</param>
116 /// <returns>true if equal LayoutLengths, else false.</returns>
117 public bool Equals(LayoutLength layoutLength)
119 return (Math.Abs(_value - layoutLength._value ) <= float.Epsilon);
123 /// A hash code for the current object.
125 public override int GetHashCode()
127 return (int)Math.Ceiling(_value);
131 /// The addition operator.
133 /// <param name="arg1">The first value.</param>
134 /// <param name="arg2">The second value.</param>
135 /// <returns>The LayoutLength containing the result of the addition.</returns>
136 public static LayoutLength operator +(LayoutLength arg1, LayoutLength arg2)
138 return new LayoutLength( arg1._value + arg2._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 public static LayoutLength operator +(LayoutLength arg1, int arg2)
149 return new LayoutLength(arg1._value + (float)arg2);
153 /// The subtraction operator.
155 /// <param name="arg1">The first value.</param>
156 /// <param name="arg2">The second value.</param>
157 /// <returns>The LayoutLength containing the result of the subtraction.</returns>
158 public static LayoutLength operator -(LayoutLength arg1, LayoutLength arg2)
160 return new LayoutLength(arg1._value - arg2._value);
164 /// The subtraction operator.
166 /// <param name="arg1">The first value.</param>
167 /// <param name="arg2">The second value.</param>
168 /// <returns>The LayoutLength containing the result of the subtraction.</returns>
169 public static LayoutLength operator -(LayoutLength arg1, int arg2)
171 return new LayoutLength(arg1._value - (float)arg2);
175 /// The multiplication operator.
177 /// <param name="arg1">The first value.</param>
178 /// <param name="arg2">The second value.</param>
179 /// <returns>The LayoutLength containing the result of the multiplication.</returns>
180 public static LayoutLength operator *(LayoutLength arg1, LayoutLength arg2)
182 return new LayoutLength(arg1._value * arg2._value);
186 /// Th multiplication operator.
188 /// <param name="arg1">The first value.</param>
189 /// <param name="arg2">The int value to scale the LayoutLength.</param>
190 /// <returns>The LayoutLength containing the result of the scaling.</returns>
191 public static LayoutLength operator *(LayoutLength arg1, int arg2)
193 return new LayoutLength(arg1._value * arg2);
197 /// The division operator.
199 /// <param name="arg1">The first value.</param>
200 /// <param name="arg2">The second value.</param>
201 /// <returns>The LayoutLength containing the result of the division.</returns>
202 public static LayoutLength operator /(LayoutLength arg1, LayoutLength arg2)
204 return new LayoutLength(arg1._value / arg2._value);
208 /// Th division operator.
210 /// <param name="arg1">The first value.</param>
211 /// <param name="arg2">The int value to scale the vector by.</param>
212 /// <returns>The LayoutLength containing the result of the scaling.</returns>
213 public static LayoutLength operator /(LayoutLength arg1, int arg2)
215 return new LayoutLength(arg1._value / (float)arg2);