[NUI] Fix Weight calculation in LinearLayout
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Wed, 10 Nov 2021 12:46:19 +0000 (21:46 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 11 Nov 2021 06:23:09 +0000 (15:23 +0900)
View's Weight is considered in LinearLayout's calculation only if the
View's Specification is MatchParent.
Because Weight is used to divide the parent's space to each child.

Previously, WrapContent View's Weight was also added to the sum of
Weights.
This caused the weighted View's size was calculated incorrectly.

Now, only MatchParent View's Weight is added to the sum of Weights.
As a result, the weighted View's size is calculated correctly.

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

index 2283b13..9115e3f 100755 (executable)
@@ -345,10 +345,9 @@ namespace Tizen.NUI
                 float childMarginHeight = childMargin.Top + childMargin.Bottom;
                 bool useRemainingWidth = (childDesiredWidth == 0) && (childWeight > 0);
 
-                totalWeight += childWeight;
-
                 if ((childDesiredWidth == LayoutParamPolicies.MatchParent) || (useRemainingWidth))
                 {
+                    totalWeight += childWeight;
                     childrenMatchParentCount++;
                 }
 
@@ -487,19 +486,19 @@ namespace Tizen.NUI
                 if (needToMeasure == true)
                 {
                     MeasureChildWithMargins(childLayout, widthMeasureSpec, new LayoutLength(0), heightMeasureSpec, new LayoutLength(0));
+                }
 
-                    if (childWeight > 0)
-                    {
-                        float childMeasuredWidth = childLayout.MeasuredWidth.Size.AsDecimal();
+                if ((childWeight > 0) && ((childDesiredWidth == LayoutParamPolicies.MatchParent) || (childDesiredWidth == 0)))
+                {
+                    float childMeasuredWidth = childLayout.MeasuredWidth.Size.AsDecimal();
 
-                        if (childMeasuredWidth < 0)
-                        {
-                            totalWeightLength = Math.Max(totalWeightLength, totalWeightLength + childMargin.Start + childMargin.End);
-                        }
-                        else
-                        {
-                            totalWeightLength = Math.Max(totalWeightLength, totalWeightLength + childMeasuredWidth + childMargin.Start + childMargin.End);
-                        }
+                    if (childMeasuredWidth < 0)
+                    {
+                        totalWeightLength = Math.Max(totalWeightLength, totalWeightLength + childMargin.Start + childMargin.End);
+                    }
+                    else
+                    {
+                        totalWeightLength = Math.Max(totalWeightLength, totalWeightLength + childMeasuredWidth + childMargin.Start + childMargin.End);
                     }
                 }
             } // 2ND PHASE foreach
@@ -598,10 +597,9 @@ namespace Tizen.NUI
                 float childMarginHeight = childMargin.Top + childMargin.Bottom;
                 bool useRemainingHeight = (childDesiredHeight == 0) && (childWeight > 0);
 
-                totalWeight += childWeight;
-
                 if ((childDesiredHeight == LayoutParamPolicies.MatchParent) || (useRemainingHeight))
                 {
+                    totalWeight += childWeight;
                     childrenMatchParentCount++;
                 }
 
@@ -742,7 +740,7 @@ namespace Tizen.NUI
                     MeasureChildWithMargins(childLayout, widthMeasureSpec, new LayoutLength(0), heightMeasureSpec, new LayoutLength(0));
                 }
 
-                if (childWeight > 0)
+                if ((childWeight > 0) && ((childDesiredHeight == LayoutParamPolicies.MatchParent) || (childDesiredHeight == 0)))
                 {
                     float childMeasuredHeight = childLayout.MeasuredHeight.Size.AsDecimal();