7e0add4be99961a5c9da76d299a9d74b11ca46ef
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / FlexContainer.cs
1 /*
2  * Copyright(c) 2017 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 namespace Tizen.NUI.BaseComponents
19 {
20     /// <summary>
21     /// FlexContainer implements a subset of the flexbox spec (defined by W3C):https://www.w3.org/TR/css3-flexbox/<br />
22     /// It aims at providing a more efficient way to layout, align, and distribute space among items in the container, even when their size is unknown or dynamic.<br />
23     /// FlexContainer has the ability to alter the width and the height of its children (i.e., flex items) to fill the available space in the best possible way on different screen sizes.<br />
24     /// FlexContainer can expand items to fill available free space, or shrink them to prevent overflow.<br />
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class FlexContainer : View
28     {
29         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30
31         internal FlexContainer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.FlexContainer_SWIGUpcast(cPtr), cMemoryOwn)
32         {
33             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34         }
35
36         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FlexContainer obj)
37         {
38             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39         }
40
41         /// <summary>
42         /// To make the FlexContainer instance be disposed.
43         /// </summary>
44         /// <since_tizen> 3 </since_tizen>
45         protected override void Dispose(DisposeTypes type)
46         {
47             if(disposed)
48             {
49                 return;
50             }
51
52             if(type == DisposeTypes.Explicit)
53             {
54                 //Called by User
55                 //Release your own managed resources here.
56                 //You should release all of your own disposable objects here.
57             }
58
59             //Release your own unmanaged resources here.
60             //You should not access any managed member here except static instance.
61             //because the execution order of Finalizes is non-deterministic.
62
63             if (swigCPtr.Handle != global::System.IntPtr.Zero)
64             {
65                 if (swigCMemOwn)
66                 {
67                     swigCMemOwn = false;
68                     NDalicPINVOKE.delete_FlexContainer(swigCPtr);
69                 }
70                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
71             }
72
73             base.Dispose(type);
74         }
75
76
77         internal new class Property
78         {
79             internal static readonly int CONTENT_DIRECTION = NDalicPINVOKE.FlexContainer_Property_CONTENT_DIRECTION_get();
80             internal static readonly int FLEX_DIRECTION = NDalicPINVOKE.FlexContainer_Property_FLEX_DIRECTION_get();
81             internal static readonly int FLEX_WRAP = NDalicPINVOKE.FlexContainer_Property_FLEX_WRAP_get();
82             internal static readonly int JUSTIFY_CONTENT = NDalicPINVOKE.FlexContainer_Property_JUSTIFY_CONTENT_get();
83             internal static readonly int ALIGN_ITEMS = NDalicPINVOKE.FlexContainer_Property_ALIGN_ITEMS_get();
84             internal static readonly int ALIGN_CONTENT = NDalicPINVOKE.FlexContainer_Property_ALIGN_CONTENT_get();
85
86         }
87
88         /// <summary>
89         /// Enumeration for the instance of child properties belonging to the FlexContainer class.
90         /// </summary>
91         /// <since_tizen> 3 </since_tizen>
92         public class ChildProperty
93         {
94             internal static readonly int FLEX = NDalicPINVOKE.FlexContainer_ChildProperty_FLEX_get();
95             internal static readonly int ALIGN_SELF = NDalicPINVOKE.FlexContainer_ChildProperty_ALIGN_SELF_get();
96             internal static readonly int FLEX_MARGIN = NDalicPINVOKE.FlexContainer_ChildProperty_FLEX_MARGIN_get();
97         }
98
99         /// <summary>
100         /// Creates a FlexContainer handle.
101         /// Calling member functions with an uninitialized handle is not allowed.
102         /// </summary>
103         /// <since_tizen> 3 </since_tizen>
104         public FlexContainer() : this(NDalicPINVOKE.FlexContainer_New(), true)
105         {
106             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107
108         }
109
110         /// <summary>
111         /// Enumeration for the direction of the main axis in the flex container. This determines
112         /// the direction that flex items are laid out in the flex container.
113         /// </summary>
114         /// <since_tizen> 3 </since_tizen>
115         public enum FlexDirectionType
116         {
117             /// <summary>
118             /// The flexible items are displayed vertically as a column.
119             /// </summary>
120             /// <since_tizen> 3 </since_tizen>
121             Column,
122             /// <summary>
123             /// The flexible items are displayed vertically as a column, but in reverse order.
124             /// </summary>
125             /// <since_tizen> 3 </since_tizen>
126             ColumnReverse,
127             /// <summary>
128             /// The flexible items are displayed horizontally as a row.
129             /// </summary>
130             /// <since_tizen> 3 </since_tizen>
131             Row,
132             /// <summary>
133             /// The flexible items are displayed horizontally as a row.
134             /// </summary>
135             /// <since_tizen> 3 </since_tizen>
136             RowReverse
137         }
138
139         /// <summary>
140         /// Enumeration for the primary direction in which content is ordered in the flex container
141         /// and on which sides the ?�start??and ?�end??are.
142         /// </summary>
143         /// <since_tizen> 3 </since_tizen>
144         public enum ContentDirectionType
145         {
146             /// <summary>
147             /// Inherits the same direction from the parent.
148             /// </summary>
149             /// <since_tizen> 3 </since_tizen>
150             Inherit,
151             /// <summary>
152             /// From left to right.
153             /// </summary>
154             /// <since_tizen> 3 </since_tizen>
155             LTR,
156             /// <summary>
157             /// From right to left.
158             /// </summary>
159             /// <since_tizen> 3 </since_tizen>
160             RTL
161         }
162
163         /// <summary>
164         /// Enumeration for the alignment of the flex items when the items do not use all available
165         /// space on the main axis.
166         /// </summary>
167         /// <since_tizen> 3 </since_tizen>
168         public enum Justification
169         {
170             /// <summary>
171             /// Items are positioned at the beginning of the container.
172             /// </summary>
173             /// <since_tizen> 3 </since_tizen>
174             JustifyFlexStart,
175             /// <summary>
176             /// Items are positioned at the center of the container.
177             /// </summary>
178             /// <since_tizen> 3 </since_tizen>
179             JustifyCenter,
180             /// <summary>
181             /// Items are positioned at the end of the container.
182             /// </summary>
183             /// <since_tizen> 3 </since_tizen>
184             JustifyFlexEnd,
185             /// <summary>
186             /// Items are positioned with equal space between the lines.
187             /// </summary>
188             /// <since_tizen> 3 </since_tizen>
189             JustifySpaceBetween,
190             /// <summary>
191             /// Items are positioned with equal space before, between, and after the lines.
192             /// </summary>
193             /// <since_tizen> 3 </since_tizen>
194             JustifySpaceAround
195         }
196
197         /// <summary>
198         /// Enumeration for the alignment of the flex items or lines when the items or lines do not
199         /// use all the available space on the cross axis.
200         /// </summary>
201         /// <since_tizen> 3 </since_tizen>
202         public enum Alignment
203         {
204             /// <summary>
205             /// Inherits the same alignment from the parent (only valid for "alignSelf" property).
206             /// </summary>
207             /// <since_tizen> 3 </since_tizen>
208             AlignAuto,
209             /// <summary>
210             /// At the beginning of the container.
211             /// </summary>
212             /// <since_tizen> 3 </since_tizen>
213             AlignFlexStart,
214             /// <summary>
215             /// At the center of the container.
216             /// </summary>
217             /// <since_tizen> 3 </since_tizen>
218             AlignCenter,
219             /// <summary>
220             /// At the end of the container.
221             /// </summary>
222             /// <since_tizen> 3 </since_tizen>
223             AlignFlexEnd,
224             /// <summary>
225             /// Stretch to fit the container.
226             /// </summary>
227             /// <since_tizen> 3 </since_tizen>
228             AlignStretch
229         }
230
231         /// <summary>
232         /// Enumeration for the wrap type of the flex container when there is no enough room for
233         /// all the items on one flex line.
234         /// </summary>
235         /// <since_tizen> 3 </since_tizen>
236         public enum WrapType
237         {
238             /// <summary>
239             /// Flex items laid out in single line (shrunk to fit the flex container along the main axis).
240             /// </summary>
241             /// <since_tizen> 3 </since_tizen>
242             NoWrap,
243             /// <summary>
244             /// Flex items laid out in multiple lines if needed.
245             /// </summary>
246             /// <since_tizen> 3 </since_tizen>
247             Wrap
248         }
249
250         /// <summary>
251         /// The primary direction in which content is ordered.
252         /// </summary>
253         /// <since_tizen> 3 </since_tizen>
254         public ContentDirectionType ContentDirection
255         {
256             get
257             {
258                 int temp = 0;
259                 GetProperty(FlexContainer.Property.CONTENT_DIRECTION).Get(out temp);
260                 return (ContentDirectionType)temp;
261             }
262             set
263             {
264                 SetProperty(FlexContainer.Property.CONTENT_DIRECTION, new Tizen.NUI.PropertyValue((int)value));
265                 NotifyPropertyChanged();
266             }
267         }
268
269         /// <summary>
270         /// The direction of the main axis which determines the direction that flex items are laid out.
271         /// </summary>
272         /// <since_tizen> 3 </since_tizen>
273         public FlexDirectionType FlexDirection
274         {
275             get
276             {
277                 int temp = 0;
278                 GetProperty(FlexContainer.Property.FLEX_DIRECTION).Get(out temp);
279                 return (FlexDirectionType)temp;
280             }
281             set
282             {
283                 SetProperty(FlexContainer.Property.FLEX_DIRECTION, new Tizen.NUI.PropertyValue((int)value));
284                 NotifyPropertyChanged();
285             }
286         }
287
288         /// <summary>
289         /// Whether the flex items should wrap or not if there is no enough room for them on one flex line.
290         /// </summary>
291         /// <since_tizen> 3 </since_tizen>
292         public WrapType FlexWrap
293         {
294             get
295             {
296                 int temp = 0;
297                 GetProperty(FlexContainer.Property.FLEX_WRAP).Get(out temp);
298                 return (WrapType)temp;
299             }
300             set
301             {
302                 SetProperty(FlexContainer.Property.FLEX_WRAP, new Tizen.NUI.PropertyValue((int)value));
303                 NotifyPropertyChanged();
304             }
305         }
306
307         /// <summary>
308         /// The alignment of flex items when the items do not use all available space on the main axis.
309         /// </summary>
310         /// <since_tizen> 3 </since_tizen>
311         public Justification JustifyContent
312         {
313             get
314             {
315                 int temp = 0;
316                 GetProperty(FlexContainer.Property.JUSTIFY_CONTENT).Get(out temp);
317                 return (Justification)temp;
318             }
319             set
320             {
321                 SetProperty(FlexContainer.Property.JUSTIFY_CONTENT, new Tizen.NUI.PropertyValue((int)value));
322                 NotifyPropertyChanged();
323             }
324         }
325
326         /// <summary>
327         /// The alignment of flex items when the items do not use all available space on the cross axis.
328         /// </summary>
329         /// <since_tizen> 3 </since_tizen>
330         public Alignment AlignItems
331         {
332             get
333             {
334                 int temp = 0;
335                 GetProperty(FlexContainer.Property.ALIGN_ITEMS).Get(out temp);
336                 return (Alignment)temp;
337             }
338             set
339             {
340                 SetProperty(FlexContainer.Property.ALIGN_ITEMS, new Tizen.NUI.PropertyValue((int)value));
341                 NotifyPropertyChanged();
342             }
343         }
344
345         /// <summary>
346         /// Similar to "alignItems", but it aligns flex lines; so only works when there are multiple lines.
347         /// </summary>
348         /// <since_tizen> 3 </since_tizen>
349         public Alignment AlignContent
350         {
351             get
352             {
353                 int temp = 0;
354                 GetProperty(FlexContainer.Property.ALIGN_CONTENT).Get(out temp);
355                 return (Alignment)temp;
356             }
357             set
358             {
359                 SetProperty(FlexContainer.Property.ALIGN_CONTENT, new Tizen.NUI.PropertyValue((int)value));
360                 NotifyPropertyChanged();
361             }
362         }
363
364     }
365
366 }