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,6 +136,8 @@ namespace UnityEngine.UI.Extensions
totalPreferredHeight += heightFromSpacing; totalPreferredHeight += heightFromSpacing;
} }
if (flexibleRowHeight)
{
// Find the max value for minimum and preferred heights in each row // Find the max value for minimum and preferred heights in each row
for (int i = 0; i < rowCount; i++) for (int i = 0; i < rowCount; i++)
{ {
@ -146,6 +162,17 @@ namespace UnityEngine.UI.Extensions
maxPreferredHeightInRows[i] = maxPreferredHeightInRow; maxPreferredHeightInRows[i] = maxPreferredHeightInRow;
totalPreferredHeight += maxPreferredHeightInRow; totalPreferredHeight += maxPreferredHeightInRow;
} }
}
else
{
for (int i = 0; i < rowCount; i++)
{
maxPreferredHeightInRows[i] = minimumRowHeight;
}
totalMinHeight += rowCount * minimumRowHeight;
totalPreferredHeight = totalMinHeight;
}
totalPreferredHeight = Mathf.Max(totalMinHeight, totalPreferredHeight); totalPreferredHeight = Mathf.Max(totalMinHeight, totalPreferredHeight);
SetLayoutInputForAxis(totalMinHeight, totalPreferredHeight, 1, 1); SetLayoutInputForAxis(totalMinHeight, totalPreferredHeight, 1, 1);