use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class Tree method computeSize.
private void computeSize(Array<Node> nodes, float indent) {
float ySpacing = this.ySpacing;
float spacing = iconSpacingLeft + iconSpacingRight;
for (int i = 0, n = nodes.size; i < n; i++) {
Node node = nodes.get(i);
float rowWidth = indent + iconSpacingRight;
Actor actor = node.actor;
if (actor instanceof Layout) {
Layout layout = (Layout) actor;
rowWidth += layout.getPrefWidth();
node.height = layout.getPrefHeight();
layout.pack();
} else {
rowWidth += actor.getWidth();
node.height = actor.getHeight();
}
if (node.icon != null) {
rowWidth += spacing + node.icon.getMinWidth();
node.height = Math.max(node.height, node.icon.getMinHeight());
}
prefWidth = Math.max(prefWidth, rowWidth);
prefHeight -= node.height + ySpacing;
if (node.expanded)
computeSize(node.children, indent + indentSpacing);
}
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class VerticalGroup method computeSize.
private void computeSize() {
sizeInvalid = false;
SnapshotArray<Actor> children = getChildren();
int n = children.size;
prefWidth = 0;
if (wrap) {
prefHeight = 0;
if (columnSizes == null)
columnSizes = new FloatArray();
else
columnSizes.clear();
FloatArray columnSizes = this.columnSizes;
float space = this.space, wrapSpace = this.wrapSpace;
float pad = padTop + padBottom, groupHeight = getHeight() - pad, x = 0, y = 0, columnWidth = 0;
int i = 0, incr = 1;
if (reverse) {
i = n - 1;
n = -1;
incr = -1;
}
for (; i != n; i += incr) {
Actor child = children.get(i);
float width, height;
if (child instanceof Layout) {
Layout layout = (Layout) child;
width = layout.getPrefWidth();
height = layout.getPrefHeight();
} else {
width = child.getWidth();
height = child.getHeight();
}
float incrY = height + (y > 0 ? space : 0);
if (y + incrY > groupHeight && y > 0) {
columnSizes.add(y);
columnSizes.add(columnWidth);
prefHeight = Math.max(prefHeight, y + pad);
if (x > 0)
x += wrapSpace;
x += columnWidth;
columnWidth = 0;
y = 0;
incrY = height;
}
y += incrY;
columnWidth = Math.max(columnWidth, width);
}
columnSizes.add(y);
columnSizes.add(columnWidth);
prefHeight = Math.max(prefHeight, y + pad);
if (x > 0)
x += wrapSpace;
prefWidth = Math.max(prefWidth, x + columnWidth);
} else {
prefHeight = padTop + padBottom + space * (n - 1);
for (int i = 0; i < n; i++) {
Actor child = children.get(i);
if (child instanceof Layout) {
Layout layout = (Layout) child;
prefWidth = Math.max(prefWidth, layout.getPrefWidth());
prefHeight += layout.getPrefHeight();
} else {
prefWidth = Math.max(prefWidth, child.getWidth());
prefHeight += child.getHeight();
}
}
}
prefWidth += padLeft + padRight;
if (round) {
prefWidth = Math.round(prefWidth);
prefHeight = Math.round(prefHeight);
}
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class VerticalGroup method layoutWrapped.
private void layoutWrapped() {
float prefWidth = getPrefWidth();
if (prefWidth != lastPrefWidth) {
lastPrefWidth = prefWidth;
invalidateHierarchy();
}
int align = this.align;
boolean round = this.round;
float space = this.space, padLeft = this.padLeft, fill = this.fill, wrapSpace = this.wrapSpace;
float maxHeight = prefHeight - padTop - padBottom;
float columnX = padLeft, groupHeight = getHeight();
float yStart = prefHeight - padTop + space, y = 0, columnWidth = 0;
if ((align & Align.right) != 0)
columnX += getWidth() - prefWidth;
else if (// center
(align & Align.left) == 0)
columnX += (getWidth() - prefWidth) / 2;
if ((align & Align.top) != 0)
yStart += groupHeight - prefHeight;
else if (// center
(align & Align.bottom) == 0)
yStart += (groupHeight - prefHeight) / 2;
groupHeight -= padTop;
align = columnAlign;
FloatArray columnSizes = this.columnSizes;
SnapshotArray<Actor> children = getChildren();
int i = 0, n = children.size, incr = 1;
if (reverse) {
i = n - 1;
n = -1;
incr = -1;
}
for (int r = 0; i != n; i += incr) {
Actor child = children.get(i);
float width, height;
Layout layout = null;
if (child instanceof Layout) {
layout = (Layout) child;
width = layout.getPrefWidth();
height = layout.getPrefHeight();
} else {
width = child.getWidth();
height = child.getHeight();
}
if (y - height - space < padBottom || r == 0) {
y = yStart;
if ((align & Align.bottom) != 0)
y -= maxHeight - columnSizes.get(r);
else if (// center
(align & Align.top) == 0)
y -= (maxHeight - columnSizes.get(r)) / 2;
if (r > 0) {
columnX += wrapSpace;
columnX += columnWidth;
}
columnWidth = columnSizes.get(r + 1);
r += 2;
}
if (fill > 0)
width = columnWidth * fill;
if (layout != null) {
width = Math.max(width, layout.getMinWidth());
float maxWidth = layout.getMaxWidth();
if (maxWidth > 0 && width > maxWidth)
width = maxWidth;
}
float x = columnX;
if ((align & Align.right) != 0)
x += columnWidth - width;
else if (// center
(align & Align.left) == 0)
x += (columnWidth - width) / 2;
y -= height + space;
if (round)
child.setBounds(Math.round(x), Math.round(y), Math.round(width), Math.round(height));
else
child.setBounds(x, y, width, height);
if (layout != null)
layout.validate();
}
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class Window method hit.
public Actor hit(float x, float y, boolean touchable) {
Actor hit = super.hit(x, y, touchable);
if (hit == null && isModal && (!touchable || getTouchable() == Touchable.enabled))
return this;
float height = getHeight();
if (hit == null || hit == this)
return hit;
if (y <= height && y >= height - getPadTop() && x >= 0 && x <= getWidth()) {
// Hit the title bar, don't use the hit child if it is in the Window's table.
Actor current = hit;
while (current.getParent() != this) current = current.getParent();
if (getCell(current) != null)
return this;
}
return hit;
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class SplitPane method layout.
@Override
public void layout() {
if (!vertical)
calculateHorizBoundsAndPositions();
else
calculateVertBoundsAndPositions();
Actor firstWidget = this.firstWidget;
if (firstWidget != null) {
Rectangle firstWidgetBounds = this.firstWidgetBounds;
firstWidget.setBounds(firstWidgetBounds.x, firstWidgetBounds.y, firstWidgetBounds.width, firstWidgetBounds.height);
if (firstWidget instanceof Layout)
((Layout) firstWidget).validate();
}
Actor secondWidget = this.secondWidget;
if (secondWidget != null) {
Rectangle secondWidgetBounds = this.secondWidgetBounds;
secondWidget.setBounds(secondWidgetBounds.x, secondWidgetBounds.y, secondWidgetBounds.width, secondWidgetBounds.height);
if (secondWidget instanceof Layout)
((Layout) secondWidget).validate();
}
}
Aggregations