use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.
the class FlowLayout method getPreferredContentSize.
@Override
public Vector2i getPreferredContentSize(Canvas canvas, Vector2i sizeHint) {
Vector2i result = new Vector2i();
int filledWidth = 0;
int filledHeight = 0;
for (UIWidget widget : contents) {
Vector2i size = canvas.calculatePreferredSize(widget);
if (filledWidth != 0 && filledWidth + size.x > sizeHint.x) {
result.x = Math.max(result.x, filledWidth);
result.y += filledHeight;
filledWidth = size.x;
filledHeight = size.y;
} else {
filledWidth += size.x;
filledHeight = Math.max(filledHeight, size.y);
}
}
result.x = Math.max(result.x, filledWidth);
result.y += filledHeight;
return result;
}
use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.
the class FlowLayout method onDraw.
@Override
public void onDraw(Canvas canvas) {
int filledWidth = 0;
int filledHeight = 0;
int heightOffset = 0;
for (UIWidget widget : contents) {
Vector2i size = canvas.calculatePreferredSize(widget);
if (filledWidth != 0 && filledWidth + size.x > canvas.size().x) {
heightOffset += filledHeight;
filledWidth = 0;
filledHeight = 0;
}
canvas.drawWidget(widget, Rect2i.createFromMinAndSize(filledWidth, heightOffset, size.x, size.y));
filledWidth += size.x;
filledHeight = Math.max(filledHeight, size.y);
}
}
use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.
the class MultiRowLayout method getMaxContentSize.
@Override
public Vector2i getMaxContentSize(Canvas canvas) {
Iterator<List<UIWidget>> columns = getColumnIterator();
Vector2i size = new Vector2i();
int[] rowSizes = new int[rows];
while (columns.hasNext()) {
List<UIWidget> column = columns.next();
int columnWidth = 0;
for (int i = 0; i < column.size(); ++i) {
Vector2i maxSize = canvas.calculateMaximumSize(column.get(i));
rowSizes[i] = Math.max(rowSizes[i], maxSize.y);
columnWidth = Math.max(columnWidth, maxSize.x);
}
size.x = TeraMath.addClampAtMax(size.x, columnWidth);
if (columns.hasNext()) {
size.x = TeraMath.addClampAtMax(size.x, horizontalSpacing);
}
}
long height = 0;
for (int rowSize : rowSizes) {
height += rowSize;
}
if (!autoSizeRows) {
for (int i = 0; i < rows; ++i) {
height = Math.min(height, TeraMath.floorToInt(rowSizes[i] / rowHeights[i]));
}
}
height += verticalSpacing * (rows - 1);
size.y = (int) Math.min(Integer.MAX_VALUE, height);
return size;
}
use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.
the class MultiRowLayout method getPreferredContentSize.
@Override
public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) {
Vector2i availableSize = new Vector2i(areaHint);
int numColumns = TeraMath.ceilToInt((float) widgetList.size() / rows);
if (numColumns > 0) {
availableSize.x -= horizontalSpacing * (numColumns - 1);
}
if (rows > 0) {
availableSize.y -= verticalSpacing * (rows - 1);
}
Iterator<List<UIWidget>> columns = getColumnIterator();
Vector2i size = new Vector2i();
int[] rowSizes = new int[rows];
while (columns.hasNext()) {
List<UIWidget> column = columns.next();
ColumnInfo columnInfo = calculateColumnSize(column, canvas, availableSize);
size.x += columnInfo.width;
if (columns.hasNext()) {
size.x += horizontalSpacing;
}
for (int i = 0; i < columnInfo.widgetSizes.size(); ++i) {
rowSizes[i] = Math.max(rowSizes[i], columnInfo.widgetSizes.get(i).getY());
}
}
for (int rowSize : rowSizes) {
size.y += rowSize;
}
if (!autoSizeRows) {
for (int i = 0; i < rows; ++i) {
size.y = Math.max(size.y, TeraMath.floorToInt(rowSizes[i] / rowHeights[i]));
}
}
size.y += verticalSpacing * (rows - 1);
return size;
}
use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.
the class PropertyLayout method expand.
private void expand(Collection<Property<?, ?>> properties, MigLayout layout) {
List<Property<?, ?>> props = Lists.newArrayList(properties);
Collections.sort(props, propertyComparator);
for (Property<?, ?> property : props) {
UILabel label = property.getLabel();
UIWidget editor = property.getEditor();
editor.setTooltip(property.getDescription());
layout.addWidget(label, new CCHint("newline"));
layout.addWidget(editor, new CCHint());
}
invalidate();
}
Aggregations