use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.
the class MultiRowLayout method calculateColumnSize.
private ColumnInfo calculateColumnSize(List<UIWidget> column, Canvas canvas, Vector2i areaHint) {
int availableHeight = areaHint.y - verticalSpacing * (rows - 1);
ColumnInfo columnInfo = new ColumnInfo();
for (int i = 0; i < rows && i < column.size(); ++i) {
UIWidget widget = column.get(i);
Vector2i cellSize = new Vector2i(areaHint.x, availableHeight);
if (!autoSizeRows) {
cellSize.y *= rowHeights[i];
}
if (widget != null) {
Vector2i contentSize = canvas.calculateRestrictedSize(widget, cellSize);
columnInfo.widgetSizes.add(contentSize);
columnInfo.width = Math.max(columnInfo.width, contentSize.x);
} else {
columnInfo.widgetSizes.add(new Vector2i(0, 0));
}
}
return columnInfo;
}
use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.
the class RowLayout method calcWidths.
/**
* Calculates the widths of each of the widgets in this layout's widget list.
* Widths are first calculated for widgets with a relative width specified,
* followed by widgets which follow their content width.
* The remaining width is then split equally among the remaining widgets.
*
* @param canvas The {@link Canvas} on which this {@code RowLayout} is drawn
* @return A list of the widths of the widgets in this layout's widget list, in pixels
*/
private TIntList calcWidths(Canvas canvas) {
TIntList results = new TIntArrayList(contents.size());
if (contents.size() > 0) {
int width = canvas.size().x - horizontalSpacing * (contents.size() - 1);
int totalWidthUsed = 0;
int unprocessedWidgets = 0;
for (UIWidget widget : contents) {
RowLayoutHint hint = hints.get(widget);
if (hint != null) {
if (!hint.isUseContentWidth() && hint.getRelativeWidth() != 0) {
int elementWidth = TeraMath.floorToInt(hint.getRelativeWidth() * width);
results.add(elementWidth);
totalWidthUsed += elementWidth;
} else {
results.add(0);
unprocessedWidgets++;
}
} else {
results.add(0);
unprocessedWidgets++;
}
}
if (unprocessedWidgets > 0) {
int remainingWidthPerElement = (width - totalWidthUsed) / unprocessedWidgets;
for (int i = 0; i < results.size(); ++i) {
if (results.get(i) == 0) {
RowLayoutHint hint = hints.get(contents.get(i));
if (hint != null) {
if (hint.isUseContentWidth()) {
Vector2i contentSize = contents.get(i).getPreferredContentSize(canvas, new Vector2i(remainingWidthPerElement, canvas.size().y));
results.set(i, contentSize.x);
totalWidthUsed += contentSize.x;
unprocessedWidgets--;
}
}
}
}
}
if (unprocessedWidgets > 0) {
int remainingWidthPerElement = (width - totalWidthUsed) / unprocessedWidgets;
for (int i = 0; i < results.size(); ++i) {
if (results.get(i) == 0) {
results.set(i, remainingWidthPerElement);
}
}
}
}
return results;
}
use of org.terasology.rendering.nui.UIWidget in project Terasology by MovingBlocks.
the class BehaviorEditor method onDraw.
@Override
public void onDraw(final Canvas canvas) {
super.onDraw(canvas);
canvas.addInteractionRegion(mouseInteractionListener);
try (SubRegion subRegion = canvas.subRegion(canvas.getRegion(), false)) {
canvas.setDrawOnTop(true);
for (UIWidget widget : getWidgets()) {
if (!widget.isVisible()) {
continue;
}
if (widget instanceof RenderableNode) {
RenderableNode renderableNode = (RenderableNode) widget;
for (Port port : renderableNode.getPorts()) {
Port targetPort = port.getTargetPort();
if (port.isInput() || targetPort == null || !targetPort.node.isVisible()) {
continue;
}
drawConnection(canvas, port, targetPort, port == activeConnectionStart ? Color.BLACK : Color.GREY);
}
}
}
if (activeConnectionStart != null) {
drawConnection(canvas, activeConnectionStart, mouseWorldPosition, Color.WHITE);
}
if (selectedNode != null) {
Vector2f size = selectedNode.getSize();
Vector2f topLeft = selectedNode.getPosition();
Vector2f topRight = new Vector2f(topLeft);
topRight.add(new Vector2f(size.x + .1f, 0));
Vector2f bottomLeft = new Vector2f(topLeft);
bottomLeft.add(new Vector2f(0, size.y + .1f));
Vector2f bottomRight = new Vector2f(topLeft);
bottomRight.add(new Vector2f(size.x + 0.1f, size.y + 0.1f));
drawConnection(canvas, topLeft, topRight, Color.GREEN);
drawConnection(canvas, topRight, bottomRight, Color.GREEN);
drawConnection(canvas, bottomRight, bottomLeft, Color.GREEN);
drawConnection(canvas, bottomLeft, topLeft, Color.GREEN);
}
if (newNode != null) {
newNode.visit(node -> drawWidget(canvas, node));
}
canvas.setDrawOnTop(false);
}
}
Aggregations