42355a7cc8de9c05eb2712d78ed7f0154009d522
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Layouting / FlexLayout.cs
1 /* Copyright (c) 2018 Samsung Electronics Co., Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  */
16 using System.ComponentModel;
17
18 namespace Tizen.NUI
19 {
20     /// <summary>
21     /// [Draft] This class implements a flex layout.
22     /// The flex layout implementation is based on open source Facebook Yoga layout engine.
23     /// For more information about the flex layout API and how to use it please refer to https://yogalayout.com/docs/
24     /// We implement the subset of the API in the class below.
25     /// </summary>
26     internal class FlexLayout : LayoutGroupWrapper
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29
30         internal FlexLayout(global::System.IntPtr cPtr, bool cMemoryOwn) : base(LayoutPINVOKE.FlexLayout_SWIGUpcast(cPtr), cMemoryOwn)
31         {
32             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
33         }
34
35         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FlexLayout obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40         protected override void Dispose(DisposeTypes type)
41         {
42             if (disposed)
43             {
44                 return;
45             }
46
47             if (type == DisposeTypes.Explicit)
48             {
49                 //Called by User
50                 //Release your own managed resources here.
51                 //You should release all of your own disposable objects here.
52
53             }
54
55             //Release your own unmanaged resources here.
56             //You should not access any managed member here except static instance.
57             //because the execution order of Finalizes is non-deterministic.
58             if (swigCPtr.Handle != global::System.IntPtr.Zero)
59             {
60                 if (swigCMemOwn)
61                 {
62                     swigCMemOwn = false;
63                     LayoutPINVOKE.delete_FlexLayout(swigCPtr);
64                 }
65                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
66             }
67             base.Dispose(type);
68         }
69
70         /// <summary>
71         /// [Draft] Creates a FlexLayout object.
72         /// </summary>
73         public FlexLayout() : this(LayoutPINVOKE.FlexLayout_New(), true)
74         {
75             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
76         }
77
78         internal static FlexLayout DownCast(BaseHandle handle)
79         {
80             FlexLayout ret = new FlexLayout(LayoutPINVOKE.FlexLayout_DownCast(BaseHandle.getCPtr(handle)), true);
81             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
82             return ret;
83         }
84
85         internal FlexLayout(FlexLayout other) : this(LayoutPINVOKE.new_FlexLayout__SWIG_1(FlexLayout.getCPtr(other)), true)
86         {
87             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88         }
89
90         internal FlexLayout Assign(FlexLayout other)
91         {
92             FlexLayout ret = new FlexLayout(LayoutPINVOKE.FlexLayout_Assign(swigCPtr, FlexLayout.getCPtr(other)), false);
93             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
94             return ret;
95         }
96
97         internal void SetFlexDirection(FlexLayout.FlexDirection flexDirection)
98         {
99             LayoutPINVOKE.FlexLayout_SetFlexDirection(swigCPtr, (int)flexDirection);
100             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
101         }
102
103         internal FlexLayout.FlexDirection GetFlexDirection()
104         {
105             FlexLayout.FlexDirection ret = (FlexLayout.FlexDirection)LayoutPINVOKE.FlexLayout_GetFlexDirection(swigCPtr);
106             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107             return ret;
108         }
109
110         internal void SetFlexJustification(FlexLayout.FlexJustification flexJustification)
111         {
112             LayoutPINVOKE.FlexLayout_SetFlexJustification(swigCPtr, (int)flexJustification);
113             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114         }
115
116         internal FlexLayout.FlexJustification GetFlexJustification()
117         {
118             FlexLayout.FlexJustification ret = (FlexLayout.FlexJustification)LayoutPINVOKE.FlexLayout_GetFlexJustification(swigCPtr);
119             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120             return ret;
121         }
122
123         internal void SetFlexWrap(FlexLayout.FlexWrapType flexWrap)
124         {
125             LayoutPINVOKE.FlexLayout_SetFlexWrap(swigCPtr, (int)flexWrap);
126             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127         }
128
129         internal FlexLayout.FlexWrapType GetFlexWrap()
130         {
131             FlexLayout.FlexWrapType ret = (FlexLayout.FlexWrapType)LayoutPINVOKE.FlexLayout_GetFlexWrap(swigCPtr);
132             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133             return ret;
134         }
135
136         internal void SetFlexAlignment(FlexLayout.AlignmentType flexAlignment)
137         {
138             LayoutPINVOKE.FlexLayout_SetFlexAlignment(swigCPtr, (int)flexAlignment);
139             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140         }
141
142         internal FlexLayout.AlignmentType GetFlexAlignment()
143         {
144             FlexLayout.AlignmentType ret = (FlexLayout.AlignmentType)LayoutPINVOKE.FlexLayout_GetFlexAlignment(swigCPtr);
145             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146             return ret;
147         }
148
149         internal void SetFlexItemsAlignment(FlexLayout.AlignmentType flexAlignment)
150         {
151             LayoutPINVOKE.FlexLayout_SetFlexItemsAlignment(swigCPtr, (int)flexAlignment);
152             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153         }
154
155         internal FlexLayout.AlignmentType GetFlexItemsAlignment()
156         {
157             FlexLayout.AlignmentType ret = (FlexLayout.AlignmentType)LayoutPINVOKE.FlexLayout_GetFlexItemsAlignment(swigCPtr);
158             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159             return ret;
160         }
161
162         internal enum PropertyRange
163         {
164             CHILD_PROPERTY_START_INDEX = PropertyRanges.CHILD_PROPERTY_REGISTRATION_START_INDEX,
165             CHILD_PROPERTY_END_INDEX = PropertyRanges.CHILD_PROPERTY_REGISTRATION_START_INDEX + 1000
166         }
167
168         internal new class ChildProperty
169         {
170             internal static readonly int FLEX = LayoutPINVOKE.FlexLayout_ChildProperty_FLEX_get();
171             internal static readonly int ALIGN_SELF = LayoutPINVOKE.FlexLayout_ChildProperty_ALIGN_SELF_get();
172         }
173
174         /// <summary>
175         /// [Draft] Get/Set the flex direction in the layout.
176         /// The direction of the main-axis which determines the direction that flex items are laid out.
177         /// </summary>
178         public FlexDirection Direction
179         {
180             get
181             {
182                 return GetFlexDirection();
183             }
184             set
185             {
186                 SetFlexDirection(value);
187             }
188         }
189
190         /// <summary>
191         /// [Draft] Get/Set the justification in the layout.
192         /// </summary>
193         public FlexJustification Justification
194         {
195             get
196             {
197                 return GetFlexJustification();
198             }
199             set
200             {
201                 SetFlexJustification(value);
202             }
203         }
204
205         /// <summary>
206         /// [Draft] Get/Set the wrap in the layout.
207         /// </summary>
208         public FlexWrapType WrapType
209         {
210             get
211             {
212                 return GetFlexWrap();
213             }
214             set
215             {
216                 SetFlexWrap(value);
217             }
218         }
219
220         /// <summary>
221         /// [Draft] Get/Set the alignment of the layout content.
222         /// </summary>
223         public AlignmentType Alignment
224         {
225             get
226             {
227                 return GetFlexAlignment();
228             }
229             set
230             {
231                 SetFlexAlignment(value);
232             }
233         }
234
235         /// <summary>
236         /// [Draft] Get/Set the alignment of the layout items.
237         /// </summary>
238         public AlignmentType ItemsAlignment
239         {
240             get
241             {
242                 return GetFlexItemsAlignment();
243             }
244             set
245             {
246                 SetFlexItemsAlignment(value);
247             }
248         }
249
250         /// <summary>
251         /// [Draft] Enumeration for the direction of the main axis in the flex container.
252         /// This determines the direction that flex items are laid out in the flex container.
253         /// </summary>
254         public enum FlexDirection
255         {
256             /// <summary>
257             /// The flexible items are displayed vertically as a column
258             /// </summary>
259             Column,
260             /// <summary>
261             /// The flexible items are displayed vertically as a column, but in reverse order
262             /// </summary>
263             ColumnReverse,
264             /// <summary>
265             /// The flexible items are displayed horizontally as a row
266             /// </summary>
267             Row,
268             /// <summary>
269             /// The flexible items are displayed horizontally as a row, but in reverse order
270             /// </summary>
271             RowReverse
272         }
273
274         /// <summary>
275         /// [Draft] Enumeration for the alignment of the flex items when the items do not use all available space on the main-axis.
276         /// </summary>
277         public enum FlexJustification
278         {
279             /// <summary>
280             /// Items are positioned at the beginning of the container
281             /// </summary>
282             FlexStart,
283             /// <summary>
284             /// Items are positioned at the center of the container
285             /// </summary>
286             Center,
287             /// <summary>
288             /// Items are positioned at the end of the container
289             /// </summary>
290             FlexEnd,
291             /// <summary>
292             /// Items are positioned with equal space between the lines
293             /// </summary>
294             SpaceBetween,
295             /// <summary>
296             /// Items are positioned with equal space before, between, and after the lines
297             /// </summary>
298             SpaceAround
299         }
300
301         /// <summary>
302         /// [Draft] Enumeration for the wrap type of the flex container when there is no enough room for all the items on one flex line.
303         /// </summary>
304         public enum FlexWrapType
305         {
306             /// <summary>
307             /// Flex items laid out in single line (shrunk to fit the flex container along the main axis)
308             /// </summary>
309             NoWrap,
310             /// <summary>
311             /// Flex items laid out in multiple lines if needed
312             /// </summary>
313             Wrap
314         }
315
316         /// <summary>
317         /// [Draft] Enumeration for the alignment of the flex items or lines when the items or lines do not use all the available space on the cross-axis.
318         /// </summary>
319         public enum AlignmentType
320         {
321             /// <summary>
322             /// Inherits the same alignment from the parent (only valid for "alignSelf" property)
323             /// </summary>
324             Auto,
325             /// <summary>
326             /// At the beginning of the container
327             /// </summary>
328             FlexStart,
329             /// <summary>
330             /// At the center of the container
331             /// </summary>
332             Center,
333             /// <summary>
334             /// At the end of the container
335             /// </summary>
336             FlexEnd,
337             /// <summary>
338             /// Stretch to fit the container
339             /// </summary>
340             Stretch
341         }
342     }
343 }