2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Collections.Generic;
24 /// [Draft] This internal class houses the algorithm for computing the locations and size of cells.
26 internal class GridLocations
29 /// A struct holding the 4 points which make up a cell.
39 /// Initialize a cell with the given points.
41 /// <param name="start">The start x coordinate.</param>
42 /// <param name="end">The end x coordinate.</param>
43 /// <param name="top">The top y coordinate.</param>
44 /// <param name="bottom">The bottom y coordinate.</param>
46 public Cell( int start, int end, int top, int bottom)
55 private List<Cell> _locationsVector;
58 /// [Draft]Constructor
60 public GridLocations()
62 _locationsVector = new List<Cell>();
66 /// Get locations vector with position of each cell and cell size.
68 public List<Cell> GetLocations()
70 return _locationsVector;
74 /// [Draft] Uses the given parameters to calculate the x,y coordinates of each cell and cell size.
76 public void CalculateLocations( int numberOfColumns, int availableWidth,
77 int availableHeight, int numberOfCells)
79 numberOfColumns = Math.Max( numberOfColumns, 1 );
80 _locationsVector.Clear();
82 // Calculate width and height of columns and rows.
84 // Calculate numbers of rows, round down result as later check for remainder.
86 int numberOfRows = Math.DivRem(numberOfCells,numberOfColumns, out remainder);
87 // If number of cells not cleanly dividable by columns, add another row to house remainder cells.
88 numberOfRows += (remainder > 0) ? 1:0;
90 // Rounding on column widths performed here,
91 // if visually noticeable then can divide the space explicitly between columns.
92 int columnWidth = availableWidth / numberOfColumns;
94 int rowHeight = availableHeight;
96 if( numberOfRows > 0 )
98 // Column height supplied so use this unless exceeds available height.
99 rowHeight = (availableHeight / numberOfRows);
103 int y2 = y1 + rowHeight;
105 // Calculate start, end, top and bottom coordinate of each cell.
108 for( var i = 0u; i < numberOfRows; i++ )
111 int x2 = x1 + columnWidth;
114 for( var j = 0; j < numberOfColumns; j++ )
116 Cell cell = new Cell( x1, x2, y1, y2 );
117 _locationsVector.Add( cell );
118 // Calculate starting x and ending x position of each column
120 x2 = x2 + columnWidth;
123 // Calculate top y and bottom y position of each row.