col static method
void
col(
- List<
GDisplayObject> items, { - double gap = 0,
- double startX = 0,
- double startY = 0,
- double width = 0,
- double height = 0,
- MainAxisAlignment axisAlign = MainAxisAlignment.start,
- CrossAxisAlignment crossAlign = CrossAxisAlignment.start,
- bool mask = false,
- bool debug = false,
Arranges the items
vertically in a single column, similar to Flutter's
Column, with optional gap
between them. The column will start at the
startX
and startY
position. The width
and height
of the column can
be specified, but at least one of them must be greater than 0. The
axisAlign
parameter controls how the items are aligned along the
vertical axis, while the crossAlign
parameter controls how they are
aligned along the horizontal axis. If mask
is set to true, the parent
container of the items will be clipped to the specified width and
height
. If debug
is set to true, a red rectangle will be drawn around
the column for debugging purposes.
Make sure all items belongs to the same parent.
Implementation
static void col(
List<GDisplayObject> items, {
double gap = 0,
double startX = 0,
double startY = 0,
double width = 0,
double height = 0,
MainAxisAlignment axisAlign = MainAxisAlignment.start,
CrossAxisAlignment crossAlign = CrossAxisAlignment.start,
bool mask = false,
bool debug = false,
}) {
var currentY = .0, maxW = .0, maxH = .0, itemsH = .0;
final numItems = items.length;
if (numItems == 0) {
return;
}
/// default to start.
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
itm.y = startY + currentY;
itm.x = startX;
maxW = Math.max(maxW, itm.width);
var itmH = itm.height;
itemsH += itmH;
currentY += itmH + gap;
}
if (width <= 0) {
width = maxW;
}
final parent = items.first.parent as GSprite?;
final hasSize = width > 0 && height > 0;
if (debug && parent != null && hasSize) {
final g = parent.graphics;
g.beginFill(debugColor).drawRect(startX, startY, width, height).endFill();
}
maxH = currentY - gap;
currentY = 0;
if (mask && parent != null && hasSize) {
parent.maskRect = GRect(startX, startY, width, height);
}
if (crossAlign == CrossAxisAlignment.center) {
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
itm.x = startX + (width - itm.width) / 2;
}
} else if (crossAlign == CrossAxisAlignment.end) {
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
itm.x = startX + width - itm.width;
}
}
if (axisAlign == MainAxisAlignment.center) {
var centerY = (height - maxH) / 2;
startY += centerY;
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
itm.y = startY + currentY;
currentY += itm.width + gap;
}
} else if (axisAlign == MainAxisAlignment.end) {
startY += height - maxH;
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
itm.y = startY + currentY;
currentY += itm.height + gap;
}
} else if (axisAlign == MainAxisAlignment.spaceEvenly) {
/// calculate gap.
gap = (height - itemsH) / (numItems + 1);
startY += gap;
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
itm.y = startY + currentY;
currentY += itm.height + gap;
}
} else if (axisAlign == MainAxisAlignment.spaceBetween) {
gap = (height - itemsH) / (numItems - 1);
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
itm.y = startY + currentY;
currentY += itm.height + gap;
}
} else if (axisAlign == MainAxisAlignment.spaceAround) {
gap = (height - itemsH) / (numItems);
startY += gap / 2;
for (var i = 0; i < numItems; ++i) {
var itm = items[i];
itm.y = startY + currentY;
currentY += itm.height + gap;
}
}
}