layoutData = (BoxLayoutData) d;
} else {
layoutData = new BoxLayoutData();
}
Margins cm = layoutData.getMargins();
if (cm == null) {
cm = new Margins(0);
}
// TODO strange issue where getOffsetWidth call in 2nd loop is returning smaller number than acutal offset
// when packing CENTER or END so we cache the offsetWidth for use in 2nd loop
int ww = widget.getOffsetWidth();
loopWidthMap.put(widget, ww);
totalFlex += layoutData.getFlex();
totalWidth += (ww + cm.getLeft() + cm.getRight());
maxHeight = Math.max(maxHeight, widget.getOffsetHeight() + cm.getTop() + cm.getBottom());
}
int innerCtHeight = maxHeight + pt + pb;
if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCH)) {
getContainerTarget().setSize(w, h, true);
} else if (hBoxLayoutAlign.equals(HBoxLayoutAlign.MIDDLE) || hBoxLayoutAlign.equals(HBoxLayoutAlign.BOTTOM)) {
getContainerTarget().setSize(w, h = Math.max(h, innerCtHeight), true);
} else {
getContainerTarget().setSize(w, innerCtHeight, true);
}
int extraWidth = w - totalWidth - pl - pr;
int allocated = 0;
int cw, ch, ct;
int availableHeight = h - pt - pb;
if (getPack().equals(BoxLayoutPack.CENTER)) {
pl += extraWidth / 2;
} else if (getPack().equals(BoxLayoutPack.END)) {
pl += extraWidth;
}
for (int i = 0, len = getWidgetCount(); i < len; i++) {
Widget widget = getWidget(i);
if (!widget.isVisible()) {
continue;
}
BoxLayoutData layoutData = null;
Object d = widget.getLayoutData();
if (d instanceof BoxLayoutData) {
layoutData = (BoxLayoutData) d;
} else {
layoutData = new BoxLayoutData();
}
Margins cm = layoutData.getMargins();
if (cm == null) {
cm = new Margins(0);
}
cw = loopWidthMap.remove(widget);
ch = widget.getOffsetHeight();
pl += cm.getLeft();
pl = Math.max(0, pl);
if (hBoxLayoutAlign.equals(HBoxLayoutAlign.MIDDLE)) {
int diff = availableHeight - (ch + cm.getTop() + cm.getBottom());
if (diff == 0) {
ct = pt + cm.getTop();
} else {
ct = pt + cm.getTop() + (diff / 2);
}
} else {
if (hBoxLayoutAlign.equals(HBoxLayoutAlign.BOTTOM)) {
ct = h - (pb + cm.getBottom() + ch);
} else {
ct = pt + cm.getTop();
}
}
boolean component = widget instanceof Component;
Component c = null;
if (component) {
c = (Component) widget;
}
int width = -1;
if (component) {
c.setPosition(pl, ct);
} else {
XElement.as(widget.getElement()).setLeftTop(pl, ct);
}
if (getPack().equals(BoxLayoutPack.START) && layoutData.getFlex() > 0) {
int add = (int) Math.floor(extraWidth * (layoutData.getFlex() / totalFlex));
allocated += add;
if (isAdjustForFlexRemainder() && i == getWidgetCount() - 1) {
add += (extraWidth - allocated);
}
cw += add;
width = cw;
}
if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCH)) {
applyLayout(
widget,
width,
Util.constrain(stretchHeight - cm.getTop() - cm.getBottom(), layoutData.getMinSize(),
layoutData.getMaxSize()));
} else if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCHMAX)) {
applyLayout(widget, width,
Util.constrain(maxHeight - cm.getTop() - cm.getBottom(), layoutData.getMinSize(), layoutData.getMaxSize()));
} else if (width > 0) {
applyLayout(widget, width, -1);
}
pl += cw + cm.getRight();
}
// do we need overflow
if (enableOverflow) {
int runningWidth = 0;
for (int i = 0, len = getWidgetCount(); i < len; i++) {
Widget widget = getWidget(i);
if (widget == more) {
continue;
}
BoxLayoutData layoutData = null;
Object d = widget.getLayoutData();
if (d instanceof BoxLayoutData) {
layoutData = (BoxLayoutData) d;
} else {
layoutData = new BoxLayoutData();
}
Margins cm = layoutData.getMargins();
if (cm == null) {
cm = new Margins(0);
}
runningWidth += getWidgetWidth(widget);
runningWidth += cm.getLeft();
runningWidth += cm.getRight();
}
if (runningWidth > w) {
hasOverflow = true;
onOverflow();