use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class Tree method draw.
/** Draws selection, icons, and expand icons. */
private void draw(Batch batch, Array<Node> nodes, float indent) {
Drawable plus = style.plus, minus = style.minus;
float x = getX(), y = getY();
for (int i = 0, n = nodes.size; i < n; i++) {
Node node = nodes.get(i);
Actor actor = node.actor;
if (selection.contains(node) && style.selection != null) {
style.selection.draw(batch, x, y + actor.getY() - ySpacing / 2, getWidth(), node.height + ySpacing);
} else if (node == overNode && style.over != null) {
style.over.draw(batch, x, y + actor.getY() - ySpacing / 2, getWidth(), node.height + ySpacing);
}
if (node.icon != null) {
float iconY = actor.getY() + Math.round((node.height - node.icon.getMinHeight()) / 2);
batch.setColor(actor.getColor());
node.icon.draw(batch, x + node.actor.getX() - iconSpacingRight - node.icon.getMinWidth(), y + iconY, node.icon.getMinWidth(), node.icon.getMinHeight());
batch.setColor(Color.WHITE);
}
if (node.children.size == 0)
continue;
Drawable expandIcon = node.expanded ? minus : plus;
float iconY = actor.getY() + Math.round((node.height - expandIcon.getMinHeight()) / 2);
expandIcon.draw(batch, x + indent - iconSpacingLeft, y + iconY, expandIcon.getMinWidth(), expandIcon.getMinHeight());
if (node.expanded)
draw(batch, node.children, indent + indentSpacing);
}
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class VerticalGroup method layout.
public void layout() {
if (sizeInvalid)
computeSize();
if (wrap) {
layoutWrapped();
return;
}
boolean round = this.round;
int align = this.align;
float space = this.space, padLeft = this.padLeft, fill = this.fill;
float columnWidth = (expand ? getWidth() : prefWidth) - padLeft - padRight, y = prefHeight - padTop + space;
if ((align & Align.top) != 0)
y += getHeight() - prefHeight;
else if (// center
(align & Align.bottom) == 0)
y += (getHeight() - prefHeight) / 2;
float startX;
if ((align & Align.left) != 0)
startX = padLeft;
else if ((align & Align.right) != 0)
startX = getWidth() - padRight - columnWidth;
else
startX = padLeft + (getWidth() - padLeft - padRight - columnWidth) / 2;
align = columnAlign;
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 (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 = startX;
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 Stack method layout.
public void layout() {
if (sizeInvalid)
computeSize();
float width = getWidth(), height = getHeight();
Array<Actor> children = getChildren();
for (int i = 0, n = children.size; i < n; i++) {
Actor child = children.get(i);
child.setBounds(0, 0, width, height);
if (child instanceof Layout)
((Layout) child).validate();
}
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class Table method clearChildren.
/** Removes all actors and cells from the table. */
public void clearChildren() {
Array<Cell> cells = this.cells;
for (int i = cells.size - 1; i >= 0; i--) {
Cell cell = cells.get(i);
Actor actor = cell.actor;
if (actor != null)
actor.remove();
}
cellPool.freeAll(cells);
cells.clear();
rows = 0;
columns = 0;
if (rowDefaults != null)
cellPool.free(rowDefaults);
rowDefaults = null;
implicitEndRow = false;
super.clearChildren();
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class Table method computeSize.
private void computeSize() {
sizeInvalid = false;
Array<Cell> cells = this.cells;
int cellCount = cells.size;
// Implicitly End the row for layout purposes.
if (cellCount > 0 && !cells.peek().endRow) {
endRow();
implicitEndRow = true;
}
int columns = this.columns, rows = this.rows;
float[] columnMinWidth = this.columnMinWidth = ensureSize(this.columnMinWidth, columns);
float[] rowMinHeight = this.rowMinHeight = ensureSize(this.rowMinHeight, rows);
float[] columnPrefWidth = this.columnPrefWidth = ensureSize(this.columnPrefWidth, columns);
float[] rowPrefHeight = this.rowPrefHeight = ensureSize(this.rowPrefHeight, rows);
float[] columnWidth = this.columnWidth = ensureSize(this.columnWidth, columns);
float[] rowHeight = this.rowHeight = ensureSize(this.rowHeight, rows);
float[] expandWidth = this.expandWidth = ensureSize(this.expandWidth, columns);
float[] expandHeight = this.expandHeight = ensureSize(this.expandHeight, rows);
float spaceRightLast = 0;
for (int i = 0; i < cellCount; i++) {
Cell c = cells.get(i);
int column = c.column, row = c.row, colspan = c.colspan;
Actor a = c.actor;
// Collect rows that expand and colspan=1 columns that expand.
if (c.expandY != 0 && expandHeight[row] == 0)
expandHeight[row] = c.expandY;
if (colspan == 1 && c.expandX != 0 && expandWidth[column] == 0)
expandWidth[column] = c.expandX;
// Compute combined padding/spacing for cells.
// Spacing between actors isn't additive, the larger is used. Also, no spacing around edges.
c.computedPadLeft = c.padLeft.get(a) + (column == 0 ? 0 : Math.max(0, c.spaceLeft.get(a) - spaceRightLast));
c.computedPadTop = c.padTop.get(a);
if (c.cellAboveIndex != -1) {
Cell above = cells.get(c.cellAboveIndex);
c.computedPadTop += Math.max(0, c.spaceTop.get(a) - above.spaceBottom.get(a));
}
float spaceRight = c.spaceRight.get(a);
c.computedPadRight = c.padRight.get(a) + ((column + colspan) == columns ? 0 : spaceRight);
c.computedPadBottom = c.padBottom.get(a) + (row == rows - 1 ? 0 : c.spaceBottom.get(a));
spaceRightLast = spaceRight;
// Determine minimum and preferred cell sizes.
float prefWidth = c.prefWidth.get(a);
float prefHeight = c.prefHeight.get(a);
float minWidth = c.minWidth.get(a);
float minHeight = c.minHeight.get(a);
float maxWidth = c.maxWidth.get(a);
float maxHeight = c.maxHeight.get(a);
if (prefWidth < minWidth)
prefWidth = minWidth;
if (prefHeight < minHeight)
prefHeight = minHeight;
if (maxWidth > 0 && prefWidth > maxWidth)
prefWidth = maxWidth;
if (maxHeight > 0 && prefHeight > maxHeight)
prefHeight = maxHeight;
if (colspan == 1) {
// Spanned column min and pref width is added later.
float hpadding = c.computedPadLeft + c.computedPadRight;
columnPrefWidth[column] = Math.max(columnPrefWidth[column], prefWidth + hpadding);
columnMinWidth[column] = Math.max(columnMinWidth[column], minWidth + hpadding);
}
float vpadding = c.computedPadTop + c.computedPadBottom;
rowPrefHeight[row] = Math.max(rowPrefHeight[row], prefHeight + vpadding);
rowMinHeight[row] = Math.max(rowMinHeight[row], minHeight + vpadding);
}
float uniformMinWidth = 0, uniformMinHeight = 0;
float uniformPrefWidth = 0, uniformPrefHeight = 0;
for (int i = 0; i < cellCount; i++) {
Cell c = cells.get(i);
int column = c.column;
// Colspan with expand will expand all spanned columns if none of the spanned columns have expand.
int expandX = c.expandX;
outer: if (expandX != 0) {
int nn = column + c.colspan;
for (int ii = column; ii < nn; ii++) if (expandWidth[ii] != 0)
break outer;
for (int ii = column; ii < nn; ii++) expandWidth[ii] = expandX;
}
// Collect uniform sizes.
if (c.uniformX == Boolean.TRUE && c.colspan == 1) {
float hpadding = c.computedPadLeft + c.computedPadRight;
uniformMinWidth = Math.max(uniformMinWidth, columnMinWidth[column] - hpadding);
uniformPrefWidth = Math.max(uniformPrefWidth, columnPrefWidth[column] - hpadding);
}
if (c.uniformY == Boolean.TRUE) {
float vpadding = c.computedPadTop + c.computedPadBottom;
uniformMinHeight = Math.max(uniformMinHeight, rowMinHeight[c.row] - vpadding);
uniformPrefHeight = Math.max(uniformPrefHeight, rowPrefHeight[c.row] - vpadding);
}
}
// Size uniform cells to the same width/height.
if (uniformPrefWidth > 0 || uniformPrefHeight > 0) {
for (int i = 0; i < cellCount; i++) {
Cell c = cells.get(i);
if (uniformPrefWidth > 0 && c.uniformX == Boolean.TRUE && c.colspan == 1) {
float hpadding = c.computedPadLeft + c.computedPadRight;
columnMinWidth[c.column] = uniformMinWidth + hpadding;
columnPrefWidth[c.column] = uniformPrefWidth + hpadding;
}
if (uniformPrefHeight > 0 && c.uniformY == Boolean.TRUE) {
float vpadding = c.computedPadTop + c.computedPadBottom;
rowMinHeight[c.row] = uniformMinHeight + vpadding;
rowPrefHeight[c.row] = uniformPrefHeight + vpadding;
}
}
}
// Distribute any additional min and pref width added by colspanned cells to the columns spanned.
for (int i = 0; i < cellCount; i++) {
Cell c = cells.get(i);
int colspan = c.colspan;
if (colspan == 1)
continue;
int column = c.column;
Actor a = c.actor;
float minWidth = c.minWidth.get(a);
float prefWidth = c.prefWidth.get(a);
float maxWidth = c.maxWidth.get(a);
if (prefWidth < minWidth)
prefWidth = minWidth;
if (maxWidth > 0 && prefWidth > maxWidth)
prefWidth = maxWidth;
float spannedMinWidth = -(c.computedPadLeft + c.computedPadRight), spannedPrefWidth = spannedMinWidth;
float totalExpandWidth = 0;
for (int ii = column, nn = ii + colspan; ii < nn; ii++) {
spannedMinWidth += columnMinWidth[ii];
spannedPrefWidth += columnPrefWidth[ii];
// Distribute extra space using expand, if any columns have expand.
totalExpandWidth += expandWidth[ii];
}
float extraMinWidth = Math.max(0, minWidth - spannedMinWidth);
float extraPrefWidth = Math.max(0, prefWidth - spannedPrefWidth);
for (int ii = column, nn = ii + colspan; ii < nn; ii++) {
float ratio = totalExpandWidth == 0 ? 1f / colspan : expandWidth[ii] / totalExpandWidth;
columnMinWidth[ii] += extraMinWidth * ratio;
columnPrefWidth[ii] += extraPrefWidth * ratio;
}
}
// Determine table min and pref size.
tableMinWidth = 0;
tableMinHeight = 0;
tablePrefWidth = 0;
tablePrefHeight = 0;
for (int i = 0; i < columns; i++) {
tableMinWidth += columnMinWidth[i];
tablePrefWidth += columnPrefWidth[i];
}
for (int i = 0; i < rows; i++) {
tableMinHeight += rowMinHeight[i];
tablePrefHeight += Math.max(rowMinHeight[i], rowPrefHeight[i]);
}
float hpadding = padLeft.get(this) + padRight.get(this);
float vpadding = padTop.get(this) + padBottom.get(this);
tableMinWidth = tableMinWidth + hpadding;
tableMinHeight = tableMinHeight + vpadding;
tablePrefWidth = Math.max(tablePrefWidth + hpadding, tableMinWidth);
tablePrefHeight = Math.max(tablePrefHeight + vpadding, tableMinHeight);
}
Aggregations