[NUI] Add IsXamlUsing flag to Camera, ItemView and etc
[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 System.Diagnostics.CodeAnalysis;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.BaseComponents
23 {
24     /// <summary>
25     /// FlexContainer implements a subset of the flexbox spec (defined by W3C):https://www.w3.org/TR/css3-flexbox/<br />
26     /// 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 />
27     /// 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 />
28     /// FlexContainer can expand items to fill available free space, or shrink them to prevent overflow.<br />
29     /// </summary>
30     /// <since_tizen> 3 </since_tizen>
31     [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
32     public class FlexContainer : View
33     {
34         /// <summary> Property of ContentDirection </summary>
35         [EditorBrowsable(EditorBrowsableState.Never)]
36         public static BindableProperty ContentDirectionProperty = null;
37         internal static void SetInternalContentDirectionProperty(BindableObject bindable, object oldValue, object newValue)
38         {
39             var flexContainer = (FlexContainer)bindable;
40             if (newValue != null)
41             {
42                 Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.ContentDirection, new Tizen.NUI.PropertyValue((int)newValue));
43             }
44         }
45         internal static object GetInternalContentDirectionProperty(BindableObject bindable)
46         {
47             var flexContainer = (FlexContainer)bindable;
48             int temp = 0;
49             Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.ContentDirection).Get(out temp);
50             return (ContentDirectionType)temp;
51         }
52
53         /// <summary> Property of FlexDirection </summary>
54         [EditorBrowsable(EditorBrowsableState.Never)]
55         public static BindableProperty FlexDirectionProperty = null;
56         internal static void SetInternalFlexDirectionProperty(BindableObject bindable, object oldValue, object newValue)
57         {
58             var flexContainer = (FlexContainer)bindable;
59             if (newValue != null)
60             {
61                 Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.FlexDirection, new Tizen.NUI.PropertyValue((int)newValue));
62             }
63         }
64         internal static object GetInternalFlexDirectionProperty(BindableObject bindable)
65         {
66             var flexContainer = (FlexContainer)bindable;
67             int temp = 0;
68             Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.FlexDirection).Get(out temp);
69             return (FlexDirectionType)temp;
70         }
71
72         /// <summary> Property of FlexWrap </summary>
73         [EditorBrowsable(EditorBrowsableState.Never)]
74         public static BindableProperty FlexWrapProperty = null;
75         internal static void SetInternalFlexWrapProperty(BindableObject bindable, object oldValue, object newValue)
76         {
77             var flexContainer = (FlexContainer)bindable;
78             if (newValue != null)
79             {
80                 Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.FlexWrap, new Tizen.NUI.PropertyValue((int)newValue));
81             }
82         }
83         internal static object GetInternalFlexWrapProperty(BindableObject bindable)
84         {
85             var flexContainer = (FlexContainer)bindable;
86             int temp = 0;
87             Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.FlexWrap).Get(out temp);
88             return (WrapType)temp;
89         }
90
91         /// <summary> Property of JustifyContent </summary>
92         [EditorBrowsable(EditorBrowsableState.Never)]
93         public static BindableProperty JustifyContentProperty = null;
94         internal static void SetInternalJustifyContentProperty(BindableObject bindable, object oldValue, object newValue)
95         {
96             var flexContainer = (FlexContainer)bindable;
97             if (newValue != null)
98             {
99                 Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.JustifyContent, new Tizen.NUI.PropertyValue((int)newValue));
100             }
101         }
102         internal static object GetInternalJustifyContentProperty(BindableObject bindable)
103         {
104             var flexContainer = (FlexContainer)bindable;
105             int temp = 0;
106             Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.JustifyContent).Get(out temp);
107             return (Justification)temp;
108         }
109
110         /// <summary> Property of AlignItems </summary>
111         [EditorBrowsable(EditorBrowsableState.Never)]
112         public static BindableProperty AlignItemsProperty = null;
113         internal static void SetInternalAlignItemsProperty(BindableObject bindable, object oldValue, object newValue)
114         {
115             var flexContainer = (FlexContainer)bindable;
116             if (newValue != null)
117             {
118                 Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.AlignItems, new Tizen.NUI.PropertyValue((int)newValue));
119             }
120         }
121         internal static object GetInternalAlignItemsProperty(BindableObject bindable)
122         {
123             var flexContainer = (FlexContainer)bindable;
124             int temp = 0;
125             Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.AlignItems).Get(out temp);
126             return (Alignment)temp;
127         }
128
129         /// <summary> Property of AlignContent </summary>
130         [EditorBrowsable(EditorBrowsableState.Never)]
131         public static BindableProperty AlignContentProperty = null;
132         internal static void SetInternalAlignContentProperty(BindableObject bindable, object oldValue, object newValue)
133         {
134             var flexContainer = (FlexContainer)bindable;
135             if (newValue != null)
136             {
137                 Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.AlignContent, new Tizen.NUI.PropertyValue((int)newValue));
138             }
139         }
140         internal static object GetInternalAlignContentProperty(BindableObject bindable)
141         {
142             var flexContainer = (FlexContainer)bindable;
143             int temp = 0;
144             Tizen.NUI.Object.GetProperty((System.Runtime.InteropServices.HandleRef)flexContainer.SwigCPtr, FlexContainer.Property.AlignContent).Get(out temp);
145             return (Alignment)temp;
146         }
147
148         static FlexContainer()
149         {
150             if (NUIApplication.IsUsingXaml)
151             {
152                 ContentDirectionProperty = BindableProperty.Create(nameof(ContentDirection), typeof(ContentDirectionType), typeof(FlexContainer), ContentDirectionType.Inherit,
153                     propertyChanged: SetInternalContentDirectionProperty, defaultValueCreator: GetInternalContentDirectionProperty);
154
155                 FlexDirectionProperty = BindableProperty.Create(nameof(FlexDirection), typeof(FlexDirectionType), typeof(FlexContainer), FlexDirectionType.Column,
156                     propertyChanged: SetInternalFlexDirectionProperty, defaultValueCreator: GetInternalFlexDirectionProperty);
157
158                 FlexWrapProperty = BindableProperty.Create(nameof(FlexWrap), typeof(WrapType), typeof(FlexContainer), WrapType.NoWrap,
159                     propertyChanged: SetInternalFlexWrapProperty, defaultValueCreator: GetInternalFlexWrapProperty);
160
161                 JustifyContentProperty = BindableProperty.Create(nameof(JustifyContent), typeof(Justification), typeof(FlexContainer), Justification.JustifyFlexStart,
162                     propertyChanged: SetInternalJustifyContentProperty, defaultValueCreator: GetInternalJustifyContentProperty);
163
164                 AlignItemsProperty = BindableProperty.Create(nameof(AlignItems), typeof(Alignment), typeof(FlexContainer), Alignment.AlignAuto,
165                     propertyChanged: SetInternalAlignItemsProperty, defaultValueCreator: GetInternalAlignItemsProperty);
166
167                 AlignContentProperty = BindableProperty.Create(nameof(AlignContent), typeof(Alignment), typeof(FlexContainer), Alignment.AlignAuto,
168                     propertyChanged: SetInternalAlignContentProperty, defaultValueCreator: GetInternalAlignContentProperty);
169             }
170         }
171
172
173         /// <summary>
174         /// Creates a FlexContainer handle.
175         /// Calling member functions with an uninitialized handle is not allowed.
176         /// </summary>
177         /// <since_tizen> 3 </since_tizen>
178         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
179         public FlexContainer() : this(Interop.FlexContainer.New(), true)
180         {
181             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182         }
183
184         internal FlexContainer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
185         {
186         }
187
188         /// <summary>
189         /// Enumeration for the direction of the main axis in the flex container. This determines
190         /// the direction that flex items are laid out in the flex container.
191         /// </summary>
192         /// <since_tizen> 3 </since_tizen>
193         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
194         public enum FlexDirectionType
195         {
196             /// <summary>
197             /// The flexible items are displayed vertically as a column.
198             /// </summary>
199             /// <since_tizen> 3 </since_tizen>
200             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
201             Column,
202             /// <summary>
203             /// The flexible items are displayed vertically as a column, but in reverse order.
204             /// </summary>
205             /// <since_tizen> 3 </since_tizen>
206             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
207             ColumnReverse,
208             /// <summary>
209             /// The flexible items are displayed horizontally as a row.
210             /// </summary>
211             /// <since_tizen> 3 </since_tizen>
212             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
213             Row,
214             /// <summary>
215             /// The flexible items are displayed horizontally as a row.
216             /// </summary>
217             /// <since_tizen> 3 </since_tizen>
218             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
219             RowReverse
220         }
221
222         /// <summary>
223         /// Enumeration for the primary direction in which content is ordered in the flex container
224         /// and on which sides the ?�start??and ?�end??are.
225         /// </summary>
226         /// <since_tizen> 3 </since_tizen>
227         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
228         public enum ContentDirectionType
229         {
230             /// <summary>
231             /// Inherits the same direction from the parent.
232             /// </summary>
233             /// <since_tizen> 3 </since_tizen>
234             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
235             Inherit,
236             /// <summary>
237             /// From left to right.
238             /// </summary>
239             /// <since_tizen> 3 </since_tizen>
240             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
241             LTR,
242             /// <summary>
243             /// From right to left.
244             /// </summary>
245             /// <since_tizen> 3 </since_tizen>
246             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
247             RTL
248         }
249
250         /// <summary>
251         /// Enumeration for the alignment of the flex items when the items do not use all available
252         /// space on the main axis.
253         /// </summary>
254         /// <since_tizen> 3 </since_tizen>
255         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
256         public enum Justification
257         {
258             /// <summary>
259             /// Items are positioned at the beginning of the container.
260             /// </summary>
261             /// <since_tizen> 3 </since_tizen>
262             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
263             JustifyFlexStart,
264             /// <summary>
265             /// Items are positioned at the center of the container.
266             /// </summary>
267             /// <since_tizen> 3 </since_tizen>
268             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
269             JustifyCenter,
270             /// <summary>
271             /// Items are positioned at the end of the container.
272             /// </summary>
273             /// <since_tizen> 3 </since_tizen>
274             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
275             JustifyFlexEnd,
276             /// <summary>
277             /// Items are positioned with equal space between the lines.
278             /// </summary>
279             /// <since_tizen> 3 </since_tizen>
280             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
281             JustifySpaceBetween,
282             /// <summary>
283             /// Items are positioned with equal space before, between, and after the lines.
284             /// </summary>
285             /// <since_tizen> 3 </since_tizen>
286             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
287             JustifySpaceAround
288         }
289
290         /// <summary>
291         /// Enumeration for the alignment of the flex items or lines when the items or lines do not
292         /// use all the available space on the cross axis.
293         /// </summary>
294         /// <since_tizen> 3 </since_tizen>
295         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
296         public enum Alignment
297         {
298             /// <summary>
299             /// Inherits the same alignment from the parent (only valid for "alignSelf" property).
300             /// </summary>
301             /// <since_tizen> 3 </since_tizen>
302             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
303             AlignAuto,
304             /// <summary>
305             /// At the beginning of the container.
306             /// </summary>
307             /// <since_tizen> 3 </since_tizen>
308             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
309             AlignFlexStart,
310             /// <summary>
311             /// At the center of the container.
312             /// </summary>
313             /// <since_tizen> 3 </since_tizen>
314             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
315             AlignCenter,
316             /// <summary>
317             /// At the end of the container.
318             /// </summary>
319             /// <since_tizen> 3 </since_tizen>
320             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
321             AlignFlexEnd,
322             /// <summary>
323             /// Stretch to fit the container.
324             /// </summary>
325             /// <since_tizen> 3 </since_tizen>
326             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
327             AlignStretch
328         }
329
330         /// <summary>
331         /// Enumeration for the wrap type of the flex container when there is no enough room for
332         /// all the items on one flex line.
333         /// </summary>
334         /// <since_tizen> 3 </since_tizen>
335         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
336         public enum WrapType
337         {
338             /// <summary>
339             /// Flex items laid out in single line (shrunk to fit the flex container along the main axis).
340             /// </summary>
341             /// <since_tizen> 3 </since_tizen>
342             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
343             NoWrap,
344             /// <summary>
345             /// Flex items laid out in multiple lines if needed.
346             /// </summary>
347             /// <since_tizen> 3 </since_tizen>
348             [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
349             Wrap
350         }
351
352         /// <summary>
353         /// The primary direction in which content is ordered.
354         /// </summary>
355         /// <since_tizen> 3 </since_tizen>
356         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
357         public ContentDirectionType ContentDirection
358         {
359             get
360             {
361                 if (NUIApplication.IsUsingXaml)
362                 {
363                     return (ContentDirectionType)GetValue(ContentDirectionProperty);
364                 }
365                 else
366                 {
367                     return (ContentDirectionType)GetInternalContentDirectionProperty(this);
368                 }
369             }
370             set
371             {
372                 if (NUIApplication.IsUsingXaml)
373                 {
374                     SetValue(ContentDirectionProperty, value);
375                 }
376                 else
377                 {
378                     SetInternalContentDirectionProperty(this, null, value);
379                 }
380                 NotifyPropertyChanged();
381             }
382         }
383
384         /// <summary>
385         /// The direction of the main axis which determines the direction that flex items are laid out.
386         /// </summary>
387         /// <since_tizen> 3 </since_tizen>
388         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
389         public FlexDirectionType FlexDirection
390         {
391             get
392             {
393                 if (NUIApplication.IsUsingXaml)
394                 {
395                     return (FlexDirectionType)GetValue(FlexDirectionProperty);
396                 }
397                 else
398                 {
399                     return (FlexDirectionType)GetInternalFlexDirectionProperty(this);
400                 }
401             }
402             set
403             {
404                 if (NUIApplication.IsUsingXaml)
405                 {
406                     SetValue(FlexDirectionProperty, value);
407                 }
408                 else
409                 {
410                     SetInternalFlexDirectionProperty(this, null, value);
411                 }
412                 NotifyPropertyChanged();
413             }
414         }
415
416         /// <summary>
417         /// Whether the flex items should wrap or not if there is no enough room for them on one flex line.
418         /// </summary>
419         /// <since_tizen> 3 </since_tizen>
420         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
421         public WrapType FlexWrap
422         {
423             get
424             {
425                 if (NUIApplication.IsUsingXaml)
426                 {
427                     return (WrapType)GetValue(FlexWrapProperty);
428                 }
429                 else
430                 {
431                     return (WrapType)GetInternalFlexWrapProperty(this);
432                 }
433             }
434             set
435             {
436                 if (NUIApplication.IsUsingXaml)
437                 {
438                     SetValue(FlexWrapProperty, value);
439                 }
440                 else
441                 {
442                     SetInternalFlexWrapProperty(this, null, value);
443                 }
444                 NotifyPropertyChanged();
445             }
446         }
447
448         /// <summary>
449         /// The alignment of flex items when the items do not use all available space on the main axis.
450         /// </summary>
451         /// <since_tizen> 3 </since_tizen>
452         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
453         public Justification JustifyContent
454         {
455             get
456             {
457                 if (NUIApplication.IsUsingXaml)
458                 {
459                     return (Justification)GetValue(JustifyContentProperty);
460                 }
461                 else
462                 {
463                     return (Justification)GetInternalJustifyContentProperty(this);
464                 }
465             }
466             set
467             {
468                 if (NUIApplication.IsUsingXaml)
469                 {
470                     SetValue(JustifyContentProperty, value);
471                 }
472                 else
473                 {
474                     SetInternalJustifyContentProperty(this, null, value);
475                 }
476                 NotifyPropertyChanged();
477             }
478         }
479
480         /// <summary>
481         /// The alignment of flex items when the items do not use all available space on the cross axis.
482         /// </summary>
483         /// <since_tizen> 3 </since_tizen>
484         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
485         public Alignment AlignItems
486         {
487             get
488             {
489                 if (NUIApplication.IsUsingXaml)
490                 {
491                     return (Alignment)GetValue(AlignItemsProperty);
492                 }
493                 else
494                 {
495                     return (Alignment)GetInternalAlignItemsProperty(this);
496                 }
497             }
498             set
499             {
500                 if (NUIApplication.IsUsingXaml)
501                 {
502                     SetValue(AlignItemsProperty, value);
503                 }
504                 else
505                 {
506                     SetInternalAlignItemsProperty(this, null, value);
507                 }
508                 NotifyPropertyChanged();
509             }
510         }
511
512         /// <summary>
513         /// Similar to "alignItems", but it aligns flex lines; so only works when there are multiple lines.
514         /// </summary>
515         /// <since_tizen> 3 </since_tizen>
516         [Obsolete("This has been deprecated in API8 and will be removed in API10. Use FlexLayout instead.")]
517         public Alignment AlignContent
518         {
519             get
520             {
521                 if (NUIApplication.IsUsingXaml)
522                 {
523                     return (Alignment)GetValue(AlignContentProperty);
524                 }
525                 else
526                 {
527                     return (Alignment)GetInternalAlignContentProperty(this);
528                 }
529             }
530             set
531             {
532                 if (NUIApplication.IsUsingXaml)
533                 {
534                     SetValue(AlignContentProperty, value);
535                 }
536                 else
537                 {
538                     SetInternalAlignContentProperty(this, null, value);
539                 }
540                 NotifyPropertyChanged();
541             }
542         }
543
544
545         [EditorBrowsable(EditorBrowsableState.Never)]
546         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
547         {
548             Interop.FlexContainer.DeleteFlexContainer(swigCPtr);
549         }
550
551         /// <summary>
552         /// Enumeration for the instance of child properties belonging to the FlexContainer class.
553         /// </summary>
554         internal class ChildProperty
555         {
556             internal static readonly int FLEX = Interop.FlexContainer.ChildPropertyFlexGet();
557             internal static readonly int AlignSelf = Interop.FlexContainer.ChildPropertyAlignSelfGet();
558             internal static readonly int FlexMargin = Interop.FlexContainer.ChildPropertyFlexMarginGet();
559         }
560
561         internal new class Property
562         {
563             internal static readonly int ContentDirection = Interop.FlexContainer.ContentDirectionGet();
564             internal static readonly int FlexDirection = Interop.FlexContainer.FlexDirectionGet();
565             internal static readonly int FlexWrap = Interop.FlexContainer.FlexWrapGet();
566             internal static readonly int JustifyContent = Interop.FlexContainer.JustifyContentGet();
567             internal static readonly int AlignItems = Interop.FlexContainer.AlignItemsGet();
568             internal static readonly int AlignContent = Interop.FlexContainer.AlignContentGet();
569         }
570     }
571 }