use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.
the class AbstractGuiResourceLoadingList method load.
@Override
public void load() {
// Stop current loading
if (loaderThread != null) {
loaderThread.interrupt();
try {
loaderThread.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
// Clear list
resourcesQueue.clear();
for (GuiElement element : new ArrayList<>(resourcesPanel.getChildren())) {
resourcesPanel.removeElement(element);
}
selected.clear();
onSelectionChanged();
// Load new data
loaderThread = new Thread(new Runnable() {
@Override
public void run() {
try {
onLoad.consume(new Consumer<Supplier<U>>() {
@Override
public void consume(final Supplier<U> obj) {
resourcesQueue.offer(new Runnable() {
@Override
public void run() {
resourcesPanel.addElements(null, new Element(obj.get()));
resourcesPanel.sortElements();
}
});
}
});
} finally {
resourcesQueue.offer(new Runnable() {
@Override
public void run() {
getListPanel().removeElement(loadingElement);
}
});
}
}
});
getListPanel().addElements(new VerticalLayout.Data(0.5), loadingElement);
loaderThread.start();
}
use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.
the class VerticalLayout method calcMinSize.
@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
int maxWidth = 0;
int height = 0;
int spacing = 0;
for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
height += spacing;
spacing = this.spacing;
GuiElement element = entry.getKey();
ReadableDimension minSize = element.getMinSize();
int width = minSize.getWidth();
if (width > maxWidth) {
maxWidth = width;
}
height += minSize.getHeight();
}
return new Dimension(maxWidth, height);
}
use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.
the class CustomLayout method layOut.
@Override
@SuppressWarnings("unchecked")
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer container, ReadableDimension size) {
result.clear();
if (parent == null) {
Collection<GuiElement> elements = container.getChildren();
for (GuiElement element : elements) {
result.put(element, Pair.of(new Point(0, 0), new Dimension(element.getMinSize())));
}
} else {
Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> elements = parent.layOut(container, size);
for (Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> entry : elements.entrySet()) {
Pair<ReadablePoint, ReadableDimension> pair = entry.getValue();
result.put(entry.getKey(), Pair.of(new Point(pair.getLeft()), new Dimension(pair.getRight())));
}
}
layout((T) container, size.getWidth(), size.getHeight());
return (Map) result;
}
use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.
the class GridLayout method calcNeededCellSize.
private Pair<int[], int[]> calcNeededCellSize(GuiContainer<?> container) {
int[] columnMaxWidth = new int[columns];
int[] rowMaxHeight = new int[(container.getElements().size() - 1 + columns) / columns];
int elements = 0;
for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
int column = elements % columns;
int row = elements / columns;
GuiElement element = entry.getKey();
ReadableDimension minSize = element.getMinSize();
int width = minSize.getWidth();
if (width > columnMaxWidth[column]) {
columnMaxWidth[column] = width;
}
int height = minSize.getHeight();
if (height > rowMaxHeight[row]) {
rowMaxHeight[row] = height;
}
elements++;
}
return Pair.of(columnMaxWidth, rowMaxHeight);
}
use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.
the class GridLayout method calcMinSize.
@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
Preconditions.checkState(columns != 0, "Columns may not be 0.");
int maxWidth = 0, maxHeight = 0;
int elements = 0;
for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
GuiElement element = entry.getKey();
ReadableDimension minSize = element.getMinSize();
int width = minSize.getWidth();
if (width > maxWidth) {
maxWidth = width;
}
int height = minSize.getHeight();
if (height > maxHeight) {
maxHeight = height;
}
elements++;
}
int rows = (elements - 1 + columns) / columns;
int totalWidth = maxWidth * columns;
int totalHeight = maxHeight * rows;
if (!cellsEqualSize) {
Pair<int[], int[]> maxCellSize = calcNeededCellSize(container);
totalWidth = 0;
for (int w : maxCellSize.getLeft()) {
totalWidth += w;
}
totalHeight = 0;
for (int h : maxCellSize.getRight()) {
totalHeight += h;
}
}
if (elements > 0) {
totalWidth += spacingX * (columns - 1);
}
if (elements > columns) {
totalHeight += spacingY * (rows - 1);
}
return new Dimension(totalWidth, totalHeight);
}
Aggregations