m.count++;
// only compute the preferred size for the fixed elements in this pass
Constraint c = constraint(elem);
if (!c.stretch) {
IDimension psize = preferredSize(elem, hintX, hintY);
float pwidth = psize.width(), pheight = psize.height();
m.prefWidth += pwidth;
m.prefHeight += pheight;
m.maxWidth = Math.max(m.maxWidth, pwidth);
m.maxHeight = Math.max(m.maxHeight, pheight);
m.fixWidth += pwidth;
m.fixHeight += pheight;
} else {
m.stretchers++;
m.totalWeight += c.weight;
}
}
// now compute the preferred size for the stretched elements, providing them with more
// accurate width/height hints
for (Element<?> elem : elems) {
if (!elem.isVisible()) continue;
Constraint c = constraint(elem);
if (!c.stretch) continue;
// the first argument to computeSize is not used for stretched elements
float availX = hintX - m.gaps(_gap), availY = hintY - m.gaps(_gap);
float ehintX = vert ? availX : c.computeSize(0, m.totalWeight, availX - m.fixWidth);
float ehintY = vert ? c.computeSize(0, m.totalWeight, availY - m.fixHeight) : availY;
IDimension psize = preferredSize(elem, ehintX, ehintY);
float pwidth = psize.width(), pheight = psize.height();
m.unitWidth = Math.max(m.unitWidth, pwidth / c.weight);
m.unitHeight = Math.max(m.unitHeight, pheight / c.weight);
m.maxWidth = Math.max(m.maxWidth, pwidth);
m.maxHeight = Math.max(m.maxHeight, pheight);
}