use of de.johni0702.minecraft.gui.utils.lwjgl.Point in project jGui by ReplayMod.
the class GridLayout method layOut.
@Override
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size) {
Preconditions.checkState(columns != 0, "Columns may not be 0.");
int elements = container.getElements().size();
int rows = (elements - 1 + columns) / columns;
if (rows < 1) {
return Collections.emptyMap();
}
int cellWidth = (size.getWidth() + spacingX) / columns - spacingX;
int cellHeight = (size.getHeight() + spacingY) / rows - spacingY;
Pair<int[], int[]> maxCellSize = null;
if (!cellsEqualSize) {
maxCellSize = calcNeededCellSize(container);
}
Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = new LinkedHashMap<>();
Iterator<Map.Entry<GuiElement, LayoutData>> iter = container.getElements().entrySet().iterator();
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
if (!iter.hasNext()) {
return map;
}
int x = j * (cellWidth + spacingX);
int y = i * (cellHeight + spacingY);
if (maxCellSize != null) {
cellWidth = maxCellSize.getLeft()[j];
cellHeight = maxCellSize.getRight()[i];
x = 0;
for (int x1 = 0; x1 < j; x1++) {
x += maxCellSize.getLeft()[x1];
x += spacingX;
}
y = 0;
for (int y1 = 0; y1 < i; y1++) {
y += maxCellSize.getRight()[y1];
y += spacingY;
}
}
Map.Entry<GuiElement, LayoutData> entry = iter.next();
GuiElement element = entry.getKey();
Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
Dimension elementSize = new Dimension(element.getMinSize());
ReadableDimension elementMaxSize = element.getMaxSize();
elementSize.setWidth(Math.min(cellWidth, elementMaxSize.getWidth()));
elementSize.setHeight(Math.min(cellHeight, elementMaxSize.getHeight()));
int remainingWidth = cellWidth - elementSize.getWidth();
int remainingHeight = cellHeight - elementSize.getHeight();
x += (int) (data.alignmentX * remainingWidth);
y += (int) (data.alignmentY * remainingHeight);
map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), elementSize));
}
}
return map;
}
Aggregations