[NUI] respect flex child margin changes (#2271)
authorYeongJong Lee <cleanlyj@naver.com>
Mon, 23 Nov 2020 11:20:22 +0000 (20:20 +0900)
committerJiyun Yang <ji.yang@samsung.com>
Thu, 26 Nov 2020 08:19:50 +0000 (17:19 +0900)
The flex child margin is only set when a flex child is added to flexlayout,
so margin changes after `View.Add` are ignored.

To respect child margin changes, This patch add code to set flex margin in
`OnMeasure`.

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

index 7fccbde..53ac89d 100755 (executable)
@@ -682,6 +682,8 @@ namespace Tizen.NUI
             parentMeasureSpecificationWidth = widthMeasureSpec;
             parentMeasureSpecificationHeight = heightMeasureSpec;
 
+            Extents zeroMargin = new Extents();
+
             // Assign child properties
             for (int i = 0; i < LayoutChildren.Count; i++)
             {
@@ -703,7 +705,9 @@ namespace Tizen.NUI
                 float flexBasis = GetFlexBasis(Child);
                 float flexShrink = GetFlexShrink(Child);
                 float flexGrow = GetFlexGrow(Child);
+                Extents childMargin = Child.ExcludeLayouting ? zeroMargin : layoutItem.Margin;
 
+                Interop.FlexLayout.FlexLayout_SetMargin(childHandleRef, Extents.getCPtr(childMargin));
                 Interop.FlexLayout.FlexLayout_SetFlexAlignmentSelf(childHandleRef, (int)flexAlignemnt);
                 Interop.FlexLayout.FlexLayout_SetFlexPositionType(childHandleRef, (int)positionType);
                 Interop.FlexLayout.FlexLayout_SetFlexAspectRatio(childHandleRef, flexAspectRatio);
@@ -713,6 +717,7 @@ namespace Tizen.NUI
             }
 
             Interop.FlexLayout.FlexLayout_CalculateLayout(swigCPtr, width, height, isLayoutRtl);
+            zeroMargin.Dispose();
 
             LayoutLength flexLayoutWidth = new LayoutLength(Interop.FlexLayout.FlexLayout_GetWidth(swigCPtr));
             LayoutLength flexLayoutHeight = new LayoutLength(Interop.FlexLayout.FlexLayout_GetHeight(swigCPtr));