public Cell(int viewIndex, int row, int column, int rowSpan, int columnSpan, GridLengthType columnGridLengthType, GridLengthType rowGridLengthType) { ViewIndex = viewIndex; Row = row; Column = column; RowSpan = rowSpan; ColumnSpan = columnSpan; ColumnGridLengthType = columnGridLengthType; RowGridLengthType = rowGridLengthType; }
public Cell(int viewIndex, int row, int column, int rowSpan, int columnSpan, GridLengthType columnGridLengthType, GridLengthType rowGridLengthType, bool measureStarAsAuto) { ViewIndex = viewIndex; Row = row; Column = column; RowSpan = rowSpan; ColumnSpan = columnSpan; ColumnGridLengthType = columnGridLengthType; RowGridLengthType = rowGridLengthType; MeasureStarAsAuto = measureStarAsAuto; }
private void InitializeCells() { // If the width/height constraints are infinity, then Star rows/columns won't really make any sense. // When that happens, we need to tag the cells so they can be measured as Auto cells instead. bool isGridWidthConstraintInfinite = double.IsInfinity(_gridWidthConstraint); bool isGridHeightConstraintInfinite = double.IsInfinity(_gridHeightConstraint); for (int n = 0; n < _childrenToLayOut.Length; n++) { IUIElement?child = _childrenToLayOut[n]; if (!child.Visible) { continue; } int column = child.GridColumn().Clamp(0, _columns.Length - 1); int columnSpan = _grid.GridColumnSpan().Clamp(1, _columns.Length - column); GridLengthType columnGridLengthType = GridLengthType.None; for (int columnIndex = column; columnIndex < column + columnSpan; columnIndex++) { columnGridLengthType |= ToGridLengthType(_columns[columnIndex].ColumnDefinition.Width.GridUnitType); } var row = child.GridRow().Clamp(0, _rows.Length - 1); var rowSpan = child.GridRowSpan().Clamp(1, _rows.Length - row); var rowGridLengthType = GridLengthType.None; for (int rowIndex = row; rowIndex < row + rowSpan; rowIndex++) { rowGridLengthType |= ToGridLengthType(_rows[rowIndex].RowDefinition.Height.GridUnitType); } // Check for infinite constraints and Stars, so we can mark them for measurement as if they were Auto var measureStarAsAuto = (isGridHeightConstraintInfinite && IsStar(rowGridLengthType)) || (isGridWidthConstraintInfinite && IsStar(columnGridLengthType)); _cells[n] = new Cell(n, row, column, rowSpan, columnSpan, columnGridLengthType, rowGridLengthType, measureStarAsAuto); } }
bool HasFlag(GridLengthType a, GridLengthType b) { // Avoiding Enum.HasFlag here for performance reasons; we don't need the type check return((a & b) == b); }
public GridLength(double length, GridLengthType type = GridLengthType.Pixel) { Length = length; Type = type; }