int totalFlex = 0;
int totalWidth = 0;
int maxHeight = 0;
for (int i = 0; i < container.getItemCount(); i++) {
BoxComponent c = (BoxComponent) container.getItem(i);
c.el().setStyleAttribute("margin", "0px");
callLayout(c, false);
HBoxLayoutData layoutData = null;
LayoutData d = getLayoutData(c);
if (d != null && d instanceof HBoxLayoutData) {
layoutData = (HBoxLayoutData) d;
} else {
layoutData = new HBoxLayoutData();
}
Margins cm = layoutData.getMargins();
totalFlex += layoutData.getFlex();
totalWidth += c.getWidth() + cm.left + cm.right;
maxHeight = Math.max(maxHeight, c.getHeight() + cm.top + cm.bottom);
}
int innerCtHeight = maxHeight + t + getPadding().bottom;
if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCH)) {
innerCt.setSize(w, h, true);
} else if (hBoxLayoutAlign.equals(HBoxLayoutAlign.MIDDLE) || hBoxLayoutAlign.equals(HBoxLayoutAlign.BOTTOM)) {
innerCt.setSize(w, h = Math.max(h, innerCtHeight), true);
} else {
innerCt.setSize(w, innerCtHeight, true);
}
int extraWidth = w - totalWidth - l - getPadding().right;
int allocated = 0;
int cw, ch, ct;
int availableHeight = h - t - getPadding().bottom;
if (getPack().equals(BoxLayoutPack.CENTER)) {
l += extraWidth / 2;
} else if (getPack().equals(BoxLayoutPack.END)) {
l += extraWidth;
}
for (int i = 0; i < container.getItemCount(); i++) {
BoxComponent c = (BoxComponent) container.getItem(i);
HBoxLayoutData layoutData = null;
LayoutData d = getLayoutData(c);
if (d != null && d instanceof HBoxLayoutData) {
layoutData = (HBoxLayoutData) d;
} else {
layoutData = new HBoxLayoutData();
}
Margins cm = layoutData.getMargins();
cw = c.getWidth();
ch = c.getHeight();
l += cm.left;
if (hBoxLayoutAlign.equals(HBoxLayoutAlign.MIDDLE)) {
int diff = availableHeight - (ch + cm.top + cm.bottom);
if (diff == 0) {
ct = t + cm.top;
} else {
ct = t + cm.top + (diff / 2);
}
} else {
if (hBoxLayoutAlign.equals(HBoxLayoutAlign.BOTTOM)) {
ct = h - (getPadding().bottom + cm.bottom + ch);
} else {
ct = t + cm.top;
}
}
int width = -1;
c.setPosition(l, ct);
if (getPack().equals(BoxLayoutPack.START) && layoutData.getFlex() > 0) {
int add = (int) Math.floor(extraWidth * (layoutData.getFlex() / totalFlex));
allocated += add;
if (isAdjustForFlexRemainder() && i == container.getItemCount() - 1) {
add += (extraWidth - allocated);
}
cw += add;
width = cw;
}
if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCH)) {
c.setSize(width, Util.constrain(strechHeight - cm.top - cm.bottom, layoutData.getMinHeight(),
layoutData.getMaxHeight()));
} else if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCHMAX)) {
c.setSize(width, Util.constrain(maxHeight - cm.top - cm.bottom, layoutData.getMinHeight(),
layoutData.getMaxHeight()));
} else if (width > 0) {
c.setWidth(width);
}
l += cw + cm.right;
}
}