Allowed flexible row expansion as a choice, instead of a compulsion

--HG--
branch : develop_5.3
release
Rahul Raman 2016-12-27 21:34:16 +00:00
parent da480b1f8b
commit 9cf482d6ed
1 changed files with 52 additions and 25 deletions

View File

@ -58,6 +58,20 @@ namespace UnityEngine.UI.Extensions
} }
} }
[SerializeField]
protected bool flexibleRowHeight = true;
/// <summary>
/// Expand rows to fit the cell with the highest preferred height?
/// </summary>
public bool FlexibleRowHeight
{
get { return flexibleRowHeight; }
set
{
SetProperty(ref flexibleRowHeight, value);
}
}
[SerializeField] [SerializeField]
protected float cellSpacing = 0f; protected float cellSpacing = 0f;
/// <summary> /// <summary>
@ -122,29 +136,42 @@ namespace UnityEngine.UI.Extensions
totalPreferredHeight += heightFromSpacing; totalPreferredHeight += heightFromSpacing;
} }
// Find the max value for minimum and preferred heights in each row if (flexibleRowHeight)
for (int i = 0; i < rowCount; i++)
{ {
float maxMinimumHeightInRow = 0; // Find the max value for minimum and preferred heights in each row
float maxPreferredHeightInRow = 0; for (int i = 0; i < rowCount; i++)
for (int j = 0; j < columnWidths.Length; j++)
{ {
int childIndex = (i * columnWidths.Length) + j; float maxMinimumHeightInRow = 0;
float maxPreferredHeightInRow = 0;
if (childIndex >= rectChildren.Count) for (int j = 0; j < columnWidths.Length; j++)
break; {
int childIndex = (i * columnWidths.Length) + j;
maxPreferredHeightInRow = Mathf.Max(LayoutUtility.GetPreferredHeight(rectChildren[childIndex]), maxPreferredHeightInRow); if (childIndex >= rectChildren.Count)
maxMinimumHeightInRow = Mathf.Max(LayoutUtility.GetMinHeight(rectChildren[childIndex]), maxMinimumHeightInRow); break;
maxPreferredHeightInRow = Mathf.Max(LayoutUtility.GetPreferredHeight(rectChildren[childIndex]), maxPreferredHeightInRow);
maxMinimumHeightInRow = Mathf.Max(LayoutUtility.GetMinHeight(rectChildren[childIndex]), maxMinimumHeightInRow);
}
maxMinimumHeightInRow = Mathf.Max(minimumRowHeight, maxMinimumHeightInRow);
totalMinHeight += maxMinimumHeightInRow;
maxPreferredHeightInRow = Mathf.Max(minimumRowHeight, maxPreferredHeightInRow);
maxPreferredHeightInRows[i] = maxPreferredHeightInRow;
totalPreferredHeight += maxPreferredHeightInRow;
}
}
else
{
for (int i = 0; i < rowCount; i++)
{
maxPreferredHeightInRows[i] = minimumRowHeight;
} }
maxMinimumHeightInRow = Mathf.Max(minimumRowHeight, maxMinimumHeightInRow); totalMinHeight += rowCount * minimumRowHeight;
totalMinHeight += maxMinimumHeightInRow; totalPreferredHeight = totalMinHeight;
maxPreferredHeightInRow = Mathf.Max(minimumRowHeight, maxPreferredHeightInRow);
maxPreferredHeightInRows[i] = maxPreferredHeightInRow;
totalPreferredHeight += maxPreferredHeightInRow;
} }
totalPreferredHeight = Mathf.Max(totalMinHeight, totalPreferredHeight); totalPreferredHeight = Mathf.Max(totalMinHeight, totalPreferredHeight);