9 [AddComponentMenu(
"Layout/Extensions/Table Layout Group")]
105 private float[] preferredRowHeights;
109 base.CalculateLayoutInputHorizontal();
111 float horizontalSize = padding.horizontal;
114 int actualCellCount = Mathf.Min(rectChildren.Count,
columnWidths.Length);
116 for (
int i = 0; i < actualCellCount; i++)
124 SetLayoutInputForAxis(horizontalSize, horizontalSize, 0, 0);
130 int rowCount = Mathf.CeilToInt(rectChildren.Count / (
float)columnCount);
132 preferredRowHeights =
new float[rowCount];
134 float totalMinHeight = padding.vertical;
135 float totalPreferredHeight = padding.vertical;
139 float heightFromSpacing = ((rowCount - 1) *
rowSpacing);
140 totalMinHeight += heightFromSpacing;
141 totalPreferredHeight += heightFromSpacing;
148 float maxMinimumHeightInRow = 0;
149 float maxPreferredHeightInRow = 0;
151 for (
int i = 0; i < rowCount; i++)
156 for (
int j = 0; j < columnCount; j++)
158 int childIndex = (i * columnCount) + j;
161 if (childIndex == rectChildren.Count)
164 maxPreferredHeightInRow = Mathf.Max(LayoutUtility.GetPreferredHeight(rectChildren[childIndex]), maxPreferredHeightInRow);
165 maxMinimumHeightInRow = Mathf.Max(LayoutUtility.GetMinHeight(rectChildren[childIndex]), maxMinimumHeightInRow);
168 totalMinHeight += maxMinimumHeightInRow;
169 totalPreferredHeight += maxPreferredHeightInRow;
172 preferredRowHeights[i] = maxPreferredHeightInRow;
178 for (
int i = 0; i < rowCount; i++)
182 totalPreferredHeight = totalMinHeight;
185 totalPreferredHeight = Mathf.Max(totalMinHeight, totalPreferredHeight);
186 SetLayoutInputForAxis(totalMinHeight, totalPreferredHeight, 1, 1);
198 float startOffset = 0;
199 float requiredSizeWithoutPadding = 0;
202 int actualCellCount = Mathf.Min(rectChildren.Count,
columnWidths.Length);
204 for (
int i = 0; i < actualCellCount; i++)
212 startOffset = GetStartOffset(0, requiredSizeWithoutPadding);
215 startOffset += requiredSizeWithoutPadding;
217 float positionX = startOffset;
219 for (
int i = 0; i < rectChildren.Count; i++)
221 int currentColumnIndex = i % columnCount;
224 if (currentColumnIndex == 0)
225 positionX = startOffset;
230 SetChildAlongAxis(rectChildren[i], 0, positionX,
columnWidths[currentColumnIndex]);
242 int rowCount = preferredRowHeights.Length;
246 float startOffset = 0;
247 float requiredSizeWithoutPadding = 0;
249 for (
int i = 0; i < rowCount; i++)
250 requiredSizeWithoutPadding += preferredRowHeights[i];
253 requiredSizeWithoutPadding += (rowCount - 1) *
rowSpacing;
255 startOffset = GetStartOffset(1, requiredSizeWithoutPadding);
258 startOffset += requiredSizeWithoutPadding;
260 float positionY = startOffset;
262 for (
int i = 0; i < rowCount; i++)
265 positionY -= preferredRowHeights[i];
267 for (
int j = 0; j < columnCount; j++)
269 int childIndex = (i * columnCount) + j;
272 if (childIndex == rectChildren.Count)
275 SetChildAlongAxis(rectChildren[childIndex], 1, positionY, preferredRowHeights[i]);
281 positionY += preferredRowHeights[i] +
rowSpacing;
285 preferredRowHeights =
null;
Arranges child objects into a non-uniform grid, with fixed column widths and flexible row heights
override void SetLayoutVertical()
Corner StartCorner
The corner starting from which the cells should be arranged
override void CalculateLayoutInputHorizontal()
float ColumnSpacing
The horizontal spacing between each cell in the table
override void SetLayoutHorizontal()
override void CalculateLayoutInputVertical()
float[] ColumnWidths
The widths of all the columns in the table
float MinimumRowHeight
The minimum height for any row in the table
bool FlexibleRowHeight
Expand rows to fit the cell with the highest preferred height?
float RowSpacing
The vertical spacing between each row in the table
Credit Erdener Gonenc - @PixelEnvision.