1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
@Override protected void layoutChildren() {
final Insets insets = getInsets();
double width = getWidth();
double height = getHeight();
final Orientation bias = getContentBias();
if (bias == null) {
final double minWidth = minWidth(-1);
final double minHeight = minHeight(-1);
width = width < minWidth ? minWidth : width;
height = height < minHeight ? minHeight : height;
} else if (bias == Orientation.HORIZONTAL) {
final double minWidth = minWidth(-1);
width = width < minWidth ? minWidth : width;
final double minHeight = minHeight(width);
height = height < minHeight ? minHeight : height;
} else {
final double minHeight = minHeight(-1);
height = height < minHeight ? minHeight : height;
final double minWidth = minWidth(height);
width = width < minWidth ? minWidth : width;
}
final double insideX = insets.getLeft();
final double insideY = insets.getTop();
final double insideWidth = width - insideX - insets.getRight();
final double insideHeight = height - insideY - insets.getBottom();
final Node c = getCenter();
final Node r = getRight();
final Node b = getBottom();
final Node l = getLeft();
final Node t = getTop();
double topHeight = 0;
if (t != null && t.isManaged()) {
Insets topMargin = getNodeMargin(t);
double adjustedWidth = adjustWidthByMargin(insideWidth, topMargin);
double adjustedHeight = adjustHeightByMargin(insideHeight, topMargin);
topHeight = snapSize(t.prefHeight(adjustedWidth));
topHeight = Math.min(topHeight, adjustedHeight);
Vec2d result = boundedNodeSizeWithBias(t, adjustedWidth,
topHeight, true, true, TEMP_VEC2D);
topHeight = snapSize(result.y);
t.resize(snapSize(result.x), topHeight);
topHeight = snapSpace(topMargin.getBottom()) + topHeight + snapSpace(topMargin.getTop());
Pos alignment = getAlignment(t);
positionInArea(t, insideX, insideY, insideWidth, topHeight, 0/*ignore baseline*/,
topMargin,
alignment != null? alignment.getHpos() : HPos.LEFT,
alignment != null? alignment.getVpos() : VPos.TOP, isSnapToPixel());
}
double bottomHeight = 0;
if (b != null && b.isManaged()) {
Insets bottomMargin = getNodeMargin(b);
double adjustedWidth = adjustWidthByMargin(insideWidth, bottomMargin);
double adjustedHeight = adjustHeightByMargin(insideHeight - topHeight, bottomMargin);
bottomHeight = snapSize(b.prefHeight(adjustedWidth));
bottomHeight = Math.min(bottomHeight, adjustedHeight);
Vec2d result = boundedNodeSizeWithBias(b, adjustedWidth,
bottomHeight, true, true, TEMP_VEC2D);
bottomHeight = snapSize(result.y);
b.resize(snapSize(result.x), bottomHeight);
bottomHeight = snapSpace(bottomMargin.getBottom()) + bottomHeight + snapSpace(bottomMargin.getTop());
Pos alignment = getAlignment(b);
positionInArea(b, insideX, insideY + insideHeight - bottomHeight,
insideWidth, bottomHeight, 0/*ignore baseline*/,
bottomMargin,
alignment != null? alignment.getHpos() : HPos.LEFT,
alignment != null? alignment.getVpos() : VPos.BOTTOM, isSnapToPixel());
}
double leftWidth = 0;
if (l != null && l.isManaged()) {
Insets leftMargin = getNodeMargin(l);
double adjustedWidth = adjustWidthByMargin(insideWidth, leftMargin);
double adjustedHeight = adjustHeightByMargin(insideHeight - topHeight - bottomHeight, leftMargin); // ????
leftWidth = snapSize(l.prefWidth(adjustedHeight));
leftWidth = Math.min(leftWidth, adjustedWidth);
Vec2d result = boundedNodeSizeWithBias(l, leftWidth, adjustedHeight,
true, true, TEMP_VEC2D);
leftWidth = snapSize(result.x);
l.resize(leftWidth, snapSize(result.y));
leftWidth = snapSpace(leftMargin.getLeft()) + leftWidth + snapSpace(leftMargin.getRight());
Pos alignment = getAlignment(l);
positionInArea(l, insideX, insideY + topHeight,
leftWidth, insideHeight - topHeight - bottomHeight, 0/*ignore baseline*/,
leftMargin,
alignment != null? alignment.getHpos() : HPos.LEFT,
alignment != null? alignment.getVpos() : VPos.TOP, isSnapToPixel());
}
double rightWidth = 0;
if (r != null && r.isManaged()) {
Insets rightMargin = getNodeMargin(r);
double adjustedWidth = adjustWidthByMargin(insideWidth - leftWidth, rightMargin);
double adjustedHeight = adjustHeightByMargin(insideHeight - topHeight - bottomHeight, rightMargin);
rightWidth = snapSize(r.prefWidth(adjustedHeight));
rightWidth = Math.min(rightWidth, adjustedWidth);
Vec2d result = boundedNodeSizeWithBias(r, rightWidth, adjustedHeight,
true, true, TEMP_VEC2D);
rightWidth = snapSize(result.x);
r.resize(rightWidth, snapSize(result.y));
rightWidth = snapSpace(rightMargin.getLeft()) + rightWidth + snapSpace(rightMargin.getRight());
Pos alignment = getAlignment(r);
positionInArea(r, insideX + insideWidth - rightWidth, insideY + topHeight,
rightWidth, insideHeight - topHeight - bottomHeight, 0/*ignore baseline*/,
rightMargin,
alignment != null? alignment.getHpos() : HPos.RIGHT,
alignment != null? alignment.getVpos() : VPos.TOP, isSnapToPixel());
}
if (c != null && c.isManaged()) {
Pos alignment = getAlignment(c);
layoutInArea(c, insideX + leftWidth, insideY + topHeight,
insideWidth - leftWidth - rightWidth,
insideHeight - topHeight - bottomHeight, 0/*ignore baseline*/,
getNodeMargin(c),
alignment != null? alignment.getHpos() : HPos.CENTER,
alignment != null? alignment.getVpos() : VPos.CENTER);
}
} |
Partager