grid static method
void
grid(})
Simplistic grid approach that requires you pass the amount of cols
.
Positions the display objects in a grid layout, with the number of rows
and columns specified by rows
and cols
, respectively.
If width
and height
are defined, the items will be positioned within
the specified bounds. Otherwise, the items will be positioned using the
maximum dimensions of the items in the list.
gapX
and gapY
specify the gap between the items, and startX
and
startY
specify the starting position of the first item.
Implementation
static void grid(
List<GDisplayObject> items, {
double gapX = 0,
double gapY = 0,
int rows = 0,
required int cols,
double width = 0,
double height = 0,
double startX = 0,
double startY = 0,
}) {
final numItems = items.length;
/// calculate max item width.
var maxItemW = .0, maxItemH = .0;
/// default to start.
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
maxItemW = Math.max(itm.width, maxItemW);
maxItemH = Math.max(itm.height, maxItemH);
}
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
var idx = i % cols;
var idy = i ~/ cols;
itm.x = startX + idx * (maxItemW + gapX);
itm.y = startY + idy * (maxItemH + gapY);
}
}