Follow formatting NUI
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Layouting / LayoutLength.cs
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// [Draft] A type that represents a layout length. Currently, this implies pixels, but could be extended to handle device dependant sizes, etc.
26     /// </summary>
27     public struct LayoutLength
28     {
29         private float _value;
30
31         /// <summary>
32         /// [Draft] Constructor from an int
33         /// </summary>
34         /// <param name="value">Int to initialize with.</param>
35         /// <since_tizen> 6 </since_tizen>
36         public LayoutLength(int value)
37         {
38             _value = value;
39         }
40
41         /// <summary>
42         /// [Draft] Constructor from a float
43         /// </summary>
44         /// <param name="value">Float to initialize with.</param>
45         /// <since_tizen> 6 </since_tizen>
46         public LayoutLength(float value)
47         {
48             _value = value;
49         }
50
51         /// <summary>
52         /// [Draft] Constructor from a LayoutLength
53         /// </summary>
54         /// <param name="layoutLength">LayoutLength object to initialize with.</param>
55         /// <since_tizen> 6 </since_tizen>
56         public LayoutLength(LayoutLength layoutLength)
57         {
58             _value = layoutLength._value;
59         }
60
61         /// <summary>
62         /// [Draft] Return value as rounded value (whole number), best used as final output
63         /// </summary>
64         /// <returns>The layout length value as a rounded whole number.</returns>
65         /// <since_tizen> 6 </since_tizen>
66         public float AsRoundedValue()
67         {
68             return (float)Math.Round((decimal)_value, MidpointRounding.AwayFromZero);
69         }
70
71         /// <summary>
72         /// [Draft] Return value as the raw decimal value, best used for calculations
73         /// </summary>
74         /// <returns>The layout length value as the raw decimal value.</returns>
75         /// <since_tizen> 6 </since_tizen>
76         public float AsDecimal()
77         {
78             return _value;
79         }
80
81         /// <summary>
82         /// [Draft] The == operator.
83         /// </summary>
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)
89         {
90             return arg1.Equals(arg2);
91         }
92
93         /// <summary>
94         /// [Draft] The != operator.
95         /// </summary>
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)
101         {
102             return !arg1.Equals(arg2);
103         }
104
105         /// <summary>
106         /// Determines whether the specified object is equal to the current object.
107         /// </summary>
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)
112         {
113             if (obj is LayoutLength)
114             {
115                 return this.Equals((LayoutLength)obj);
116             }
117             return false;
118         }
119
120         /// <summary>
121         /// Determines whether the specified object is equal to the current object.
122         /// </summary>
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)
127         {
128             return (Math.Abs(_value - layoutLength._value) <= float.Epsilon);
129         }
130
131         /// <summary>
132         /// A hash code for the current object.
133         /// </summary>
134         /// <returns>Calculated hash code.</returns>
135         /// <since_tizen> 6 </since_tizen>
136         public override int GetHashCode()
137         {
138             return (int)Math.Ceiling(_value);
139         }
140
141         /// <summary>
142         /// The addition operator.
143         /// </summary>
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)
149         {
150             return new LayoutLength(arg1._value + arg2._value);
151         }
152
153         /// <summary>
154         /// The addition operator.
155         /// </summary>
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)
161         {
162             return new LayoutLength(arg1._value + (float)arg2);
163         }
164
165         /// <summary>
166         /// The subtraction operator.
167         /// </summary>
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)
173         {
174             return new LayoutLength(arg1._value - arg2._value);
175         }
176
177         /// <summary>
178         /// The subtraction operator.
179         /// </summary>
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)
185         {
186             return new LayoutLength(arg1._value - (float)arg2);
187         }
188
189         /// <summary>
190         /// The multiplication operator.
191         /// </summary>
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)
197         {
198             return new LayoutLength(arg1._value * arg2._value);
199         }
200
201         /// <summary>
202         /// Th multiplication operator.
203         /// </summary>
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)
209         {
210             return new LayoutLength(arg1._value * arg2);
211         }
212
213         /// <summary>
214         /// The division operator.
215         /// </summary>
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)
221         {
222             return new LayoutLength(arg1._value / arg2._value);
223         }
224
225         /// <summary>
226         /// Th division operator.
227         /// </summary>
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)
233         {
234             return new LayoutLength(arg1._value / (float)arg2);
235         }
236     }
237 }