[NUI] Add ThemeManager (#2034)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Size.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.Binding;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// A three-dimensional size.
26     /// </summary>
27     /// <since_tizen> 5 </since_tizen>
28     [Tizen.NUI.Binding.TypeConverter(typeof(SizeTypeConverter))]
29     public class Size : Disposable, ICloneable
30     {
31
32         /// <summary>
33         /// The constructor.
34         /// </summary>
35         /// <remarks>
36         /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
37         /// For example, the followings are possible. <br />
38         /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
39         /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
40         /// view.MinimumSize = new Size(10, 10, 0); <br />
41         /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
42         /// </remarks>
43         /// <since_tizen> 5 </since_tizen>
44         public Size() : this(Interop.Vector3.new_Vector3__SWIG_0(), true)
45         {
46             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
47         }
48
49         /// <summary>
50         /// The constructor.
51         /// </summary>
52         /// <param name="width">The width component.</param>
53         /// <param name="height">The height component.</param>
54         /// <param name="depth">The depth component(optional).</param>
55         /// <remarks>
56         /// Size2D and Size are implicitly converted to each other, so these are compatible and can be replaced without any type casting. <br />
57         /// For example, the followings are possible. <br />
58         /// view.Size2D = new Size(10.0f, 10.0f, 10.0f); // be aware that here the depth value(10.0f) will be lost. <br />
59         /// view.Size = new Size2D(10, 10); // be aware that here the depth value is 0.0f by default. <br />
60         /// view.MinimumSize = new Size(10, 10, 0); <br />
61         /// Size Tmp = view.MaximumSize; //here Tmp.Depth will be 0.0f. <br />
62         /// </remarks>
63         /// <since_tizen> 5 </since_tizen>
64         public Size(float width, float height, float depth = 0.0f) : this(Interop.Vector3.new_Vector3__SWIG_1(width, height, depth), true)
65         {
66             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
67         }
68
69         /// <summary>
70         /// The constructor.
71         /// </summary>
72         /// <param name="size2d">Size2D with width and height.</param>
73         /// <since_tizen> 5 </since_tizen>
74         public Size(Size2D size2d) : this(Interop.Vector3.new_Vector3__SWIG_3(Size2D.getCPtr(size2d)), true)
75         {
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77         }
78
79         /// <summary>
80         /// The Zero constant, (0.0f, 0.0f, 0.0f).
81         /// </summary>
82         /// <since_tizen> 5 </since_tizen>
83         public static Size Zero
84         {
85             get
86             {
87                 global::System.IntPtr cPtr = Interop.Vector3.Vector3_ZERO_get();
88                 Size ret = (cPtr == global::System.IntPtr.Zero) ? null : new Size(cPtr, false);
89                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90                 return ret;
91             }
92         }
93
94         /// <summary>
95         /// The Width property for the width component of size
96         /// </summary>
97         /// <since_tizen> 5 </since_tizen>
98         [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size(...) constructor")]
99         public float Width
100         {
101             set
102             {
103                 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size(...) constructor");
104
105                 Interop.Vector3.Vector3_Width_set(swigCPtr, value);
106                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107
108                 callback?.Invoke(value, null, null);
109             }
110             get
111             {
112                 float ret = Interop.Vector3.Vector3_Width_get(swigCPtr);
113                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114                 return ret;
115             }
116         }
117
118         /// <summary>
119         /// The Height property for the height component of size.
120         /// </summary>
121         /// <since_tizen> 5 </since_tizen>
122         [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size(...) constructor")]
123         public float Height
124         {
125             set
126             {
127                 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size(...) constructor");
128
129                 Interop.Vector3.Vector3_Height_set(swigCPtr, value);
130                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131
132                 callback?.Invoke(null, value, null);
133             }
134             get
135             {
136                 float ret = Interop.Vector3.Vector3_Height_get(swigCPtr);
137                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138                 return ret;
139             }
140         }
141
142         /// <summary>
143         /// The Depth property for the depth component of size.
144         /// </summary>
145         /// <since_tizen> 5 </since_tizen>
146         [Obsolete("Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size(...) constructor")]
147         public float Depth
148         {
149             set
150             {
151                 Tizen.Log.Fatal("NUI", "Please do not use this setter, Deprecated in API8, will be removed in API10. please use new Size(...) constructor");
152                 
153                 Interop.Vector3.Vector3_Depth_set(swigCPtr, value);
154                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155
156                 callback?.Invoke(null, null, value);
157             }
158             get
159             {
160                 float ret = Interop.Vector3.Vector3_Depth_get(swigCPtr);
161                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162                 return ret;
163             }
164         }
165
166         /// <summary>
167         /// The addition operator for A+B.
168         /// </summary>
169         /// <param name="arg1">Size to assign A.</param>
170         /// <param name="arg2">Size to assign B.</param>
171         /// <returns>A size containing the result of the addition.</returns>
172         /// <since_tizen> 5 </since_tizen>
173         public static Size operator +(Size arg1, Size arg2)
174         {
175             return arg1.Add(arg2);
176         }
177
178         /// <summary>
179         /// The subtraction operator for A-B.
180         /// </summary>
181         /// <param name="arg1">Size to subtract A.</param>
182         /// <param name="arg2">Size to subtract B.</param>
183         /// <returns>The size containing the result of the subtraction.</returns>
184         /// <since_tizen> 5 </since_tizen>
185         public static Size operator -(Size arg1, Size arg2)
186         {
187             return arg1.Subtract(arg2);
188         }
189
190         /// <summary>
191         /// The unary negation operator.
192         /// </summary>
193         /// <param name="arg1">Size for unary negation.</param>
194         /// <returns>A size containing the negation.</returns>
195         /// <since_tizen> 5 </since_tizen>
196         public static Size operator -(Size arg1)
197         {
198             return arg1.Subtract();
199         }
200
201         /// <summary>
202         /// The multiplication operator.
203         /// </summary>
204         /// <param name="arg1">Size for multiplication.</param>
205         /// <param name="arg2">The size to multiply.</param>
206         /// <returns>A size containing the result of the multiplication.</returns>
207         /// <since_tizen> 5 </since_tizen>
208         public static Size operator *(Size arg1, Size arg2)
209         {
210             return arg1.Multiply(arg2);
211         }
212
213         /// <summary>
214         /// The multiplication operator.
215         /// </summary>
216         /// <param name="arg1">Size for multiplication.</param>
217         /// <param name="arg2">The float value to scale the size.</param>
218         /// <returns>A size containing the result of the scaling.</returns>
219         /// <since_tizen> 5 </since_tizen>
220         public static Size operator *(Size arg1, float arg2)
221         {
222             return arg1.Multiply(arg2);
223         }
224
225         /// <summary>
226         /// The division operator.
227         /// </summary>
228         /// <param name="arg1">Size for division.</param>
229         /// <param name="arg2">The size to divide.</param>
230         /// <returns>A size containing the result of the division.</returns>
231         /// <since_tizen> 5 </since_tizen>
232         public static Size operator /(Size arg1, Size arg2)
233         {
234             return arg1.Divide(arg2);
235         }
236
237         /// <summary>
238         /// The division operator.
239         /// </summary>
240         /// <param name="arg1">Size for division.</param>
241         /// <param name="arg2">The float value to scale the size by.</param>
242         /// <returns>A Size containing the result of the scaling.</returns>
243         /// <since_tizen> 5 </since_tizen>
244         public static Size operator /(Size arg1, float arg2)
245         {
246             return arg1.Divide(arg2);
247         }
248
249         /// <summary>
250         /// The array subscript operator.
251         /// </summary>
252         /// <param name="index">Subscript index.</param>
253         /// <returns>The float at the given index.</returns>
254         /// <since_tizen> 5 </since_tizen>
255         public float this[uint index]
256         {
257             get
258             {
259                 return ValueOfIndex(index);
260             }
261         }
262
263         /// <summary>
264         /// Determines whether the specified object is equal to the current object.
265         /// </summary>
266         /// <param name="obj">The object to compare with the current object.</param>
267         /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
268         public override bool Equals(System.Object obj)
269         {
270             Size size = obj as Size;
271             bool equal = false;
272             if (Width == size?.Width && Height == size?.Height && Depth == size?.Depth)
273             {
274                 equal = true;
275             }
276             return equal;
277         }
278
279         /// <summary>
280         /// Gets the the hash code of this Size.
281         /// </summary>
282         /// <returns>The Hash Code.</returns>
283         /// <since_tizen> 6 </since_tizen>
284         public override int GetHashCode()
285         {
286             return swigCPtr.Handle.GetHashCode();
287         }
288
289         /// <summary>
290         /// Checks equality.<br />
291         /// Utilizes appropriate machine epsilon values.<br />
292         /// </summary>
293         /// <param name="rhs">The size to test against.</param>
294         /// <returns>True if the sizes are equal.</returns>
295         /// <since_tizen> 5 </since_tizen>
296         public bool EqualTo(Size rhs)
297         {
298             bool ret = Interop.Vector3.Vector3_EqualTo(swigCPtr, Size.getCPtr(rhs));
299             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300             return ret;
301         }
302
303         /// <summary>
304         /// Checks inequality.<br />
305         /// Utilizes appropriate machine epsilon values.<br />
306         /// </summary>
307         /// <param name="rhs">The size to test against.</param>
308         /// <returns>True if the sizes are not equal.</returns>
309         /// <since_tizen> 5 </since_tizen>
310         public bool NotEqualTo(Size rhs)
311         {
312             bool ret = Interop.Vector3.Vector3_NotEqualTo(swigCPtr, Size.getCPtr(rhs));
313             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314             return ret;
315         }
316
317         /// <inheritdoc/>
318         [EditorBrowsable(EditorBrowsableState.Never)]
319         public object Clone() => new Size(Width, Height, Depth);
320
321         /// <summary>
322         /// The type cast operator, Size to Vector3.
323         /// </summary>
324         /// <param name="size">The object of size type.</param>
325         /// <since_tizen> 5 </since_tizen>
326         public static implicit operator Vector3(Size size)
327         {
328             return new Vector3(size.Width, size.Height, size.Depth);
329         }
330
331         /// <summary>
332         /// The type cast operator, Vector3 to Size type.
333         /// </summary>
334         /// <param name="vec">The object of Vector3 type.</param>
335         /// <since_tizen> 5 </since_tizen>
336         public static implicit operator Size(Vector3 vec)
337         {
338             return new Size(vec.Width, vec.Height, vec.Depth);
339         }
340
341         /// <summary>
342         /// Implicit type cast operator, Size2D to Size
343         /// </summary>
344         /// <param name="size2d">The object of Size2D type.</param>
345         /// <since_tizen> none </since_tizen>
346         /// This will be public opened in tizen_next by ACR.
347         [EditorBrowsable(EditorBrowsableState.Never)]
348         public static implicit operator Size(Size2D size2d)
349         {
350             return new Size(size2d.Width, size2d.Height, 0);
351         }
352         
353
354         internal static Size GetSizeFromPtr(global::System.IntPtr cPtr)
355         {
356             Size ret = new Size(cPtr, false);
357             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358             return ret;
359         }
360
361         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size obj)
362         {
363             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
364         }
365
366         internal Size(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
367         {
368         }
369
370         /// This will not be public opened.
371         [EditorBrowsable(EditorBrowsableState.Never)]
372         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
373         {
374             Interop.Vector3.delete_Vector3(swigCPtr);
375         }
376
377         private Size Add(Size rhs)
378         {
379             Size ret = new Size(Interop.Vector3.Vector3_Add(swigCPtr, Size.getCPtr(rhs)), true);
380             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381             return ret;
382         }
383
384         private Size Subtract(Size rhs)
385         {
386             Size ret = new Size(Interop.Vector3.Vector3_Subtract__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
387             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388             return ret;
389         }
390
391         private Size Multiply(Size rhs)
392         {
393             Size ret = new Size(Interop.Vector3.Vector3_Multiply__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
394             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
395             return ret;
396         }
397
398         private Size Multiply(float rhs)
399         {
400             Size ret = new Size(Interop.Vector3.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
401             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
402             return ret;
403         }
404
405         private Size Divide(Size rhs)
406         {
407             Size ret = new Size(Interop.Vector3.Vector3_Divide__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
408             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409             return ret;
410         }
411
412         private Size Divide(float rhs)
413         {
414             Size ret = new Size(Interop.Vector3.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
415             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
416             return ret;
417         }
418
419         private Size Subtract()
420         {
421             Size ret = new Size(Interop.Vector3.Vector3_Subtract__SWIG_1(swigCPtr), true);
422             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
423             return ret;
424         }
425
426         private float ValueOfIndex(uint index)
427         {
428             float ret = Interop.Vector3.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
429             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
430             return ret;
431         }
432
433         internal delegate void SizeChangedCallback(float? width, float? height, float? depth);
434
435         internal Size(SizeChangedCallback cb, float w, float h, float d) : this(Interop.Vector3.new_Vector3__SWIG_1(w, h, d), true)
436         {
437             callback = cb;
438             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
439         }
440
441         internal Size(SizeChangedCallback cb, Size other) : this(cb, other.Width, other.Height, other.Depth)
442         {
443         }
444
445         private SizeChangedCallback callback = null;
446     }
447 }
448