use of javafx.geometry.HPos in project JFoenix by jfoenixadmin.
the class JFXNodesList method layoutChildren.
@Override
protected void layoutChildren() {
performingLayout = true;
List<Node> children = getChildren();
Insets insets = getInsets();
double width = getWidth();
double rotate = getRotate();
double height = getHeight();
double left = snapSpace(insets.getLeft());
double right = snapSpace(insets.getRight());
double space = snapSpace(getSpacing());
boolean isFillWidth = isFillWidth();
double contentWidth = width - left - right;
Pos alignment = getAlignment();
alignment = alignment == null ? Pos.TOP_CENTER : alignment;
final HPos hpos = alignment.getHpos();
final VPos vpos = alignment.getVpos();
double y = 0;
for (int i = 0, size = children.size(); i < size; i++) {
Node child = children.get(i);
child.autosize();
child.setRotate(rotate % 180 == 0 ? rotate : -rotate);
// init child node if not added using addAnimatedChild method
if (!animationsMap.containsKey(child)) {
if (child instanceof JFXNodesList) {
StackPane container = new StackPane(child);
container.setPickOnBounds(false);
getChildren().set(i, container);
}
initChild(child, i, null, true);
}
double x = 0;
double childWidth = child.getLayoutBounds().getWidth();
double childHeight = child.getLayoutBounds().getHeight();
if (childWidth > width) {
switch(hpos) {
case CENTER:
x = snapPosition(contentWidth - childWidth) / 2;
break;
}
Node alignToChild = getAlignNodeToChild(child);
if (alignToChild != null && child instanceof Parent) {
((Parent) child).layout();
double alignedWidth = alignToChild.getLayoutBounds().getWidth();
double alignedX = alignToChild.getLayoutX();
if (childWidth / 2 > alignedX + alignedWidth) {
alignedWidth = -(childWidth / 2 - (alignedWidth / 2 + alignedX));
} else {
alignedWidth = alignedWidth / 2 + alignedX - childWidth / 2;
}
child.setTranslateX(-alignedWidth * Math.cos(Math.toRadians(rotate)));
child.setTranslateY(alignedWidth * Math.cos(Math.toRadians(90 - rotate)));
}
} else {
childWidth = contentWidth;
}
final Insets margin = getMargin(child);
if (margin != null) {
childWidth += margin.getLeft() + margin.getRight();
childHeight += margin.getTop() + margin.getRight();
}
layoutInArea(child, x, y, childWidth, childHeight, /* baseline shouldn't matter */
0, margin, isFillWidth, true, hpos, vpos);
y += child.getLayoutBounds().getHeight() + space;
if (margin != null) {
y += margin.getTop() + margin.getBottom();
}
y = snapPosition(y);
}
performingLayout = false;
}