[NUI] Fix WrapContent View's LinearLayout size calculation
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Wed, 10 Nov 2021 12:59:12 +0000 (21:59 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 11 Nov 2021 06:23:09 +0000 (15:23 +0900)
When a View's Specification was WrapContent, the View's LinearLayout did
not consider its child size correctly.
This caused that the View's Size became 0 incorrectly.

To resolve the above, LinearLayout always considers its child size and
the LinearLayout uses its child size when it calculates its own size.

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

index 9115e3f..99a7444 100755 (executable)
@@ -426,6 +426,7 @@ namespace Tizen.NUI
                 int childDesiredHeight = childLayout.Owner.HeightSpecification;
                 float childWeight = childLayout.Owner.Weight;
                 Extents childMargin = childLayout.Margin;
+                float childMarginHeight = childMargin.Top + childMargin.Bottom;
                 bool useRemainingWidth = (childDesiredWidth == 0) && (childWeight > 0);
                 bool needToMeasure = false;
 
@@ -486,6 +487,16 @@ namespace Tizen.NUI
                 if (needToMeasure == true)
                 {
                     MeasureChildWithMargins(childLayout, widthMeasureSpec, new LayoutLength(0), heightMeasureSpec, new LayoutLength(0));
+
+                    float childMeasuredHeight = childLayout.MeasuredHeight.Size.AsDecimal();
+                    if (childMeasuredHeight < 0)
+                    {
+                        maxHeight = Math.Max(maxHeight, childMarginHeight);
+                    }
+                    else
+                    {
+                        maxHeight = Math.Max(maxHeight, childMeasuredHeight + childMarginHeight);
+                    }
                 }
 
                 if ((childWeight > 0) && ((childDesiredWidth == LayoutParamPolicies.MatchParent) || (childDesiredWidth == 0)))
@@ -678,6 +689,7 @@ namespace Tizen.NUI
                 int childDesiredHeight = childLayout.Owner.HeightSpecification;
                 float childWeight = childLayout.Owner.Weight;
                 Extents childMargin = childLayout.Margin;
+                float childMarginWidth = childMargin.Start + childMargin.End;
                 bool useRemainingHeight = (childDesiredHeight == 0) && (childWeight > 0);
                 bool needToMeasure = false;
 
@@ -738,6 +750,16 @@ namespace Tizen.NUI
                 if (needToMeasure == true)
                 {
                     MeasureChildWithMargins(childLayout, widthMeasureSpec, new LayoutLength(0), heightMeasureSpec, new LayoutLength(0));
+
+                    float childMeasuredWidth = childLayout.MeasuredWidth.Size.AsDecimal();
+                    if (childMeasuredWidth < 0)
+                    {
+                        maxWidth = Math.Max(maxWidth, childMarginWidth);
+                    }
+                    else
+                    {
+                        maxWidth = Math.Max(maxWidth, childMeasuredWidth + childMarginWidth);
+                    }
                 }
 
                 if ((childWeight > 0) && ((childDesiredHeight == LayoutParamPolicies.MatchParent) || (childDesiredHeight == 0)))