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