public IEnumerable <LayoutItemData> ListLayoutItems() { for (int i = 0; i < cells.Length; i++) { LayoutItemData item = cells[i]; if (item != null) { yield return(item); } } }
public void Occupy(int column, int span, LayoutItemData item) { int maxC = column + span; for (int c = column; c < maxC; c++) { cells[c] = item; } while (nextAvailableCell < columns && cells[nextAvailableCell] != null) { nextAvailableCell++; } }
public void LayoutItem(VisualElement visual) { int colSpan = Math.Min(Columns, GetColumnSpan(visual)); int rowSpan = GetRowSpan(visual); if (availableRow == null) { availableRow = GetRow(rows.Count); } LayoutRow startRow = availableRow; int startColumn = startRow.NextAvailableColumn; int?foundCol = null; int rowUpper = 0; while (foundCol == null) { foundCol = startRow.FindAvailableColumn(startColumn, colSpan); rowUpper = startRow.RowNo + rowSpan; if (foundCol == null) { startRow = GetRow(startRow.RowNo + 1); startColumn = startRow.NextAvailableColumn; continue; } for (int r = startRow.RowNo + 1; r < rowUpper; r++) { LayoutRow nextRow = GetRow(r); if (nextRow.IsFull) { foundCol = null; startRow = GetRow(nextRow.RowNo + 1); startColumn = startRow.NextAvailableColumn; break; } if (GetRow(r).FindAvailableColumn(startColumn, colSpan) == null) { foundCol = null; startColumn++; break; } } } var item = new LayoutItemData(visual, startRow.RowNo, startColumn, colSpan); for (int r = startRow.RowNo; r < rowUpper; r++) { rows[r].Occupy(startColumn, colSpan, item); } while (availableRow != null && availableRow.IsFull) { int nextAvailableRowNo = availableRow.RowNo + 1; availableRow = nextAvailableRowNo < rows.Count ? rows[nextAvailableRowNo] : null; } }