Skip to content

Commit bb1a895

Browse files
authored
[NUI] Add Horizontal Grid (Samsung#1461)
Signed-off-by: huiyu.eun <[email protected]>
1 parent b3fb1a3 commit bb1a895

File tree

2 files changed

+313
-98
lines changed

2 files changed

+313
-98
lines changed

src/Tizen.NUI/src/internal/Layouting/GridLocations.cs

+55-13
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public struct Cell
4343
/// <param name="top">The top y coordinate.</param>
4444
/// <param name="bottom">The bottom y coordinate.</param>
4545

46-
public Cell( int start, int end, int top, int bottom)
46+
public Cell(int start, int end, int top, int bottom)
4747
{
4848
Start = start;
4949
End = end;
@@ -73,48 +73,47 @@ public List<Cell> GetLocations()
7373
/// <summary>
7474
/// [Draft] Uses the given parameters to calculate the x,y coordinates of each cell and cell size.
7575
/// </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)
7877
{
79-
numberOfColumns = Math.Max( numberOfColumns, 1 );
78+
numberOfColumns = Math.Max(numberOfColumns, 1);
8079
_locationsVector.Clear();
8180

8281
// Calculate width and height of columns and rows.
8382

8483
// Calculate numbers of rows, round down result as later check for remainder.
8584
int remainder = 0;
86-
int numberOfRows = Math.DivRem(numberOfCells,numberOfColumns, out remainder);
85+
int numberOfRows = Math.DivRem(numberOfCells, numberOfColumns, out remainder);
8786
// 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;
8988

9089
// Rounding on column widths performed here,
9190
// if visually noticeable then can divide the space explicitly between columns.
9291
int columnWidth = availableWidth / numberOfColumns;
9392

9493
int rowHeight = availableHeight;
9594

96-
if( numberOfRows > 0 )
95+
if (numberOfRows > 0)
9796
{
9897
// Column height supplied so use this unless exceeds available height.
9998
rowHeight = (availableHeight / numberOfRows);
10099
}
101100

102-
int y1 = 0;
103-
int y2 = y1 + rowHeight;
101+
int y1 = 0;
102+
int y2 = y1 + rowHeight;
104103

105104
// Calculate start, end, top and bottom coordinate of each cell.
106105

107106
// Iterate rows
108-
for( var i = 0u; i < numberOfRows; i++ )
107+
for (var i = 0u; i < numberOfRows; i++)
109108
{
110109
int x1 = 0;
111110
int x2 = x1 + columnWidth;
112111

113112
// Iterate columns
114-
for( var j = 0; j < numberOfColumns; j++ )
113+
for (var j = 0; j < numberOfColumns; j++)
115114
{
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);
118117
// Calculate starting x and ending x position of each column
119118
x1 = x2;
120119
x2 = x2 + columnWidth;
@@ -125,5 +124,48 @@ public void CalculateLocations( int numberOfColumns, int availableWidth,
125124
y2 = y2 + rowHeight;
126125
}
127126
}
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+
}
128170
}
129171
}

0 commit comments

Comments
 (0)