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 maxMinimumHeightInRow = 0;
float maxPreferredHeightInRow = 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;
// If it's the first cell in the row, reset heights for the row
if (currentColumnIndex == 0)
{ {
maxMinimumHeightInRow = minimumRowHeight; maxMinimumHeightInRow = minimumRowHeight;
maxPreferredHeightInRow = minimumRowHeight; maxPreferredHeightInRow = minimumRowHeight;
for (int j = 0; j < columnCount; j++)
{
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);
// 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; totalMinHeight += maxMinimumHeightInRow;
totalPreferredHeight += maxPreferredHeightInRow; totalPreferredHeight += maxPreferredHeightInRow;
// Add calculated row height to a commonly accessible array for reuse in SetLayoutVertical() // Add calculated row height to a commonly accessible array for reuse in SetLayoutVertical()
preferredRowHeights[currentRowIndex] = maxPreferredHeightInRow; preferredRowHeights[i] = maxPreferredHeightInRow;
}
} }
} }
else else
@ -249,12 +247,10 @@ namespace UnityEngine.UI.Extensions
float requiredSizeWithoutPadding = 0; float requiredSizeWithoutPadding = 0;
for (int i = 0; i < rowCount; i++) for (int i = 0; i < rowCount; i++)
{
requiredSizeWithoutPadding += preferredRowHeights[i]; requiredSizeWithoutPadding += preferredRowHeights[i];
requiredSizeWithoutPadding += rowSpacing;
}
requiredSizeWithoutPadding -= rowSpacing; if (rowCount > 1)
requiredSizeWithoutPadding += (rowCount - 1) * rowSpacing;
startOffset = GetStartOffset(1, requiredSizeWithoutPadding); startOffset = GetStartOffset(1, requiredSizeWithoutPadding);
@ -263,25 +259,26 @@ namespace UnityEngine.UI.Extensions
float positionY = startOffset; float positionY = startOffset;
for (int i = 0; i < rectChildren.Count; i++) for (int i = 0; i < rowCount; i++)
{ {
int currentRowIndex = i / columnCount; if (cornerY == 1)
int currentColumnIndex = i % columnCount; 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 for (int j = 0; j < columnCount; j++)
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)
{ {
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) if (cornerY == 1)
positionY -= rowSpacing; positionY -= rowSpacing;
else else
positionY += preferredRowHeights[currentRowIndex] + rowSpacing; positionY += preferredRowHeights[i] + rowSpacing;
}
} }
// Set preferredRowHeights to null to free memory // Set preferredRowHeights to null to free memory