From a08acc7856576d1bf48d8ac62ed332542ef0d237 Mon Sep 17 00:00:00 2001 From: neostom432 <31119276+neostom432@users.noreply.github.com> Date: Thu, 2 Apr 2020 14:38:21 +0900 Subject: [PATCH] [NUI] Fix grid layout measurement (#1513) 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 | 33 +++++++++++++++++------- src/Tizen.NUI/src/public/Layouting/LayoutItem.cs | 4 +-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Tizen.NUI/src/public/Layouting/GridLayout.cs b/src/Tizen.NUI/src/public/Layouting/GridLayout.cs index b160593..6615cd2 100755 --- a/src/Tizen.NUI/src/public/Layouting/GridLayout.cs +++ b/src/Tizen.NUI/src/public/Layouting/GridLayout.cs @@ -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 /// // 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; } /// diff --git a/src/Tizen.NUI/src/public/Layouting/LayoutItem.cs b/src/Tizen.NUI/src/public/Layouting/LayoutItem.cs index 7ad9b42..fa42224 100755 --- a/src/Tizen.NUI/src/public/Layouting/LayoutItem.cs +++ b/src/Tizen.NUI/src/public/Layouting/LayoutItem.cs @@ -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); } } -- 2.7.4