Modified Vertical layout functions to use nested loops to minimize condition test failures

--HG--
branch : develop_5.3
pull/413/head
Rahul Raman 2016-12-31 09:12:29 +00:00
parent 909589e544
commit 66cbf0da23
1 changed files with 42 additions and 45 deletions

View File

@ -148,30 +148,28 @@ namespace UnityEngine.UI.Extensions
float maxMinimumHeightInRow = 0;
float maxPreferredHeightInRow = 0;
for (int i = 0; i < rectChildren.Count; i++)
for (int i = 0; i < rowCount; i++)
{
int currentRowIndex = i / columnCount;
int currentColumnIndex = i % columnCount;
maxMinimumHeightInRow = minimumRowHeight;
maxPreferredHeightInRow = minimumRowHeight;
// If it's the first cell in the row, reset heights for the row
if (currentColumnIndex == 0)
for (int j = 0; j < columnCount; j++)
{
maxMinimumHeightInRow = minimumRowHeight;
maxPreferredHeightInRow = minimumRowHeight;
int childIndex = (i * columnCount) + j;
// Safeguard against tables with incomplete rows
if (childIndex == rectChildren.Count)
break;
maxPreferredHeightInRow = Mathf.Max(LayoutUtility.GetPreferredHeight(rectChildren[childIndex]), maxPreferredHeightInRow);
maxMinimumHeightInRow = Mathf.Max(LayoutUtility.GetMinHeight(rectChildren[childIndex]), maxMinimumHeightInRow);
}
maxPreferredHeightInRow = Mathf.Max(LayoutUtility.GetPreferredHeight(rectChildren[i]), maxPreferredHeightInRow);
maxMinimumHeightInRow = Mathf.Max(LayoutUtility.GetMinHeight(rectChildren[i]), maxMinimumHeightInRow);
totalMinHeight += maxMinimumHeightInRow;
totalPreferredHeight += maxPreferredHeightInRow;
// If it's the last cell in the row, or if it's the last cell and the row is incomplete, set calculated heights
if (currentColumnIndex == columnCount - 1 || (i == rectChildren.Count - 1 && currentRowIndex == rowCount - 1))
{
totalMinHeight += maxMinimumHeightInRow;
totalPreferredHeight += maxPreferredHeightInRow;
// Add calculated row height to a commonly accessible array for reuse in SetLayoutVertical()
preferredRowHeights[currentRowIndex] = maxPreferredHeightInRow;
}
// Add calculated row height to a commonly accessible array for reuse in SetLayoutVertical()
preferredRowHeights[i] = maxPreferredHeightInRow;
}
}
else
@ -249,12 +247,10 @@ namespace UnityEngine.UI.Extensions
float requiredSizeWithoutPadding = 0;
for (int i = 0; i < rowCount; i++)
{
requiredSizeWithoutPadding += preferredRowHeights[i];
requiredSizeWithoutPadding += rowSpacing;
}
requiredSizeWithoutPadding -= rowSpacing;
if (rowCount > 1)
requiredSizeWithoutPadding += (rowCount - 1) * rowSpacing;
startOffset = GetStartOffset(1, requiredSizeWithoutPadding);
@ -263,25 +259,26 @@ namespace UnityEngine.UI.Extensions
float positionY = startOffset;
for (int i = 0; i < rectChildren.Count; i++)
for (int i = 0; i < rowCount; i++)
{
int currentRowIndex = i / columnCount;
int currentColumnIndex = i % columnCount;
if (cornerY == 1)
positionY -= preferredRowHeights[i];
// If it's the first cell in the row and start corner is one of the bottom corners, then modify positionY appropriately
if (currentColumnIndex == 0 && cornerY == 1)
positionY -= preferredRowHeights[currentRowIndex];
SetChildAlongAxis(rectChildren[i], 1, positionY, preferredRowHeights[currentRowIndex]);
// If it's the first last cell in the row, then modify positionY appropriately
if (currentColumnIndex == columnCount - 1)
for (int j = 0; j < columnCount; j++)
{
if (cornerY == 1)
positionY -= rowSpacing;
else
positionY += preferredRowHeights[currentRowIndex] + rowSpacing;
int childIndex = (i * columnCount) + j;
// Safeguard against tables with incomplete rows
if (childIndex == rectChildren.Count)
break;
SetChildAlongAxis(rectChildren[childIndex], 1, positionY, preferredRowHeights[i]);
}
if (cornerY == 1)
positionY -= rowSpacing;
else
positionY += preferredRowHeights[i] + rowSpacing;
}
// Set preferredRowHeights to null to free memory