[NUI] Fix GridLayout to fill expanded size correctly
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Thu, 14 Oct 2021 12:51:18 +0000 (21:51 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Tue, 19 Oct 2021 08:08:07 +0000 (17:08 +0900)
Previously, child did not fill to the expanded size if the child had
positive Width/HeightSpecification.

e.g. Let child's WidthSpecification = 100
     Let child's HeightSpecification = 100
     Let child's expanded size (row and col's size) be (200, 200)
     Let child's Stretch mode be ExpandAndFill.
     (child should fill to the expanded size)
     Then, child's size became (100, 100) instead of fill to (200, 200)

Changing child's Width/HeightSpecification to assign
MeasuredWidth/Height could cause child's size changed.
Moreover, the changed size was not recalculated to the expanded size.

Now, child's size change is reverted so the child's size is not changed.
But the way of fixing this bug should be modified in a better way later.

e.g. Assigning MeasuredWidth/Height without changing
     Width/HeightSpecification.

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

index fb11baf..a8f0949 100755 (executable)
@@ -449,6 +449,7 @@ namespace Tizen.NUI
                     // because the grand children's Measure() is called with the mode type AtMost.
                     int widthSpecification = child.LayoutItem.Owner.WidthSpecification;
                     int heightSpecification = child.LayoutItem.Owner.HeightSpecification;
+                    Size2D origSize = new Size2D(child.LayoutItem.Owner.Size2D.Width, child.LayoutItem.Owner.Size2D.Height);
 
                     if (needMeasuredWidth)
                     {
@@ -471,6 +472,14 @@ namespace Tizen.NUI
                     {
                         child.LayoutItem.Owner.HeightSpecification = heightSpecification;
                     }
+
+                    // If the both Width/HeightSpecification are set with values bigger than 0,
+                    // then the child's Size2D is changed with the values of Width/HeightSpecification.
+                    // The Size2D changes, caused by setting Width/HeightSpecification, should be reverted.
+                    if (needMeasuredWidth && needMeasuredHeight && (widthSpecification > 0) && (heightSpecification > 0))
+                    {
+                        child.LayoutItem.Owner.SetSize(origSize.Width, origSize.Height);
+                    }
                 }
 
                 child.LayoutItem.Layout(new LayoutLength(l), new LayoutLength(t), new LayoutLength(l + width), new LayoutLength(t + height));