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