wrap static method
void
wrap(})
Wraps a list of display objects either horizontally or vertically,
depending on whether width
or height
is defined.
If width
is defined, the display objects are wrapped horizontally, with
gapX
specifying the gap between objects. If height
is defined, the
display objects are wrapped vertically, with gapY
specifying the gap
between objects.
The starting position of the first object can be set using startX
and
startY
.
Throws an assertion error if neither width
nor height
is defined.
Implementation
static void wrap(
List<GDisplayObject> items, {
double gapX = 0,
double gapY = 0,
double width = 0,
double height = 0,
double startX = 0,
double startY = 0,
}) {
assert(width > 0 || height > 0);
final numItems = items.length;
var cx = .0, cy = .0, lineS = .0;
if (width <= 0) {
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
itm.x = startX + cx;
itm.y = startY + cy;
lineS = Math.max(itm.width, lineS);
cy += itm.height;
if (cy < height) {
cy += gapY;
} else {
cy = 0;
cx += (lineS + gapX);
lineS = 0;
}
}
} else {
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
itm.x = startX + cx;
itm.y = startY + cy;
lineS = Math.max(itm.height, lineS);
cx += itm.width;
if (cx < width) {
cx += gapX;
} else {
cx = 0;
cy += (lineS + gapY);
lineS = 0;
}
}
}
}