/// <summary> /// Updates layout grid by specified action. Either by adding new rows/columns for the new photo or removing them. /// </summary> /// <param name="layoutGrid">LayoutGrid whose layout is updated.</param> /// <param name="action">Action with which to update the layout.</param> private static void UpdateLayout(LayoutGrid layoutGrid, LayoutAction action) { int cellCount = layoutGrid.CellCount; byte rowCount = layoutGrid.LayoutMatrix[0]; byte columnCount = layoutGrid.LayoutMatrix[1]; // Depending on the layout orientation, whether new columns are added first or new rows, different methods are called if (layoutGrid.LayoutOrientation == LayoutOrientation.ColumnFirst) { UpdateLayoutColumnFirst(rowCount, columnCount, cellCount, layoutGrid, action); } else { UpdateLayoutRowFirst(rowCount, columnCount, cellCount, layoutGrid, action); } }
/// <summary> /// Updates layout grid's layout, by rows, based on the action - either with addition of a new row or with the removal of the last one. /// </summary> /// <param name="rowCount">Max rows count of the final layout.</param> /// <param name="columnCount">Max column count of the final layout.</param> /// <param name="cellCount">Number of cells - photos currently in the grid.</param> /// <param name="layoutGrid">Layout grid whose layout is updating.</param> /// <param name="action">Action which is done upon a layout.</param> private static void UpdateLayoutRowFirst(byte rowCount, byte columnCount, int cellCount, LayoutGrid layoutGrid, LayoutAction action) { int col = (cellCount - 1) / rowCount; int row = (cellCount - 1) % rowCount; if (action == LayoutAction.Addition) { AddRowFirst(row, col, layoutGrid); } else { RemoveRowFirst(rowCount, cellCount, col, layoutGrid); } }
/// <summary> /// Updates layout grid's layout, by columns, based on the action - either with addition of a new column or with the removal of the last one. /// </summary> /// <param name="rowCount">Max row count of the final layout.</param> /// <param name="columnCount">Max column count of the final layout.</param> /// <param name="cellCount">Number of cells - photos currently in the grid.</param> /// <param name="layoutGrid">Layout grid whose layout is updating.</param> /// <param name="action">Action which is done upon a layout.</param> private static void UpdateLayoutColumnFirst(byte rowCount, byte columnCount, int cellCount, LayoutGrid layoutGrid, LayoutAction action) { int row = (cellCount - 1) / columnCount; // Find which row needs a column added/removed int col = (cellCount - 1) % columnCount; // Find index of the next column in the above row if (action == LayoutAction.Addition) { AddColumnFirst(row, col, layoutGrid); } else { RemoveColumnFirst(columnCount, cellCount, row, layoutGrid); } }
public void Visit(LayoutAction action) { Actions.Add(action); }