[NUI] TCSACR-226 code change (#1032)
[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 using System;
18 using System.ComponentModel;
19 using Tizen.NUI.Binding;
20
21 namespace Tizen.NUI.BaseComponents
22 {
23     /// <summary>
24     /// FlexContainer implements a subset of the flexbox spec (defined by W3C):https://www.w3.org/TR/css3-flexbox/<br />
25     /// 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 />
26     /// 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 />
27     /// FlexContainer can expand items to fill available free space, or shrink them to prevent overflow.<br />
28     /// </summary>
29     /// <since_tizen> 3 </since_tizen>
30     public class FlexContainer : View
31     {
32         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
33         [EditorBrowsable(EditorBrowsableState.Never)]
34         public static readonly BindableProperty ContentDirectionProperty = BindableProperty.Create("ContentDirection", typeof(ContentDirectionType), typeof(FlexContainer), ContentDirectionType.Inherit, propertyChanged: (bindable, oldValue, newValue) =>
35         {
36             var flexContainer = (FlexContainer)bindable;
37             if (newValue != null)
38             {
39                 Tizen.NUI.Object.SetProperty(flexContainer.swigCPtr, FlexContainer.Property.CONTENT_DIRECTION, new Tizen.NUI.PropertyValue((int)newValue));
40             }
41         },
42         defaultValueCreator: (bindable) =>
43         {
44             var flexContainer = (FlexContainer)bindable;
45             int temp = 0;
46             Tizen.NUI.Object.GetProperty(flexContainer.swigCPtr, FlexContainer.Property.CONTENT_DIRECTION).Get(out temp);
47             return (ContentDirectionType)temp;
48         });
49         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
50         [EditorBrowsable(EditorBrowsableState.Never)]
51         public static readonly BindableProperty FlexDirectionProperty = BindableProperty.Create("FlexDirection", typeof(FlexDirectionType), typeof(FlexContainer), FlexDirectionType.Column, propertyChanged: (bindable, oldValue, newValue) =>
52         {
53             var flexContainer = (FlexContainer)bindable;
54             if (newValue != null)
55             {
56                 Tizen.NUI.Object.SetProperty(flexContainer.swigCPtr, FlexContainer.Property.FLEX_DIRECTION, new Tizen.NUI.PropertyValue((int)newValue));
57             }
58         },
59         defaultValueCreator: (bindable) =>
60         {
61             var flexContainer = (FlexContainer)bindable;
62             int temp = 0;
63             Tizen.NUI.Object.GetProperty(flexContainer.swigCPtr, FlexContainer.Property.FLEX_DIRECTION).Get(out temp);
64             return (FlexDirectionType)temp;
65         });
66         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
67         [EditorBrowsable(EditorBrowsableState.Never)]
68         public static readonly BindableProperty FlexWrapProperty = BindableProperty.Create("FlexWrap", typeof(WrapType), typeof(FlexContainer), WrapType.NoWrap, propertyChanged: (bindable, oldValue, newValue) =>
69         {
70             var flexContainer = (FlexContainer)bindable;
71             if (newValue != null)
72             {
73                 Tizen.NUI.Object.SetProperty(flexContainer.swigCPtr, FlexContainer.Property.FLEX_WRAP, new Tizen.NUI.PropertyValue((int)newValue));
74             }
75         },
76         defaultValueCreator: (bindable) =>
77         {
78             var flexContainer = (FlexContainer)bindable;
79             int temp = 0;
80             Tizen.NUI.Object.GetProperty(flexContainer.swigCPtr, FlexContainer.Property.FLEX_WRAP).Get(out temp);
81             return (WrapType)temp;
82         });
83         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
84         [EditorBrowsable(EditorBrowsableState.Never)]
85         public static readonly BindableProperty JustifyContentProperty = BindableProperty.Create("JustifyContent", typeof(Justification), typeof(FlexContainer), Justification.JustifyFlexStart, propertyChanged: (bindable, oldValue, newValue) =>
86         {
87             var flexContainer = (FlexContainer)bindable;
88             if (newValue != null)
89             {
90                 Tizen.NUI.Object.SetProperty(flexContainer.swigCPtr, FlexContainer.Property.JUSTIFY_CONTENT, new Tizen.NUI.PropertyValue((int)newValue));
91             }
92         },
93         defaultValueCreator: (bindable) =>
94         {
95             var flexContainer = (FlexContainer)bindable;
96             int temp = 0;
97             Tizen.NUI.Object.GetProperty(flexContainer.swigCPtr, FlexContainer.Property.JUSTIFY_CONTENT).Get(out temp);
98             return (Justification)temp;
99         });
100         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
101         [EditorBrowsable(EditorBrowsableState.Never)]
102         public static readonly BindableProperty AlignItemsProperty = BindableProperty.Create("AlignItems", typeof(Alignment), typeof(FlexContainer), Alignment.AlignAuto, propertyChanged: (bindable, oldValue, newValue) =>
103         {
104             var flexContainer = (FlexContainer)bindable;
105             if (newValue != null)
106             {
107                 Tizen.NUI.Object.SetProperty(flexContainer.swigCPtr, FlexContainer.Property.ALIGN_ITEMS, new Tizen.NUI.PropertyValue((int)newValue));
108             }
109         },
110         defaultValueCreator: (bindable) =>
111         {
112             var flexContainer = (FlexContainer)bindable;
113             int temp = 0;
114             Tizen.NUI.Object.GetProperty(flexContainer.swigCPtr, FlexContainer.Property.ALIGN_ITEMS).Get(out temp);
115             return (Alignment)temp;
116         });
117         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
118         [EditorBrowsable(EditorBrowsableState.Never)]
119         public static readonly BindableProperty AlignContentProperty = BindableProperty.Create("AlignContent", typeof(Alignment), typeof(FlexContainer), Alignment.AlignAuto, propertyChanged: (bindable, oldValue, newValue) =>
120         {
121             var flexContainer = (FlexContainer)bindable;
122             if (newValue != null)
123             {
124                 Tizen.NUI.Object.SetProperty(flexContainer.swigCPtr, FlexContainer.Property.ALIGN_CONTENT, new Tizen.NUI.PropertyValue((int)newValue));
125             }
126         },
127         defaultValueCreator: (bindable) =>
128         {
129             var flexContainer = (FlexContainer)bindable;
130             int temp = 0;
131             Tizen.NUI.Object.GetProperty(flexContainer.swigCPtr, FlexContainer.Property.ALIGN_CONTENT).Get(out temp);
132             return (Alignment)temp;
133         });
134
135         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
136
137         /// <summary>
138         /// Creates a FlexContainer handle.
139         /// Calling member functions with an uninitialized handle is not allowed.
140         /// </summary>
141         /// <since_tizen> 3 </since_tizen>
142         public FlexContainer() : this(Interop.FlexContainer.FlexContainer_New(), true)
143         {
144             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145         }
146
147         internal FlexContainer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.FlexContainer.FlexContainer_SWIGUpcast(cPtr), cMemoryOwn)
148         {
149             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
150         }
151
152         /// <summary>
153         /// Enumeration for the direction of the main axis in the flex container. This determines
154         /// the direction that flex items are laid out in the flex container.
155         /// </summary>
156         /// <since_tizen> 3 </since_tizen>
157         public enum FlexDirectionType
158         {
159             /// <summary>
160             /// The flexible items are displayed vertically as a column.
161             /// </summary>
162             /// <since_tizen> 3 </since_tizen>
163             Column,
164             /// <summary>
165             /// The flexible items are displayed vertically as a column, but in reverse order.
166             /// </summary>
167             /// <since_tizen> 3 </since_tizen>
168             ColumnReverse,
169             /// <summary>
170             /// The flexible items are displayed horizontally as a row.
171             /// </summary>
172             /// <since_tizen> 3 </since_tizen>
173             Row,
174             /// <summary>
175             /// The flexible items are displayed horizontally as a row.
176             /// </summary>
177             /// <since_tizen> 3 </since_tizen>
178             RowReverse
179         }
180
181         /// <summary>
182         /// Enumeration for the primary direction in which content is ordered in the flex container
183         /// and on which sides the ?�start??and ?�end??are.
184         /// </summary>
185         /// <since_tizen> 3 </since_tizen>
186         public enum ContentDirectionType
187         {
188             /// <summary>
189             /// Inherits the same direction from the parent.
190             /// </summary>
191             /// <since_tizen> 3 </since_tizen>
192             Inherit,
193             /// <summary>
194             /// From left to right.
195             /// </summary>
196             /// <since_tizen> 3 </since_tizen>
197             LTR,
198             /// <summary>
199             /// From right to left.
200             /// </summary>
201             /// <since_tizen> 3 </since_tizen>
202             RTL
203         }
204
205         /// <summary>
206         /// Enumeration for the alignment of the flex items when the items do not use all available
207         /// space on the main axis.
208         /// </summary>
209         /// <since_tizen> 3 </since_tizen>
210         public enum Justification
211         {
212             /// <summary>
213             /// Items are positioned at the beginning of the container.
214             /// </summary>
215             /// <since_tizen> 3 </since_tizen>
216             JustifyFlexStart,
217             /// <summary>
218             /// Items are positioned at the center of the container.
219             /// </summary>
220             /// <since_tizen> 3 </since_tizen>
221             JustifyCenter,
222             /// <summary>
223             /// Items are positioned at the end of the container.
224             /// </summary>
225             /// <since_tizen> 3 </since_tizen>
226             JustifyFlexEnd,
227             /// <summary>
228             /// Items are positioned with equal space between the lines.
229             /// </summary>
230             /// <since_tizen> 3 </since_tizen>
231             JustifySpaceBetween,
232             /// <summary>
233             /// Items are positioned with equal space before, between, and after the lines.
234             /// </summary>
235             /// <since_tizen> 3 </since_tizen>
236             JustifySpaceAround
237         }
238
239         /// <summary>
240         /// Enumeration for the alignment of the flex items or lines when the items or lines do not
241         /// use all the available space on the cross axis.
242         /// </summary>
243         /// <since_tizen> 3 </since_tizen>
244         public enum Alignment
245         {
246             /// <summary>
247             /// Inherits the same alignment from the parent (only valid for "alignSelf" property).
248             /// </summary>
249             /// <since_tizen> 3 </since_tizen>
250             AlignAuto,
251             /// <summary>
252             /// At the beginning of the container.
253             /// </summary>
254             /// <since_tizen> 3 </since_tizen>
255             AlignFlexStart,
256             /// <summary>
257             /// At the center of the container.
258             /// </summary>
259             /// <since_tizen> 3 </since_tizen>
260             AlignCenter,
261             /// <summary>
262             /// At the end of the container.
263             /// </summary>
264             /// <since_tizen> 3 </since_tizen>
265             AlignFlexEnd,
266             /// <summary>
267             /// Stretch to fit the container.
268             /// </summary>
269             /// <since_tizen> 3 </since_tizen>
270             AlignStretch
271         }
272
273         /// <summary>
274         /// Enumeration for the wrap type of the flex container when there is no enough room for
275         /// all the items on one flex line.
276         /// </summary>
277         /// <since_tizen> 3 </since_tizen>
278         public enum WrapType
279         {
280             /// <summary>
281             /// Flex items laid out in single line (shrunk to fit the flex container along the main axis).
282             /// </summary>
283             /// <since_tizen> 3 </since_tizen>
284             NoWrap,
285             /// <summary>
286             /// Flex items laid out in multiple lines if needed.
287             /// </summary>
288             /// <since_tizen> 3 </since_tizen>
289             Wrap
290         }
291
292         /// <summary>
293         /// The primary direction in which content is ordered.
294         /// </summary>
295         /// <since_tizen> 3 </since_tizen>
296         public ContentDirectionType ContentDirection
297         {
298             get
299             {
300                 return (ContentDirectionType)GetValue(ContentDirectionProperty);
301             }
302             set
303             {
304                 SetValue(ContentDirectionProperty, value);
305                 NotifyPropertyChanged();
306             }
307         }
308
309         /// <summary>
310         /// The direction of the main axis which determines the direction that flex items are laid out.
311         /// </summary>
312         /// <since_tizen> 3 </since_tizen>
313         public FlexDirectionType FlexDirection
314         {
315             get
316             {
317                 return (FlexDirectionType)GetValue(FlexDirectionProperty);
318             }
319             set
320             {
321                 SetValue(FlexDirectionProperty, value);
322                 NotifyPropertyChanged();
323             }
324         }
325
326         /// <summary>
327         /// Whether the flex items should wrap or not if there is no enough room for them on one flex line.
328         /// </summary>
329         /// <since_tizen> 3 </since_tizen>
330         public WrapType FlexWrap
331         {
332             get
333             {
334                 return (WrapType)GetValue(FlexWrapProperty);
335             }
336             set
337             {
338                 SetValue(FlexWrapProperty, value);
339                 NotifyPropertyChanged();
340             }
341         }
342
343         /// <summary>
344         /// The alignment of flex items when the items do not use all available space on the main axis.
345         /// </summary>
346         /// <since_tizen> 3 </since_tizen>
347         public Justification JustifyContent
348         {
349             get
350             {
351                 return (Justification)GetValue(JustifyContentProperty);
352             }
353             set
354             {
355                 SetValue(JustifyContentProperty, value);
356                 NotifyPropertyChanged();
357             }
358         }
359
360         /// <summary>
361         /// The alignment of flex items when the items do not use all available space on the cross axis.
362         /// </summary>
363         /// <since_tizen> 3 </since_tizen>
364         public Alignment AlignItems
365         {
366             get
367             {
368                 return (Alignment)GetValue(AlignItemsProperty);
369             }
370             set
371             {
372                 SetValue(AlignItemsProperty, value);
373                 NotifyPropertyChanged();
374             }
375         }
376
377         /// <summary>
378         /// Similar to "alignItems", but it aligns flex lines; so only works when there are multiple lines.
379         /// </summary>
380         /// <since_tizen> 3 </since_tizen>
381         public Alignment AlignContent
382         {
383             get
384             {
385                 return (Alignment)GetValue(AlignContentProperty);
386             }
387             set
388             {
389                 SetValue(AlignContentProperty, value);
390                 NotifyPropertyChanged();
391             }
392         }
393
394         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FlexContainer obj)
395         {
396             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
397         }
398
399         /// <summary>
400         /// To make the FlexContainer instance be disposed.
401         /// </summary>
402         /// <since_tizen> 3 </since_tizen>
403         protected override void Dispose(DisposeTypes type)
404         {
405             if (disposed)
406             {
407                 return;
408             }
409
410             //Release your own unmanaged resources here.
411             //You should not access any managed member here except static instance.
412             //because the execution order of Finalizes is non-deterministic.
413
414             if (swigCPtr.Handle != global::System.IntPtr.Zero)
415             {
416                 if (swigCMemOwn)
417                 {
418                     swigCMemOwn = false;
419                     Interop.FlexContainer.delete_FlexContainer(swigCPtr);
420                 }
421                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
422             }
423
424             base.Dispose(type);
425         }
426
427         /// <summary>
428         /// Enumeration for the instance of child properties belonging to the FlexContainer class.
429         /// </summary>
430         /// <since_tizen> 3 </since_tizen>
431         [Obsolete("Deprecated in API6, Will be removed in API9, " + 
432             "Please use View.Flex, View.AlignSelf, View.FlexMargin instead!")]
433         [EditorBrowsable(EditorBrowsableState.Never)]
434         public class ChildProperty
435         {
436             internal static readonly int FLEX = Interop.FlexContainer.FlexContainer_ChildProperty_FLEX_get();
437             internal static readonly int ALIGN_SELF = Interop.FlexContainer.FlexContainer_ChildProperty_ALIGN_SELF_get();
438             internal static readonly int FLEX_MARGIN = Interop.FlexContainer.FlexContainer_ChildProperty_FLEX_MARGIN_get();
439         }
440
441         internal new class Property
442         {
443             internal static readonly int CONTENT_DIRECTION = Interop.FlexContainer.FlexContainer_Property_CONTENT_DIRECTION_get();
444             internal static readonly int FLEX_DIRECTION = Interop.FlexContainer.FlexContainer_Property_FLEX_DIRECTION_get();
445             internal static readonly int FLEX_WRAP = Interop.FlexContainer.FlexContainer_Property_FLEX_WRAP_get();
446             internal static readonly int JUSTIFY_CONTENT = Interop.FlexContainer.FlexContainer_Property_JUSTIFY_CONTENT_get();
447             internal static readonly int ALIGN_ITEMS = Interop.FlexContainer.FlexContainer_Property_ALIGN_ITEMS_get();
448             internal static readonly int ALIGN_CONTENT = Interop.FlexContainer.FlexContainer_Property_ALIGN_CONTENT_get();
449         }
450     }
451 }