@@ -43,7 +43,7 @@ public struct Cell
43
43
/// <param name="top">The top y coordinate.</param>
44
44
/// <param name="bottom">The bottom y coordinate.</param>
45
45
46
- public Cell ( int start , int end , int top , int bottom )
46
+ public Cell ( int start , int end , int top , int bottom )
47
47
{
48
48
Start = start ;
49
49
End = end ;
@@ -73,48 +73,47 @@ public List<Cell> GetLocations()
73
73
/// <summary>
74
74
/// [Draft] Uses the given parameters to calculate the x,y coordinates of each cell and cell size.
75
75
/// </summary>
76
- public void CalculateLocations ( int numberOfColumns , int availableWidth ,
77
- int availableHeight , int numberOfCells )
76
+ public void CalculateLocations ( int numberOfColumns , int availableWidth , int availableHeight , int numberOfCells )
78
77
{
79
- numberOfColumns = Math . Max ( numberOfColumns , 1 ) ;
78
+ numberOfColumns = Math . Max ( numberOfColumns , 1 ) ;
80
79
_locationsVector . Clear ( ) ;
81
80
82
81
// Calculate width and height of columns and rows.
83
82
84
83
// Calculate numbers of rows, round down result as later check for remainder.
85
84
int remainder = 0 ;
86
- int numberOfRows = Math . DivRem ( numberOfCells , numberOfColumns , out remainder ) ;
85
+ int numberOfRows = Math . DivRem ( numberOfCells , numberOfColumns , out remainder ) ;
87
86
// If number of cells not cleanly dividable by columns, add another row to house remainder cells.
88
- numberOfRows += ( remainder > 0 ) ? 1 : 0 ;
87
+ numberOfRows += ( remainder > 0 ) ? 1 : 0 ;
89
88
90
89
// Rounding on column widths performed here,
91
90
// if visually noticeable then can divide the space explicitly between columns.
92
91
int columnWidth = availableWidth / numberOfColumns ;
93
92
94
93
int rowHeight = availableHeight ;
95
94
96
- if ( numberOfRows > 0 )
95
+ if ( numberOfRows > 0 )
97
96
{
98
97
// Column height supplied so use this unless exceeds available height.
99
98
rowHeight = ( availableHeight / numberOfRows ) ;
100
99
}
101
100
102
- int y1 = 0 ;
103
- int y2 = y1 + rowHeight ;
101
+ int y1 = 0 ;
102
+ int y2 = y1 + rowHeight ;
104
103
105
104
// Calculate start, end, top and bottom coordinate of each cell.
106
105
107
106
// Iterate rows
108
- for ( var i = 0u ; i < numberOfRows ; i ++ )
107
+ for ( var i = 0u ; i < numberOfRows ; i ++ )
109
108
{
110
109
int x1 = 0 ;
111
110
int x2 = x1 + columnWidth ;
112
111
113
112
// Iterate columns
114
- for ( var j = 0 ; j < numberOfColumns ; j ++ )
113
+ for ( var j = 0 ; j < numberOfColumns ; j ++ )
115
114
{
116
- Cell cell = new Cell ( x1 , x2 , y1 , y2 ) ;
117
- _locationsVector . Add ( cell ) ;
115
+ Cell cell = new Cell ( x1 , x2 , y1 , y2 ) ;
116
+ _locationsVector . Add ( cell ) ;
118
117
// Calculate starting x and ending x position of each column
119
118
x1 = x2 ;
120
119
x2 = x2 + columnWidth ;
@@ -125,5 +124,48 @@ public void CalculateLocations( int numberOfColumns, int availableWidth,
125
124
y2 = y2 + rowHeight ;
126
125
}
127
126
}
127
+
128
+
129
+ /// <summary>
130
+ /// [Draft] Uses the given parameters to calculate the x,y coordinates of each cell and cell size.
131
+ /// </summary>
132
+ public void CalculateLocationsRow ( int numberOfRows , int availableWidth , int availableHeight , int numberOfCells )
133
+ {
134
+ numberOfRows = Math . Max ( numberOfRows , 1 ) ;
135
+ _locationsVector . Clear ( ) ;
136
+
137
+ int remainder = 0 ;
138
+ int numberOfColumns = Math . DivRem ( numberOfCells , numberOfRows , out remainder ) ;
139
+
140
+ numberOfColumns += ( remainder > 0 ) ? 1 : 0 ;
141
+
142
+ int rowHeight = availableHeight / numberOfRows ;
143
+ int columnWidth = availableHeight ;
144
+
145
+ if ( numberOfColumns > 0 )
146
+ {
147
+ columnWidth = ( availableWidth / numberOfColumns ) ;
148
+ }
149
+
150
+ int x1 = 0 ;
151
+ int x2 = x1 + columnWidth ;
152
+
153
+ for ( var i = 0u ; i < numberOfColumns ; i ++ )
154
+ {
155
+ int y1 = 0 ;
156
+ int y2 = y1 + rowHeight ;
157
+
158
+ for ( var j = 0 ; j < numberOfRows ; j ++ )
159
+ {
160
+ Cell cell = new Cell ( x1 , x2 , y1 , y2 ) ;
161
+ _locationsVector . Add ( cell ) ;
162
+ y1 = y2 ;
163
+ y2 = y2 + rowHeight ;
164
+ }
165
+
166
+ x1 = x2 ;
167
+ x2 = x2 + columnWidth ;
168
+ }
169
+ }
128
170
}
129
171
}
0 commit comments