[NUI] correct logical operator in enum validation (#2045)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Layouting / FlexLayout.cs
1 /* Copyright (c) 2019 Samsung Electronics Co., Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  */
16
17 using System;
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20 using System.Runtime.InteropServices;
21 using System.Diagnostics;
22 using Tizen.NUI.Binding;
23
24 namespace Tizen.NUI
25 {
26     /// <summary>
27     /// This class implements a flex layout.
28     /// The flex layout implementation is based on open source Facebook Yoga layout engine.
29     /// For more information about the flex layout API and how to use it please refer to https://yogalayout.com/docs/
30     /// We implement the subset of the API in the class below.
31     /// </summary>
32     public class FlexLayout : LayoutGroup, global::System.IDisposable
33     {
34         /// <summary>
35         /// FlexItemProperty
36         /// </summary>
37         [EditorBrowsable(EditorBrowsableState.Never)]
38         internal static readonly BindableProperty FlexItemProperty = BindableProperty.CreateAttached("FlexItem", typeof(HandleRef), typeof(FlexLayout), default(HandleRef));
39
40         /// <summary>
41         /// FlexAlignmentSelfProperty
42         /// </summary>
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public static readonly BindableProperty FlexAlignmentSelfProperty = BindableProperty.CreateAttached("FlexAlignmentSelf", typeof(AlignmentType), typeof(FlexLayout), AlignmentType.Auto, validateValue: ValidateEnum((int)AlignmentType.Auto, (int)AlignmentType.Stretch), propertyChanged: OnChildPropertyChanged);
45
46         /// <summary>
47         /// FlexPositionTypeProperty
48         /// </summary>
49         [EditorBrowsable(EditorBrowsableState.Never)]
50         public static readonly BindableProperty FlexPositionTypeProperty = BindableProperty.CreateAttached("FlexPositionType", typeof(PositionType), typeof(FlexLayout), PositionType.Relative, validateValue: ValidateEnum((int)PositionType.Relative, (int)PositionType.Absolute), propertyChanged: OnChildPropertyChanged);
51
52         /// <summary>
53         /// AspectRatioProperty
54         /// </summary>
55         [EditorBrowsable(EditorBrowsableState.Never)]
56         public static readonly BindableProperty FlexAspectRatioProperty = BindableProperty.CreateAttached("FlexAspectRatio", typeof(float), typeof(FlexLayout), FlexUndefined, validateValue: (bindable, value) => (float)value > 0, propertyChanged: OnChildPropertyChanged);
57
58         /// <summary>
59         /// FlexBasisProperty
60         /// </summary>
61         [EditorBrowsable(EditorBrowsableState.Never)]
62         public static readonly BindableProperty FlexBasisProperty = BindableProperty.CreateAttached("FlexBasis", typeof(float), typeof(FlexLayout), FlexUndefined, validateValue: (bindable, value) => (float)value >= 0, propertyChanged: OnChildPropertyChanged);
63
64         /// <summary>
65         /// FlexShrinkProperty
66         /// </summary>
67         [EditorBrowsable(EditorBrowsableState.Never)]
68         public static readonly BindableProperty FlexShrinkProperty = BindableProperty.CreateAttached("FlexShrink", typeof(float), typeof(FlexLayout), 1.0f, validateValue: (bindable, value) => (float)value >= 0, propertyChanged: OnChildPropertyChanged);
69
70         /// <summary>
71         /// FlexGrowProperty
72         /// </summary>
73         [EditorBrowsable(EditorBrowsableState.Never)]
74         public static readonly BindableProperty FlexGrowProperty = BindableProperty.CreateAttached("FlexGrow", typeof(float), typeof(FlexLayout), FlexUndefined, validateValue: (bindable, value) => (float)value >= 0, propertyChanged: OnChildPropertyChanged);
75
76         private static bool LayoutDebugFlex = false; // Debug flag
77
78         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
79         private bool swigCMemOwn;
80         private bool disposed;
81         private bool isDisposeQueued = false;
82
83         private MeasureSpecification parentMeasureSpecificationWidth;
84         private MeasureSpecification parentMeasureSpecificationHeight;
85
86         private IntPtr _rootFlex;  // Pointer to the unmanged flex layout class.
87
88         internal const float FlexUndefined = 10E20F; // Auto setting which is equivalent to WrapContent.
89
90         internal struct MeasuredSize
91         {
92             public MeasuredSize(float x, float y)
93             {
94                 width = x;
95                 height = y;
96             }
97             public float width;
98             public float height;
99         };
100
101         /// <summary>
102         /// Gets the alignment self of the child view.
103         /// </summary>
104         /// <seealso cref="SetFlexAlignmentSelf(View, AlignmentType)"/>
105         /// <param name="view">The child view.</param>
106         /// <returns> The value of alignment self.</returns>
107         /// <since_tizen> 8 </since_tizen>
108         public static AlignmentType GetFlexAlignmentSelf(View view) => GetAttachedValue<AlignmentType>(view, FlexAlignmentSelfProperty);
109
110         /// <summary>
111         /// Gets the position type of the child view.
112         /// </summary>
113         /// <seealso cref="SetFlexPositionType(View, PositionType)"/>
114         /// <param name="view">The child view.</param>
115         /// <returns> The value of position type</returns>
116         /// <since_tizen> 8 </since_tizen>
117         public static PositionType GetFlexPositionType(View view) => GetAttachedValue<PositionType>(view, FlexPositionTypeProperty);
118
119         /// <summary>
120         /// Gets the aspect ratio of the child view.
121         /// </summary>
122         /// <seealso cref="SetFlexAspectRatio(View, float)"/>
123         /// <param name="view">The child view.</param>
124         /// <returns> The value of aspect ratio</returns>
125         /// <since_tizen> 8 </since_tizen>
126         public static float GetFlexAspectRatio(View view) => GetAttachedValue<float>(view, FlexAspectRatioProperty);
127
128         /// <summary>
129         /// Gets the basis of the child view.
130         /// </summary>
131         /// <seealso cref="SetFlexBasis(View, float)"/>
132         /// <param name="view">The child view.</param>
133         /// <returns> The value of basis</returns>
134         /// <since_tizen> 8 </since_tizen>
135         public static float GetFlexBasis(View view) => GetAttachedValue<float>(view, FlexBasisProperty);
136
137         /// <summary>
138         /// Gets the shrink of the child view.
139         /// </summary>
140         /// <seealso cref="SetFlexShrink(View, float)"/>
141         /// <param name="view">The child view.</param>
142         /// <returns> The value of shrink</returns>
143         /// <since_tizen> 8 </since_tizen>
144         public static float GetFlexShrink(View view) => GetAttachedValue<float>(view, FlexShrinkProperty);
145
146         /// <summary>
147         /// Gets the grow of the child view.
148         /// </summary>
149         /// <seealso cref="SetFlexGrow(View, float)"/>
150         /// <param name="view">The child view.</param>
151         /// <returns> The value of grow</returns>
152         /// <since_tizen> 8 </since_tizen>
153         public static float GetFlexGrow(View view) => GetAttachedValue<float>(view, FlexGrowProperty);
154
155         /// <summary>
156         /// Sets the alignment self of the child view.<br/>
157         /// Alignment self has the same options and effect as <see cref="ItemsAlignment"/> but instead of affecting the children within a container,
158         /// you can apply this property to a single child to change its alignment within its parent.<br/>
159         /// Alignment self overrides any option set by the parent with <see cref="ItemsAlignment"/>.
160         /// </summary>
161         /// <param name="view">The child view.</param>
162         /// <param name="value">The value of alignment self.</param>
163         /// <since_tizen> 8 </since_tizen>
164         public static void SetFlexAlignmentSelf(View view, AlignmentType value) => SetAttachedValue(view, FlexAlignmentSelfProperty, value);
165
166         /// <summary>
167         /// Sets the position type of the child view.<br/>
168         /// The position type of an element defines how it is positioned within its parent.
169         /// By default a child is positioned relatively. This means a child is positioned according to the normal flow of the layout,
170         /// and then offset relative to that position based on the values of <see cref="View.Margin"/>.<br/>
171         /// When positioned absolutely an element doesn't take part in the normal layout flow.
172         /// It is instead laid out independent of its siblings. The position is determined based on the <see cref="View.Margin"/>.
173         /// </summary>
174         /// <param name="view">The child view.</param>
175         /// <param name="value">The value of position type.</param>
176         /// <since_tizen> 8 </since_tizen>
177         public static void SetFlexPositionType(View view, PositionType value) => SetAttachedValue(view, FlexPositionTypeProperty, value);
178
179         /// <summary>
180         /// Sets the aspect ratio of the child view.
181         /// Aspect ratio Defines as the ratio between the width and the height of a node
182         /// e.g. if a node has an aspect ratio of 2 then its width is twice the size of its height.<br/>
183         /// Aspect ratio accepts any floating point value > 0. this has higher priority than flex grow.
184         /// </summary>
185         /// <param name="view">The child view.</param>
186         /// <param name="value">The value of aspect ratio</param>
187         /// <since_tizen> 8 </since_tizen>
188         public static void SetFlexAspectRatio(View view, float value) => SetAttachedValue(view, FlexAspectRatioProperty, value);
189
190         /// <summary>
191         /// Sets the flex basis of the child view.
192         /// Flex basis is an axis-independent way of providing the default size of an item along the main axis.<br/>
193         /// Setting the flex basis of a child is similar to setting the width of that child if its parent is a container with <see cref="FlexDirection.Row"/>
194         /// or setting the height of a child if its parent is a container with <see cref="FlexDirection.Column"/>.<br/>
195         /// The flex basis of an item is the default size of that item, the size of the item before any flex grow and flex shrink calculations are performed.
196         /// </summary>
197         /// <param name="view">The child view.</param>
198         /// <param name="value">The value of basis</param>
199         /// <since_tizen> 8 </since_tizen>
200         public static void SetFlexBasis(View view, float value) => SetAttachedValue(view, FlexBasisProperty, value);
201
202         /// <summary>
203         /// Sets the flex shrink of the child view.
204         /// Flex shrink describes how to shrink children along the main axis in the case that the total size of the children overflow the size of the container on the main axis.<br/>
205         /// Flex shrink is very similar to flex grow and can be thought of in the same way if any overflowing size is considered to be negative remaining space.
206         /// These two properties also work well together by allowing children to grow and shrink as needed.<br/>
207         /// Flex shrink accepts any floating point value >= 0, with 1 being the default value. A container will shrink its children weighted by the child’s flex shrink value.
208         /// </summary>
209         /// <param name="view">The child view.</param>
210         /// <param name="value">The value of shrink</param>
211         /// <since_tizen> 8 </since_tizen>
212         public static void SetFlexShrink(View view, float value) => SetAttachedValue(view, FlexShrinkProperty, value);
213
214         /// <summary>
215         /// Sets the grow of the child view.
216         /// Flex grow describes how any space within a container should be distributed among its children along the main axis.
217         /// After laying out its children, a container will distribute any remaining space according to the flex grow values specified by its children.<br/>
218         /// Flex grow accepts any floating point value >= 0, with 0 being the default value.<br/>
219         /// A container will distribute any remaining space among its children weighted by the child’s flex grow value.
220         /// </summary>
221         /// <param name="view">The child view.</param>
222         /// <param name="value">The value of flex</param>
223         /// <since_tizen> 8 </since_tizen>
224         public static void SetFlexGrow(View view, float value) => SetAttachedValue(view, FlexGrowProperty, value);
225
226         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
227         internal delegate void ChildMeasureCallback( global::System.IntPtr child, float width, int measureModeWidth, float height, int measureModeHeight, out MeasuredSize measureSize );
228
229         event ChildMeasureCallback measureChildDelegate; // Stores a delegate to the child measure callback. Used for all children of this FlexLayout.
230
231         internal FlexLayout(global::System.IntPtr cPtr, bool cMemoryOwn)
232         {
233             swigCMemOwn = cMemoryOwn;
234             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
235             _rootFlex = Interop.FlexLayout.FlexLayout_New();
236             measureChildDelegate = new ChildMeasureCallback(measureChild);
237         }
238
239         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FlexLayout obj)
240         {
241             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
242         }
243
244         /// <inheritdoc/>
245         /// <since_tizen> 6 </since_tizen>
246         public void Dispose()
247         {
248             // Throw exception if Dispose() is called in separate thread.
249             if (!Window.IsInstalled())
250             {
251                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
252             }
253
254             if (isDisposeQueued)
255             {
256                 Dispose(DisposeTypes.Implicit);
257             }
258             else
259             {
260                 Dispose(DisposeTypes.Explicit);
261                 System.GC.SuppressFinalize(this);
262             }
263         }
264
265         /// <inheritdoc/>
266         /// <since_tizen> 6 </since_tizen>
267         protected virtual void Dispose(DisposeTypes type)
268         {
269             if (disposed)
270             {
271                 return;
272             }
273
274             if (type == DisposeTypes.Explicit)
275             {
276                 // Called by User
277                 // Release your own managed resources here.
278                 // You should release all of your own disposable objects here.
279
280             }
281
282             // Release your own unmanaged resources here.
283             // You should not access any managed member here except static instance.
284             // because the execution order of Finalizes is non-deterministic.
285             if (swigCPtr.Handle != global::System.IntPtr.Zero)
286             {
287                 if (swigCMemOwn)
288                 {
289                     swigCMemOwn = false;
290                     Interop.FlexLayout.delete_FlexLayout(swigCPtr);
291                 }
292                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
293             }
294             disposed = true;
295         }
296
297         /// <summary>
298         /// Creates a FlexLayout object.
299         /// </summary>
300         /// <since_tizen> 6 </since_tizen>
301         public FlexLayout() : this(Interop.FlexLayout.FlexLayout_New(), true)
302         {
303             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304         }
305
306         internal static FlexLayout DownCast(BaseHandle handle)
307         {
308             FlexLayout ret = new FlexLayout(Interop.FlexLayout.FlexLayout_DownCast(BaseHandle.getCPtr(handle)), true);
309             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310             return ret;
311         }
312
313         internal FlexLayout(FlexLayout other) : this(Interop.FlexLayout.new_FlexLayout__SWIG_1(FlexLayout.getCPtr(other)), true)
314         {
315             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316         }
317
318         internal FlexLayout.AlignmentType GetFlexAlignment()
319         {
320             FlexLayout.AlignmentType ret = (FlexLayout.AlignmentType)Interop.FlexLayout.FlexLayout_GetFlexAlignment(swigCPtr);
321             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322             return ret;
323         }
324
325         internal FlexLayout.AlignmentType GetFlexItemsAlignment()
326         {
327             FlexLayout.AlignmentType ret = (FlexLayout.AlignmentType)Interop.FlexLayout.FlexLayout_GetFlexItemsAlignment(swigCPtr);
328             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329             return ret;
330         }
331
332         /// <summary>
333         /// Gets/Sets the flex direction in the layout.
334         /// The direction of the main-axis which determines the direction that flex items are laid out.
335         /// </summary>
336         /// <exception cref="InvalidEnumArgumentException">Thrown when using invalid arguments that are enumerators.</exception>
337         /// <since_tizen> 6 </since_tizen>
338         public FlexDirection Direction
339         {
340             get => (FlexDirection)Interop.FlexLayout.FlexLayout_GetFlexDirection(swigCPtr);
341             set
342             {
343                 if (value < FlexDirection.Column || value > FlexDirection.RowReverse)
344                     throw new InvalidEnumArgumentException(nameof(Direction));
345
346                 Interop.FlexLayout.FlexLayout_SetFlexDirection(swigCPtr, (int)value);
347                 RequestLayout();
348             }
349         }
350
351         /// <summary>
352         /// Gets/Sets the justification in the layout.
353         /// Justify content describes how to align children within the main axis of their container.<br/>
354         /// For example, you can use this property to center a child horizontally within a container with <see cref="Direction"/> set to <see cref="FlexDirection.Row"/>
355         /// or vertically within a container with <see cref="Direction"/> set to <see cref="FlexDirection.Column"/>.
356         /// </summary>
357         /// <exception cref="InvalidEnumArgumentException">Thrown when using invalid arguments that are enumerators.</exception>
358         /// <since_tizen> 6 </since_tizen>
359         public FlexJustification Justification
360         {
361             get => (FlexJustification)Interop.FlexLayout.FlexLayout_GetFlexJustification(swigCPtr);
362             set
363             {
364                 if (value < FlexJustification.FlexStart || value > FlexJustification.SpaceAround)
365                     throw new InvalidEnumArgumentException(nameof(Justification));
366
367                 Interop.FlexLayout.FlexLayout_SetFlexJustification(swigCPtr, (int)value);
368                 RequestLayout();
369             }
370         }
371
372         /// <summary>
373         /// Gets/Sets the wrap in the layout.
374         /// The flex wrap property is set on containers and controls what happens when children overflow the size of the container along the main axis.<br/>
375         /// By default children are forced into a single line (which can shrink elements).<br/>
376         /// If wrapping is allowed items are wrapped into multiple lines along the main axis if needed. wrap reverse behaves the same, but the order of the lines is reversed.<br/>
377         /// When wrapping lines <see cref="Alignment"/> can be used to specify how the lines are placed in the container.
378         /// </summary>
379         /// <exception cref="InvalidEnumArgumentException">Thrown when using invalid arguments that are enumerators.</exception>
380         /// <since_tizen> 6 </since_tizen>
381         public FlexWrapType WrapType
382         {
383             get => (FlexWrapType)Interop.FlexLayout.FlexLayout_GetFlexWrap(swigCPtr);
384             set
385             {
386                 if (value != FlexWrapType.NoWrap && value != FlexWrapType.Wrap)
387                     throw new InvalidEnumArgumentException(nameof(WrapType));
388
389                 Interop.FlexLayout.FlexLayout_SetFlexWrap(swigCPtr, (int)value);
390                 RequestLayout();
391
392             }
393         }
394
395         /// <summary>
396         /// Gets/Sets the alignment of the layout content.
397         /// Alignment defines the distribution of lines along the cross-axis.<br/>
398         /// This only has effect when items are wrapped to multiple lines using flex wrap.
399         /// </summary>
400         /// <exception cref="InvalidEnumArgumentException">Thrown when using invalid arguments that are enumerators.</exception>
401         /// <since_tizen> 6 </since_tizen>
402         public AlignmentType Alignment
403         {
404             get => GetFlexAlignment();
405             set
406             {
407                 if (value < AlignmentType.Auto || value > AlignmentType.Stretch)
408                     throw new InvalidEnumArgumentException(nameof(Alignment));
409
410                 Interop.FlexLayout.FlexLayout_SetFlexAlignment(swigCPtr, (int)value);
411                 RequestLayout();
412             }
413         }
414
415         /// <summary>
416         /// Gets/Sets the alignment of the layout items.
417         /// Items alignment describes how to align children along the cross axis of their container.<br/>
418         /// Align items is very similar to <see cref="Justification"/> but instead of applying to the main axis, align items applies to the cross axis.
419         /// </summary>
420         /// <exception cref="InvalidEnumArgumentException">Thrown when using invalid arguments that are enumerators.</exception>
421         /// <since_tizen> 6 </since_tizen>
422         public AlignmentType ItemsAlignment
423         {
424             get => GetFlexItemsAlignment();
425             set
426             {
427                 if (value < AlignmentType.Auto || value > AlignmentType.Stretch)
428                     throw new InvalidEnumArgumentException(nameof(ItemsAlignment));
429
430                 Interop.FlexLayout.FlexLayout_SetFlexItemsAlignment(swigCPtr, (int)value);
431                 RequestLayout();
432             }
433         }
434
435         /// <summary>
436         /// Enumeration for the direction of the main axis in the flex container.
437         /// This determines the direction that flex items are laid out in the flex container.
438         /// </summary>
439         /// <since_tizen> 6 </since_tizen>
440         public enum FlexDirection
441         {
442             /// <summary>
443             /// The flexible items are displayed vertically as a column
444             /// </summary>
445             Column,
446             /// <summary>
447             /// The flexible items are displayed vertically as a column, but in reverse order
448             /// </summary>
449             ColumnReverse,
450             /// <summary>
451             /// The flexible items are displayed horizontally as a row
452             /// </summary>
453             Row,
454             /// <summary>
455             /// The flexible items are displayed horizontally as a row, but in reverse order
456             /// </summary>
457             RowReverse
458         }
459
460         /// <summary>
461         /// Enumeration for the alignment of the flex items when the items do not use all available space on the main-axis.
462         /// </summary>
463         /// <since_tizen> 6 </since_tizen>
464         public enum FlexJustification
465         {
466             /// <summary>
467             /// Items are positioned at the beginning of the container.
468             /// </summary>
469             FlexStart,
470             /// <summary>
471             /// Items are positioned at the center of the container.
472             /// </summary>
473             Center,
474             /// <summary>
475             /// Items are positioned at the end of the container.
476             /// </summary>
477             FlexEnd,
478             /// <summary>
479             /// Items are positioned with equal space between the lines.
480             /// </summary>
481             SpaceBetween,
482             /// <summary>
483             /// Items are positioned with equal space before, between, and after the lines.<br/>
484             /// Compared to <see cref="FlexJustification.SpaceBetween"/> using <see cref="FlexJustification.SpaceAround"/>
485             /// will result in space being distributed to the beginning of the first child and end of the last child.
486             /// </summary>
487             SpaceAround
488         }
489
490         /// <summary>
491         /// Enumeration for the wrap type of the flex container when there is no enough room for all the items on one flex line.
492         /// </summary>
493         /// <since_tizen> 6 </since_tizen>
494         public enum FlexWrapType
495         {
496             /// <summary>
497             /// Flex items laid out in single line (shrunk to fit the flex container along the main axis)
498             /// </summary>
499             NoWrap,
500             /// <summary>
501             /// Flex items laid out in multiple lines if needed
502             /// </summary>
503             Wrap
504         }
505
506         /// <summary>
507         /// Enumeration for the alignment of the flex items or lines when the items or lines do not use all the available space on the cross-axis.
508         /// </summary>
509         /// <since_tizen> 6 </since_tizen>
510         public enum AlignmentType
511         {
512             /// <summary>
513             /// Inherits the same alignment from the parent
514             /// </summary>
515             Auto,
516             /// <summary>
517             /// At the beginning of the container
518             /// </summary>
519             FlexStart,
520             /// <summary>
521             /// At the center of the container
522             /// </summary>
523             Center,
524             /// <summary>
525             /// At the end of the container
526             /// </summary>
527             FlexEnd,
528             /// <summary>
529             /// Stretch to fit the container
530             /// </summary>
531             Stretch
532         }
533
534         /// <summary>
535         /// Enumeration for the position type of the flex item how it is positioned within its parent.
536         /// </summary>
537         /// <since_tizen> 8 </since_tizen>
538         public enum PositionType
539         {
540             /// <summary>
541             /// Flex items laid out relatively.
542             /// </summary>
543             Relative,
544             /// <summary>
545             /// Flex items laid out absolutely.
546             /// </summary>
547             Absolute
548         }
549
550         private void measureChild(global::System.IntPtr childPtr, float width, int measureModeWidth, float height, int measureModeHeight, out MeasuredSize measureSize)
551         {
552             // We need to measure child layout
553             View child = Registry.GetManagedBaseHandleFromNativePtr(childPtr) as View;
554
555             LayoutItem childLayout = child.Layout;
556
557             MeasureSpecification childWidthMeasureSpec = GetChildMeasureSpecification(
558                                     new MeasureSpecification(
559                                         new LayoutLength(parentMeasureSpecificationWidth.Size - (child.Margin.Start + child.Margin.End)),
560                                         parentMeasureSpecificationWidth.Mode),
561                                     new LayoutLength(Padding.Start + Padding.End),
562                                     new LayoutLength(child.WidthSpecification));
563
564             MeasureSpecification childHeightMeasureSpec = GetChildMeasureSpecification(
565                                     new MeasureSpecification(
566                                         new LayoutLength(parentMeasureSpecificationHeight.Size - (child.Margin.Top + child.Margin.Bottom)),
567                                         parentMeasureSpecificationHeight.Mode),
568                                     new LayoutLength(Padding.Top + Padding.Bottom),
569                                     new LayoutLength(child.HeightSpecification));
570
571             childLayout.Measure(childWidthMeasureSpec, childHeightMeasureSpec);
572
573             measureSize.width = childLayout.MeasuredWidth.Size.AsRoundedValue();
574             measureSize.height = childLayout.MeasuredHeight.Size.AsRoundedValue();
575         }
576
577         void InsertChild(LayoutItem child)
578         {
579             // Store created node for child
580             IntPtr childPtr = Interop.FlexLayout.FlexLayout_AddChildWithMargin(swigCPtr, View.getCPtr(child.Owner), Extents.getCPtr(child.Owner.Margin), measureChildDelegate, LayoutChildren.Count - 1);
581             HandleRef childHandleRef = new HandleRef(child.Owner, childPtr);
582             SetAttachedValue(child.Owner, FlexItemProperty, childHandleRef);
583         }
584
585         /// <summary>
586         /// Callback when child is added to container.<br />
587         /// Derived classes can use this to set their own child properties on the child layout's owner.<br />
588         /// </summary>
589         /// <param name="child">The Layout child.</param>
590         /// <since_tizen> 6 </since_tizen>
591         protected override void OnChildAdd(LayoutItem child)
592         {
593             InsertChild(child);
594         }
595
596         /// <summary>
597         /// Callback when child is removed from container.<br />
598         /// </summary>
599         /// <param name="child">The Layout child.</param>
600         /// <since_tizen> 6 </since_tizen>
601         protected override void OnChildRemove(LayoutItem child)
602         {
603             // When child View is removed from it's parent View (that is a Layout) then remove it from the layout too.
604             // FlexLayout refers to the child as a View not LayoutItem.
605             Interop.FlexLayout.FlexLayout_RemoveChild(swigCPtr, child);
606         }
607
608         /// <summary>
609         /// Measure the layout and its content to determine the measured width and the measured height.<br />
610         /// </summary>
611         /// <param name="widthMeasureSpec">horizontal space requirements as imposed by the parent.</param>
612         /// <param name="heightMeasureSpec">vertical space requirements as imposed by the parent.</param>
613         /// <since_tizen> 6 </since_tizen>
614         protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
615         {
616             bool isLayoutRtl = Owner.LayoutDirection == ViewLayoutDirectionType.RTL;
617             Extents padding = Owner.Padding;
618             Extents margin = Owner.Margin;
619
620             Interop.FlexLayout.FlexLayout_SetMargin(swigCPtr, Extents.getCPtr(margin));
621             Interop.FlexLayout.FlexLayout_SetPadding(swigCPtr, Extents.getCPtr(padding));
622
623             float width = FlexUndefined; // Behaves as WrapContent (Flex Auto)
624             float height = FlexUndefined; // Behaves as WrapContent (Flex Auto)
625
626             if (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly || widthMeasureSpec.Mode == MeasureSpecification.ModeType.AtMost)
627             {
628                 width = widthMeasureSpec.Size.AsDecimal();
629             }
630
631             if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly || heightMeasureSpec.Mode == MeasureSpecification.ModeType.AtMost)
632             {
633                 height = heightMeasureSpec.Size.AsDecimal();
634             }
635
636             // Save measureSpec to measure children.
637             // In other Layout, we can pass it as parameter to measuring child but in FlexLayout we can't
638             // because measurChild function is called by native callback.
639             parentMeasureSpecificationWidth = widthMeasureSpec;
640             parentMeasureSpecificationHeight = heightMeasureSpec;
641
642             // Assign child properties
643             for (int i = 0; i < LayoutChildren.Count; i++)
644             {
645                 LayoutItem layoutItem = LayoutChildren[i];
646                 View Child = layoutItem?.Owner;
647                 HandleRef childHandleRef = (HandleRef)Child.GetValue(FlexItemProperty);
648                 if (childHandleRef.Handle == IntPtr.Zero || Child == null)
649                     continue;
650
651                 AlignmentType flexAlignemnt = GetFlexAlignmentSelf(Child);
652                 PositionType flexPosition = GetFlexPositionType(Child);
653                 float flexAspectRatio = GetFlexAspectRatio(Child);
654                 float flexBasis = GetFlexBasis(Child);
655                 float flexShrink = GetFlexShrink(Child);
656                 float flexGrow = GetFlexGrow(Child);
657
658                 Interop.FlexLayout.FlexLayout_SetFlexAlignmentSelf(childHandleRef, (int)flexAlignemnt);
659                 Interop.FlexLayout.FlexLayout_SetFlexPositionType(childHandleRef, (int)flexPosition);
660                 Interop.FlexLayout.FlexLayout_SetFlexAspectRatio(childHandleRef, flexAspectRatio);
661                 Interop.FlexLayout.FlexLayout_SetFlexBasis(childHandleRef, flexBasis);
662                 Interop.FlexLayout.FlexLayout_SetFlexShrink(childHandleRef, flexShrink);
663                 Interop.FlexLayout.FlexLayout_SetFlexGrow(childHandleRef, flexGrow);
664             }
665
666             Interop.FlexLayout.FlexLayout_CalculateLayout(swigCPtr, width, height, isLayoutRtl);
667
668             LayoutLength flexLayoutWidth = new LayoutLength(Interop.FlexLayout.FlexLayout_GetWidth(swigCPtr));
669             LayoutLength flexLayoutHeight = new LayoutLength(Interop.FlexLayout.FlexLayout_GetHeight(swigCPtr));
670
671             Debug.WriteLineIf(LayoutDebugFlex, "FlexLayout OnMeasure width:" + flexLayoutWidth.AsRoundedValue()
672                                                 + " height:" + flexLayoutHeight.AsRoundedValue());
673
674             SetMeasuredDimensions(GetDefaultSize(flexLayoutWidth, widthMeasureSpec),
675                                    GetDefaultSize(flexLayoutHeight, heightMeasureSpec));
676         }
677
678         /// <summary>
679         /// Assign a size and position to each of its children.<br />
680         /// </summary>
681         /// <param name="changed">This is a new size or position for this layout.</param>
682         /// <param name="left">Left position, relative to parent.</param>
683         /// <param name="top"> Top position, relative to parent.</param>
684         /// <param name="right">Right position, relative to parent.</param>
685         /// <param name="bottom">Bottom position, relative to parent.</param>
686         /// <since_tizen> 6 </since_tizen>
687         protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
688         {
689
690             bool isLayoutRtl = Owner.LayoutDirection == ViewLayoutDirectionType.RTL;
691             LayoutLength width = right - left;
692             LayoutLength height = bottom - top;
693
694             // Call to FlexLayout implementation to calculate layout values for later retrieval.
695             Interop.FlexLayout.FlexLayout_CalculateLayout(swigCPtr, width.AsDecimal(), height.AsDecimal(), isLayoutRtl);
696
697             int count = LayoutChildren.Count;
698             for (int childIndex = 0; childIndex < count; childIndex++)
699             {
700                 LayoutItem childLayout = LayoutChildren[childIndex];
701                 if (childLayout != null)
702                 {
703                     // Get the frame for the child, start, top, end, bottom.
704                     Vector4 frame = new Vector4(Interop.FlexLayout.FlexLayout_GetNodeFrame(swigCPtr, childIndex), true);
705                     childLayout.Layout(new LayoutLength(frame.X), new LayoutLength(frame.Y), new LayoutLength(frame.Z), new LayoutLength(frame.W));
706                 }
707             }
708         }
709
710     } // FLexlayout
711 } // namesspace Tizen.NUI