[NUI] add attached property for FlexLayout (#1803)
authorYeongJong Lee <cleanlyj@naver.com>
Mon, 27 Jul 2020 07:06:51 +0000 (16:06 +0900)
committerGitHub <noreply@github.com>
Mon, 27 Jul 2020 07:06:51 +0000 (16:06 +0900)
Attached properties are added for FlexLayout.
 - FlexAlignmentSelf
 - FlexPositionType
 - FlexAspectRatio
 - FlexBasis
 - FlexShrink
 - FlexGrow

For more informantion, see Yoga Layout [documentation](https://yogalayout.com/docs).

See also,
dali-toolkit: https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-toolkit/+/237889/
dali-csharp-binder: https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-csharp-binder/+/237888/
NUI: https://github.com/Samsung/TizenFX/pull/1803

Co-authored-by: neostom432 <31119276+neostom432@users.noreply.github.com>
src/Tizen.NUI/src/internal/Layouting/Interop/Interop.FlexLayout.cs
src/Tizen.NUI/src/public/Layouting/FlexLayout.cs

index 9e71abb..892f8ac 100755 (executable)
@@ -18,7 +18,7 @@ namespace Tizen.NUI
             public static extern global::System.IntPtr FlexLayout_SetMeasureFunction( global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_AddChildWithMargin")]
-            public static extern void FlexLayout_AddChildWithMargin( global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, global::System.Runtime.InteropServices.HandleRef jarg3, Tizen.NUI.FlexLayout.ChildMeasureCallback jarg4, int jarg5);
+            public static extern global::System.IntPtr FlexLayout_AddChildWithMargin( global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, global::System.Runtime.InteropServices.HandleRef jarg3, Tizen.NUI.FlexLayout.ChildMeasureCallback jarg4, int jarg5);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_RemoveChild")]
             public static extern global::System.IntPtr FlexLayout_RemoveChild( global::System.Runtime.InteropServices.HandleRef jarg1, LayoutItem jarg2);
@@ -86,6 +86,42 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_GetFlexItemsAlignment")]
             public static extern int FlexLayout_GetFlexItemsAlignment(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_SetFlexAlignmentSelf")]
+            public static extern void FlexLayout_SetFlexAlignmentSelf(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_GetFlexAlignmentSelf")]
+            public static extern int FlexLayout_GetFlexAlignmentSelf(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_SetFlexPositionType")]
+            public static extern void FlexLayout_SetFlexPositionType(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_GetFlexPositionType")]
+            public static extern int FlexLayout_GetFlexPositionType(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_SetFlexAspectRatio")]
+            public static extern void FlexLayout_SetFlexAspectRatio(global::System.Runtime.InteropServices.HandleRef jarg1, float jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_GetFlexAspectRatio")]
+            public static extern float FlexLayout_GetFlexAspectRatio(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_SetFlexBasis")]
+            public static extern void FlexLayout_SetFlexBasis(global::System.Runtime.InteropServices.HandleRef jarg1, float jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_GetFlexBasis")]
+            public static extern float FlexLayout_GetFlexBasis(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_SetFlexShrink")]
+            public static extern void FlexLayout_SetFlexShrink(global::System.Runtime.InteropServices.HandleRef jarg1, float jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_GetFlexShrink")]
+            public static extern float FlexLayout_GetFlexShrink(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_SetFlexGrow")]
+            public static extern void FlexLayout_SetFlexGrow(global::System.Runtime.InteropServices.HandleRef jarg1, float jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_GetFlexGrow")]
+            public static extern float FlexLayout_GetFlexGrow(global::System.Runtime.InteropServices.HandleRef jarg1);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_SetMaximumWidth")]
             public static extern void FlexLayout_SetFlexMaximumWidth(global::System.Runtime.InteropServices.HandleRef jarg1, float jarg2);
 
index 79f9a92..d1d72bd 100755 (executable)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2019 Samsung Electronics Co., Ltd.
+/* Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ using System.ComponentModel;
 using Tizen.NUI.BaseComponents;
 using System.Runtime.InteropServices;
 using System.Diagnostics;
+using Tizen.NUI.Binding;
 
 namespace Tizen.NUI
 {
@@ -30,9 +31,49 @@ namespace Tizen.NUI
     /// </summary>
     public class FlexLayout : LayoutGroup,  global::System.IDisposable
     {
+        /// <summary>
+        /// FlexItemProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        internal static readonly BindableProperty FlexItemProperty = BindableProperty.CreateAttached("FlexItem", typeof(HandleRef), typeof(FlexLayout), default(HandleRef));
+
+        /// <summary>
+        /// FlexAlignmentSelfProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty FlexAlignmentSelfProperty = BindableProperty.CreateAttached("FlexAlignmentSelf", typeof(AlignmentType), typeof(FlexLayout), AlignmentType.Auto, propertyChanged: OnChildPropertyChanged);
+
+        /// <summary>
+        /// FlexPositionTypeProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty FlexPositionTypeProperty = BindableProperty.CreateAttached("FlexPositionType", typeof(PositionType), typeof(FlexLayout), PositionType.Relative, propertyChanged: OnChildPropertyChanged);
+
+        /// <summary>
+        /// AspectRatioProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty FlexAspectRatioProperty = BindableProperty.CreateAttached("FlexAspectRatio", typeof(float), typeof(FlexLayout), FlexUndefined, validateValue: (bindable, value) => (float)value > 0, propertyChanged: OnChildPropertyChanged);
+
+        /// <summary>
+        /// FlexBasisProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty FlexBasisProperty = BindableProperty.CreateAttached("FlexBasis", typeof(float), typeof(FlexLayout), FlexUndefined, validateValue: (bindable, value) => (float)value >= 0, propertyChanged: OnChildPropertyChanged);
+
+        /// <summary>
+        /// FlexShrinkProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty FlexShrinkProperty = BindableProperty.CreateAttached("FlexShrink", typeof(float), typeof(FlexLayout), 1.0f, validateValue: (bindable, value) => (float)value >= 0, propertyChanged: OnChildPropertyChanged);
+
+        /// <summary>
+        /// FlexGrowProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty FlexGrowProperty = BindableProperty.CreateAttached("FlexGrow", typeof(float), typeof(FlexLayout), FlexUndefined, validateValue: (bindable, value) => (float)value >= 0, propertyChanged: OnChildPropertyChanged);
+
         private static bool LayoutDebugFlex = false; // Debug flag
-        float Flex{ get; set;}
-        int AlignSelf{get; set;}
 
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
         private bool swigCMemOwn;
@@ -57,6 +98,114 @@ namespace Tizen.NUI
           float height;
         };
 
+        /// <summary>
+        /// Get the alignment self of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static AlignmentType GetFlexAlignmentSelf(View view)
+        {
+            return (AlignmentType)view.GetValue(FlexAlignmentSelfProperty);
+        }
+
+        /// <summary>
+        /// Get the position type of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static PositionType GetFlexPositionType(View view)
+        {
+            return (PositionType)view.GetValue(FlexPositionTypeProperty);
+        }
+
+        /// <summary>
+        /// Get the aspect ratio of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static float GetFlexAspectRatio(View view)
+        {
+            return (float)view.GetValue(FlexAspectRatioProperty);
+        }
+
+        /// <summary>
+        /// Get the basis of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static float GetFlexBasis(View view)
+        {
+            return (float)view.GetValue(FlexBasisProperty);
+        }
+
+        /// <summary>
+        /// Get the shrink of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static float GetFlexShrink(View view)
+        {
+            return (float)view.GetValue(FlexShrinkProperty);
+        }
+
+        /// <summary>
+        /// Get the grow of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static float GetFlexGrow(View view)
+        {
+            return (float)view.GetValue(FlexGrowProperty);
+        }
+
+        /// <summary>
+        /// Set the alignment self of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetFlexAlignmentSelf(View view, AlignmentType value)
+        {
+            SetChildValue(view, FlexAlignmentSelfProperty, value);
+        }
+
+        /// <summary>
+        /// Set the position type of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetFlexPositionType(View view, PositionType value)
+        {
+            SetChildValue(view, FlexPositionTypeProperty, value);
+        }
+
+        /// <summary>
+        /// Set the aspect ratio of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetFlexAspectRatio(View view, float value)
+        {
+            SetChildValue(view, FlexAspectRatioProperty, value);
+        }
+
+        /// <summary>
+        /// Set the basis of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetFlexBasis(View view, float value)
+        {
+            SetChildValue(view, FlexBasisProperty, value);
+        }
+
+        /// <summary>
+        /// Set the shrink of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetFlexShrink(View view, float value)
+        {
+            SetChildValue(view, FlexShrinkProperty, value);
+        }
+
+        /// <summary>
+        /// Set the grow of the layout items.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetFlexGrow(View view, float value)
+        {
+            SetChildValue(view, FlexGrowProperty, value);
+        }
+
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         internal delegate MeasuredSize ChildMeasureCallback( global::System.IntPtr child, float width, int measureModeWidth, float height, int measureModeHeight );
 
@@ -400,6 +549,23 @@ namespace Tizen.NUI
             /// </summary>
             Stretch
         }
+        /// <summary>
+        /// Enumeration for the position type of the flex item how it is positioned within its parent.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public enum PositionType
+        {
+            /// <summary>
+            /// Flex items laid out relatively.
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            Relative,
+            /// <summary>
+            /// Flex items laid out absolutely.
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            Absolute
+        }
 
         private MeasuredSize measureChild(global::System.IntPtr childPtr, float width, int measureModeWidth, float height, int measureModeHeight)
         {
@@ -430,7 +596,9 @@ namespace Tizen.NUI
         void InsertChild( LayoutItem child )
         {
             // Store created node for child
-            Interop.FlexLayout.FlexLayout_AddChildWithMargin(swigCPtr, View.getCPtr(child.Owner), Extents.getCPtr(child.Owner.Margin), measureChildDelegate, LayoutChildren.Count-1);
+            IntPtr childPtr = Interop.FlexLayout.FlexLayout_AddChildWithMargin(swigCPtr, View.getCPtr(child.Owner), Extents.getCPtr(child.Owner.Margin), measureChildDelegate, LayoutChildren.Count-1);
+            HandleRef childHandleRef = new HandleRef(child.Owner, childPtr);
+            SetChildValue(child.Owner, FlexItemProperty, childHandleRef);
         }
 
         /// <summary>
@@ -490,6 +658,30 @@ namespace Tizen.NUI
             parentMeasureSpecificationWidth = widthMeasureSpec;
             parentMeasureSpecificationHeight = heightMeasureSpec;
 
+            // Assign child properties
+            for (int i = 0; i < LayoutChildren.Count; i++)
+            {
+                LayoutItem layoutItem = LayoutChildren[i];
+                View Child = layoutItem?.Owner;
+                HandleRef childHandleRef = (HandleRef)Child.GetValue(FlexItemProperty);
+                if (childHandleRef.Handle == IntPtr.Zero || Child == null)
+                    continue;
+
+                AlignmentType flexAlignemnt = GetFlexAlignmentSelf(Child);
+                PositionType flexPosition = GetFlexPositionType(Child);
+                float flexAspectRatio = GetFlexAspectRatio(Child);
+                float flexBasis = GetFlexBasis(Child);
+                float flexShrink = GetFlexShrink(Child);
+                float flexGrow = GetFlexGrow(Child);
+
+                Interop.FlexLayout.FlexLayout_SetFlexAlignmentSelf(childHandleRef, (int)flexAlignemnt);
+                Interop.FlexLayout.FlexLayout_SetFlexPositionType(childHandleRef, (int)flexPosition);
+                Interop.FlexLayout.FlexLayout_SetFlexAspectRatio(childHandleRef, flexAspectRatio);
+                Interop.FlexLayout.FlexLayout_SetFlexBasis(childHandleRef, flexBasis);
+                Interop.FlexLayout.FlexLayout_SetFlexShrink(childHandleRef, flexShrink);
+                Interop.FlexLayout.FlexLayout_SetFlexGrow(childHandleRef, flexGrow);
+            }
+
             Interop.FlexLayout.FlexLayout_CalculateLayout( swigCPtr, width, height, isLayoutRtl );
 
             LayoutLength flexLayoutWidth =  new LayoutLength( Interop.FlexLayout.FlexLayout_GetWidth(swigCPtr) );
@@ -535,4 +727,4 @@ namespace Tizen.NUI
         }
 
     } // FLexlayout
-} // namesspace Tizen.NUI
\ No newline at end of file
+} // namesspace Tizen.NUI