Allowed flexible row expansion as a choice, instead of a compulsion
--HG-- branch : develop_5.3release
parent
da480b1f8b
commit
9cf482d6ed
|
@ -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]
|
||||
protected float cellSpacing = 0f;
|
||||
/// <summary>
|
||||
|
@ -122,29 +136,42 @@ namespace UnityEngine.UI.Extensions
|
|||
totalPreferredHeight += heightFromSpacing;
|
||||
}
|
||||
|
||||
// Find the max value for minimum and preferred heights in each row
|
||||
for (int i = 0; i < rowCount; i++)
|
||||
if (flexibleRowHeight)
|
||||
{
|
||||
float maxMinimumHeightInRow = 0;
|
||||
float maxPreferredHeightInRow = 0;
|
||||
|
||||
for (int j = 0; j < columnWidths.Length; j++)
|
||||
// Find the max value for minimum and preferred heights in each row
|
||||
for (int i = 0; i < rowCount; i++)
|
||||
{
|
||||
int childIndex = (i * columnWidths.Length) + j;
|
||||
float maxMinimumHeightInRow = 0;
|
||||
float maxPreferredHeightInRow = 0;
|
||||
|
||||
if (childIndex >= rectChildren.Count)
|
||||
break;
|
||||
for (int j = 0; j < columnWidths.Length; j++)
|
||||
{
|
||||
int childIndex = (i * columnWidths.Length) + j;
|
||||
|
||||
maxPreferredHeightInRow = Mathf.Max(LayoutUtility.GetPreferredHeight(rectChildren[childIndex]), maxPreferredHeightInRow);
|
||||
maxMinimumHeightInRow = Mathf.Max(LayoutUtility.GetMinHeight(rectChildren[childIndex]), maxMinimumHeightInRow);
|
||||
if (childIndex >= rectChildren.Count)
|
||||
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 += maxMinimumHeightInRow;
|
||||
|
||||
maxPreferredHeightInRow = Mathf.Max(minimumRowHeight, maxPreferredHeightInRow);
|
||||
maxPreferredHeightInRows[i] = maxPreferredHeightInRow;
|
||||
totalPreferredHeight += maxPreferredHeightInRow;
|
||||
totalMinHeight += rowCount * minimumRowHeight;
|
||||
totalPreferredHeight = totalMinHeight;
|
||||
}
|
||||
|
||||
totalPreferredHeight = Mathf.Max(totalMinHeight, totalPreferredHeight);
|
||||
|
|
Loading…
Reference in New Issue