[NUI] Fix grid layout measurement (#1513)
authorneostom432 <31119276+neostom432@users.noreply.github.com>
Thu, 2 Apr 2020 05:38:21 +0000 (14:38 +0900)
committerGitHub <noreply@github.com>
Thu, 2 Apr 2020 05:38:21 +0000 (14:38 +0900)
When using wrap_content to match it's height or width to child count,
the result of measure was not applied again so it wasn't changed.

Update measure result after children are added.

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

index b160593..6615cd2 100755 (executable)
@@ -43,7 +43,7 @@ namespace Tizen.NUI
             Vertical
         }
 
-        private Orientation _linearOrientation = Orientation.Vertical;
+        private Orientation _GridOrientation = Orientation.Vertical;
         const int AUTO_FIT = -1;
         private int _columns = 1;
         private int _rows = 1;
@@ -61,15 +61,15 @@ namespace Tizen.NUI
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public Orientation LinearOrientation
+        public Orientation GridOrientation
         {
             get
             {
-                return _linearOrientation;
+                return _GridOrientation;
             }
             set
             {
-                _linearOrientation = value;
+                _GridOrientation = value;
                 RequestLayout();
             }
         }
@@ -216,12 +216,23 @@ namespace Tizen.NUI
                     }
                 }
 
-                if (_linearOrientation == Orientation.Horizontal)
-                    CalculateHorizontalSize(gridWidthMode, gridHeightMode, widthSize, heightSize);
+                if (_GridOrientation == Orientation.Horizontal)
+                    widthSize = CalculateHorizontalSize(gridWidthMode, gridHeightMode, widthSize, heightSize);
                 else
-                    CalculateVerticalSize(gridWidthMode, gridHeightMode, widthSize, heightSize);
+                    heightSize = CalculateVerticalSize(gridWidthMode, gridHeightMode, widthSize, heightSize);
 
             } // Children exists
+            else
+            {
+                if (_GridOrientation == Orientation.Horizontal)
+                {
+                    widthSize = (gridWidthMode == MeasureSpecification.ModeType.Unspecified)?0:widthSize;
+                }
+                else
+                {
+                    heightSize = (gridHeightMode == MeasureSpecification.ModeType.Unspecified)?0:heightSize;
+                }
+            }
 
             LayoutLength widthLength = new LayoutLength(widthSize + Padding.Start + Padding.End);
             LayoutLength heightLenght = new LayoutLength(heightSize + Padding.Top + Padding.Bottom);
@@ -232,7 +243,7 @@ namespace Tizen.NUI
             SetMeasuredDimensions(widthMeasuredSize, heightMeasuredSize);
         }
 
-        private void CalculateHorizontalSize(MeasureSpecification.ModeType gridWidthMode, MeasureSpecification.ModeType gridHeightMode, int widthSize, int heightSize)
+        private int CalculateHorizontalSize(MeasureSpecification.ModeType gridWidthMode, MeasureSpecification.ModeType gridHeightMode, int widthSize, int heightSize)
         {
             int availableContentWidth;
             int availableContentHeight;
@@ -299,9 +310,11 @@ namespace Tizen.NUI
             DetermineNumberOfRows(availableContentHeight);
 
             _locations.CalculateLocationsRow(_rows, availableContentWidth, availableContentHeight, childCount);
+
+            return availableContentWidth;
         }
 
-        private void CalculateVerticalSize(MeasureSpecification.ModeType gridWidthMode, MeasureSpecification.ModeType gridHeightMode, int widthSize, int heightSize)
+        private int CalculateVerticalSize(MeasureSpecification.ModeType gridWidthMode, MeasureSpecification.ModeType gridHeightMode, int widthSize, int heightSize)
         {
             int availableContentWidth;
             int availableContentHeight;
@@ -382,6 +395,8 @@ namespace Tizen.NUI
 
             // Locations define the start, end,top and bottom of each cell.
             _locations.CalculateLocations(_columns, availableContentWidth, availableContentHeight, childCount);
+
+            return availableContentHeight;
         }
 
         /// <summary>
index 7ad9b42..fa42224 100755 (executable)
@@ -540,10 +540,10 @@ namespace Tizen.NUI
                 }
                 else
                 {
-                    Owner.Size = new Size(right - left, bottom - top, Owner.Position.Z);
+                    Owner.SetSize(right - left, bottom - top, Owner.Position.Z);
                     if(SetPositionByLayout)
                     {
-                        Owner.Position = new Position(left, top, Owner.Position.Z);
+                        Owner.SetPosition(left, top, Owner.Position.Z);
                     }
                 }