[NUI] FlexLayout Interop and Undefined fixes (#1134)
authoragnelovaz <agnelo.vaz@samsung.com>
Thu, 21 Nov 2019 10:22:16 +0000 (10:22 +0000)
committerGitHub <noreply@github.com>
Thu, 21 Nov 2019 10:22:16 +0000 (10:22 +0000)
Fix Interops returning IntPtrs instead of floats
Fix measured child size when natural size zero.
Add Undefined constant map WrapContent to

Change-Id: Ie661294a155fb4cf971ddb96bba30472fb80168b

src/Tizen.NUI/src/internal/Layouting/Interop/Interop.FlexLayout.cs
src/Tizen.NUI/src/public/Layouting/FlexLayout.cs

index 9a11c5b..af7b8c0 100755 (executable)
@@ -27,10 +27,10 @@ namespace Tizen.NUI
             public static extern global::System.IntPtr FlexLayout_CalculateLayout( global::System.Runtime.InteropServices.HandleRef jarg1, float jarg2, float jarg3, bool jarg4);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_GetWidth")]
-            public static extern global::System.IntPtr FlexLayout_GetWidth(global::System.Runtime.InteropServices.HandleRef jarg1);
+            public static extern float FlexLayout_GetWidth(global::System.Runtime.InteropServices.HandleRef jarg1);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_GetHeight")]
-            public static extern global::System.IntPtr FlexLayout_GetHeight(global::System.Runtime.InteropServices.HandleRef jarg1);
+            public static extern float FlexLayout_GetHeight(global::System.Runtime.InteropServices.HandleRef jarg1);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FlexLayout_GetNodeFrame")]
             public static extern global::System.IntPtr FlexLayout_GetNodeFrame(global::System.Runtime.InteropServices.HandleRef jarg1, int index);
index 3e5ed67..12713c6 100755 (executable)
@@ -18,6 +18,7 @@ using System;
 using System.ComponentModel;
 using Tizen.NUI.BaseComponents;
 using System.Runtime.InteropServices;
+using System.Diagnostics;
 
 namespace Tizen.NUI
 {
@@ -29,6 +30,7 @@ namespace Tizen.NUI
     /// </summary>
     public class FlexLayout : LayoutGroup,  global::System.IDisposable
     {
+        private static bool LayoutDebugFlex = false; // Debug flag
         float Flex{ get; set;}
         int AlignSelf{get; set;}
 
@@ -39,6 +41,8 @@ namespace Tizen.NUI
 
         private IntPtr _rootFlex;  // Pointer to the unmanged flex layout class.
 
+        internal const float FlexUndefined = 10E20F; // Auto setting which is equivalent to WrapContent.
+
         internal struct MeasuredSize
         {
           public MeasuredSize(float x, float y)
@@ -400,8 +404,20 @@ namespace Tizen.NUI
             Size2D viewSize = new Size2D(8,8);
             if(view)
             {
-              viewSize = view.NaturalSize2D;
+                viewSize = view.Size2D;
+            }
+
+            // If size not set on child then use NaturalSize
+            if(viewSize.Width ==0 && viewSize.Height==0)
+            {
+                viewSize = view.NaturalSize2D;
             }
+
+            Debug.WriteLineIf( LayoutDebugFlex, "FlexLayout measureChild View:" + view.Name
+                                               + "Size:" + viewSize.Width
+                                               + ","
+                                               + viewSize.Height);
+
             return new MeasuredSize(viewSize.Width,viewSize.Height);
         }
 
@@ -449,8 +465,8 @@ namespace Tizen.NUI
             Interop.FlexLayout.FlexLayout_SetMargin(swigCPtr, Extents.getCPtr(margin));
             Interop.FlexLayout.FlexLayout_SetPadding(swigCPtr, Extents.getCPtr(padding));
 
-            float width = 0.0f;
-            float height = 0.0f;
+            float width = FlexUndefined; // Behaves as WrapContent (Flex Auto)
+            float height = FlexUndefined; // Behaves as WrapContent (Flex Auto)
 
             if( widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly ||  widthMeasureSpec.Mode == MeasureSpecification.ModeType.AtMost )
             {
@@ -464,8 +480,14 @@ namespace Tizen.NUI
 
             Interop.FlexLayout.FlexLayout_CalculateLayout( swigCPtr, width, height, isLayoutRtl );
 
-            SetMeasuredDimensions( GetDefaultSize( new LayoutLength( (float)Interop.FlexLayout.FlexLayout_GetWidth(swigCPtr) ), widthMeasureSpec ),
-                                   GetDefaultSize( new LayoutLength( (float)Interop.FlexLayout.FlexLayout_GetHeight(swigCPtr) ), heightMeasureSpec ) );
+            LayoutLength flexLayoutWidth =  new LayoutLength( Interop.FlexLayout.FlexLayout_GetWidth(swigCPtr) );
+            LayoutLength flexLayoutHeight = new LayoutLength( Interop.FlexLayout.FlexLayout_GetHeight(swigCPtr) );
+
+            Debug.WriteLineIf( LayoutDebugFlex, "FlexLayout OnMeasure width:" + flexLayoutWidth.AsRoundedValue()
+                                                + " height:" + flexLayoutHeight.AsRoundedValue() );
+
+            SetMeasuredDimensions( GetDefaultSize(flexLayoutWidth, widthMeasureSpec ),
+                                   GetDefaultSize(flexLayoutHeight, heightMeasureSpec ) );
         }
 
         /// <summary>