[NUI] Refactor dispose pattern to reduce duplication (#1112)
[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
136         /// <summary>
137         /// Creates a FlexContainer handle.
138         /// Calling member functions with an uninitialized handle is not allowed.
139         /// </summary>
140         /// <since_tizen> 3 </since_tizen>
141         public FlexContainer() : this(Interop.FlexContainer.FlexContainer_New(), true)
142         {
143             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144         }
145
146         internal FlexContainer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.FlexContainer.FlexContainer_SWIGUpcast(cPtr), cMemoryOwn)
147         {
148         }
149
150         /// <summary>
151         /// Enumeration for the direction of the main axis in the flex container. This determines
152         /// the direction that flex items are laid out in the flex container.
153         /// </summary>
154         /// <since_tizen> 3 </since_tizen>
155         public enum FlexDirectionType
156         {
157             /// <summary>
158             /// The flexible items are displayed vertically as a column.
159             /// </summary>
160             /// <since_tizen> 3 </since_tizen>
161             Column,
162             /// <summary>
163             /// The flexible items are displayed vertically as a column, but in reverse order.
164             /// </summary>
165             /// <since_tizen> 3 </since_tizen>
166             ColumnReverse,
167             /// <summary>
168             /// The flexible items are displayed horizontally as a row.
169             /// </summary>
170             /// <since_tizen> 3 </since_tizen>
171             Row,
172             /// <summary>
173             /// The flexible items are displayed horizontally as a row.
174             /// </summary>
175             /// <since_tizen> 3 </since_tizen>
176             RowReverse
177         }
178
179         /// <summary>
180         /// Enumeration for the primary direction in which content is ordered in the flex container
181         /// and on which sides the ?�start??and ?�end??are.
182         /// </summary>
183         /// <since_tizen> 3 </since_tizen>
184         public enum ContentDirectionType
185         {
186             /// <summary>
187             /// Inherits the same direction from the parent.
188             /// </summary>
189             /// <since_tizen> 3 </since_tizen>
190             Inherit,
191             /// <summary>
192             /// From left to right.
193             /// </summary>
194             /// <since_tizen> 3 </since_tizen>
195             LTR,
196             /// <summary>
197             /// From right to left.
198             /// </summary>
199             /// <since_tizen> 3 </since_tizen>
200             RTL
201         }
202
203         /// <summary>
204         /// Enumeration for the alignment of the flex items when the items do not use all available
205         /// space on the main axis.
206         /// </summary>
207         /// <since_tizen> 3 </since_tizen>
208         public enum Justification
209         {
210             /// <summary>
211             /// Items are positioned at the beginning of the container.
212             /// </summary>
213             /// <since_tizen> 3 </since_tizen>
214             JustifyFlexStart,
215             /// <summary>
216             /// Items are positioned at the center of the container.
217             /// </summary>
218             /// <since_tizen> 3 </since_tizen>
219             JustifyCenter,
220             /// <summary>
221             /// Items are positioned at the end of the container.
222             /// </summary>
223             /// <since_tizen> 3 </since_tizen>
224             JustifyFlexEnd,
225             /// <summary>
226             /// Items are positioned with equal space between the lines.
227             /// </summary>
228             /// <since_tizen> 3 </since_tizen>
229             JustifySpaceBetween,
230             /// <summary>
231             /// Items are positioned with equal space before, between, and after the lines.
232             /// </summary>
233             /// <since_tizen> 3 </since_tizen>
234             JustifySpaceAround
235         }
236
237         /// <summary>
238         /// Enumeration for the alignment of the flex items or lines when the items or lines do not
239         /// use all the available space on the cross axis.
240         /// </summary>
241         /// <since_tizen> 3 </since_tizen>
242         public enum Alignment
243         {
244             /// <summary>
245             /// Inherits the same alignment from the parent (only valid for "alignSelf" property).
246             /// </summary>
247             /// <since_tizen> 3 </since_tizen>
248             AlignAuto,
249             /// <summary>
250             /// At the beginning of the container.
251             /// </summary>
252             /// <since_tizen> 3 </since_tizen>
253             AlignFlexStart,
254             /// <summary>
255             /// At the center of the container.
256             /// </summary>
257             /// <since_tizen> 3 </since_tizen>
258             AlignCenter,
259             /// <summary>
260             /// At the end of the container.
261             /// </summary>
262             /// <since_tizen> 3 </since_tizen>
263             AlignFlexEnd,
264             /// <summary>
265             /// Stretch to fit the container.
266             /// </summary>
267             /// <since_tizen> 3 </since_tizen>
268             AlignStretch
269         }
270
271         /// <summary>
272         /// Enumeration for the wrap type of the flex container when there is no enough room for
273         /// all the items on one flex line.
274         /// </summary>
275         /// <since_tizen> 3 </since_tizen>
276         public enum WrapType
277         {
278             /// <summary>
279             /// Flex items laid out in single line (shrunk to fit the flex container along the main axis).
280             /// </summary>
281             /// <since_tizen> 3 </since_tizen>
282             NoWrap,
283             /// <summary>
284             /// Flex items laid out in multiple lines if needed.
285             /// </summary>
286             /// <since_tizen> 3 </since_tizen>
287             Wrap
288         }
289
290         /// <summary>
291         /// The primary direction in which content is ordered.
292         /// </summary>
293         /// <since_tizen> 3 </since_tizen>
294         public ContentDirectionType ContentDirection
295         {
296             get
297             {
298                 return (ContentDirectionType)GetValue(ContentDirectionProperty);
299             }
300             set
301             {
302                 SetValue(ContentDirectionProperty, value);
303                 NotifyPropertyChanged();
304             }
305         }
306
307         /// <summary>
308         /// The direction of the main axis which determines the direction that flex items are laid out.
309         /// </summary>
310         /// <since_tizen> 3 </since_tizen>
311         public FlexDirectionType FlexDirection
312         {
313             get
314             {
315                 return (FlexDirectionType)GetValue(FlexDirectionProperty);
316             }
317             set
318             {
319                 SetValue(FlexDirectionProperty, value);
320                 NotifyPropertyChanged();
321             }
322         }
323
324         /// <summary>
325         /// Whether the flex items should wrap or not if there is no enough room for them on one flex line.
326         /// </summary>
327         /// <since_tizen> 3 </since_tizen>
328         public WrapType FlexWrap
329         {
330             get
331             {
332                 return (WrapType)GetValue(FlexWrapProperty);
333             }
334             set
335             {
336                 SetValue(FlexWrapProperty, value);
337                 NotifyPropertyChanged();
338             }
339         }
340
341         /// <summary>
342         /// The alignment of flex items when the items do not use all available space on the main axis.
343         /// </summary>
344         /// <since_tizen> 3 </since_tizen>
345         public Justification JustifyContent
346         {
347             get
348             {
349                 return (Justification)GetValue(JustifyContentProperty);
350             }
351             set
352             {
353                 SetValue(JustifyContentProperty, value);
354                 NotifyPropertyChanged();
355             }
356         }
357
358         /// <summary>
359         /// The alignment of flex items when the items do not use all available space on the cross axis.
360         /// </summary>
361         /// <since_tizen> 3 </since_tizen>
362         public Alignment AlignItems
363         {
364             get
365             {
366                 return (Alignment)GetValue(AlignItemsProperty);
367             }
368             set
369             {
370                 SetValue(AlignItemsProperty, value);
371                 NotifyPropertyChanged();
372             }
373         }
374
375         /// <summary>
376         /// Similar to "alignItems", but it aligns flex lines; so only works when there are multiple lines.
377         /// </summary>
378         /// <since_tizen> 3 </since_tizen>
379         public Alignment AlignContent
380         {
381             get
382             {
383                 return (Alignment)GetValue(AlignContentProperty);
384             }
385             set
386             {
387                 SetValue(AlignContentProperty, value);
388                 NotifyPropertyChanged();
389             }
390         }
391
392         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FlexContainer obj)
393         {
394             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
395         }
396
397         /// This will not be public opened.
398         [EditorBrowsable(EditorBrowsableState.Never)]
399         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
400         {
401             Interop.FlexContainer.delete_FlexContainer(swigCPtr);
402         }
403
404         /// <summary>
405         /// Enumeration for the instance of child properties belonging to the FlexContainer class.
406         /// </summary>
407         /// <since_tizen> 3 </since_tizen>
408         [Obsolete("Deprecated in API6, Will be removed in API9, " + 
409             "Please use View.Flex, View.AlignSelf, View.FlexMargin instead!")]
410         [EditorBrowsable(EditorBrowsableState.Never)]
411         public class ChildProperty
412         {
413             internal static readonly int FLEX = Interop.FlexContainer.FlexContainer_ChildProperty_FLEX_get();
414             internal static readonly int ALIGN_SELF = Interop.FlexContainer.FlexContainer_ChildProperty_ALIGN_SELF_get();
415             internal static readonly int FLEX_MARGIN = Interop.FlexContainer.FlexContainer_ChildProperty_FLEX_MARGIN_get();
416         }
417
418         internal new class Property
419         {
420             internal static readonly int CONTENT_DIRECTION = Interop.FlexContainer.FlexContainer_Property_CONTENT_DIRECTION_get();
421             internal static readonly int FLEX_DIRECTION = Interop.FlexContainer.FlexContainer_Property_FLEX_DIRECTION_get();
422             internal static readonly int FLEX_WRAP = Interop.FlexContainer.FlexContainer_Property_FLEX_WRAP_get();
423             internal static readonly int JUSTIFY_CONTENT = Interop.FlexContainer.FlexContainer_Property_JUSTIFY_CONTENT_get();
424             internal static readonly int ALIGN_ITEMS = Interop.FlexContainer.FlexContainer_Property_ALIGN_ITEMS_get();
425             internal static readonly int ALIGN_CONTENT = Interop.FlexContainer.FlexContainer_Property_ALIGN_CONTENT_get();
426         }
427     }
428 }