use of com.ldtteam.blockout.Pane in project Structurize by ldtteam.
the class ScrollingGroup method parseChildren.
/**
* Redirect all predefined children into our container.
*
* @param params the xml parameters.
*/
@Override
public void parseChildren(final PaneParams params) {
container.parseChildren(params);
for (int i = 1; i < container.children.size(); i++) {
final Pane child = container.children.get(i);
final Pane lastChild = container.children.get(i - 1);
final int childY = lastChild.getY() + lastChild.getHeight();
child.setPosition(0, childY);
child.setSize(getInteriorWidth(), child.getHeight());
}
container.computeContentHeight();
}
use of com.ldtteam.blockout.Pane in project Structurize by ldtteam.
the class TreeView method reconstruct.
public void reconstruct() {
final List<List<TreeViewNode>> layers = new ArrayList<>();
// generate panes
for (final TreeViewNode root : treeRoots) {
construct(layers, 0, root);
}
// find tallest layer, setup layer widths
int max = Integer.MIN_VALUE;
int maxId = -1;
final int[] layerOffsets = new int[layers.size() + 1];
for (int i = 0; i < layers.size(); i++) {
int height = 0;
for (final TreeViewNode node : layers.get(i)) {
final Pane pane = node.pane;
height += pane.getHeight();
height += nodeVerticalDistance;
if (layerOffsets[i + 1] < pane.getWidth()) {
layerOffsets[i + 1] = pane.getWidth();
}
}
height -= nodeVerticalDistance;
if (height >= max) {
max = height;
maxId = i;
}
}
// transform to offsets
for (int i = 1; i < layerOffsets.length; i++) {
layerOffsets[i] += nodeHorizontalDistance;
if (i + 1 < layerOffsets.length) {
layerOffsets[i + 1] += layerOffsets[i];
}
}
final BufferBuilder bufferBuilder = new BufferBuilder(512);
bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
// set up positions and lines of tallest layer
int curY = 0;
for (final TreeViewNode node : layers.get(maxId)) {
final Pane pane = node.pane;
pane.setPosition(layerOffsets[maxId], curY);
curY += pane.getHeight() + nodeVerticalDistance;
}
// set up positions and lines before tallest layer
for (int i = maxId - 1; i >= 0; i--) {
curY = 0;
Pane postponesPane = null;
for (final TreeViewNode node : layers.get(i)) {
final Pane pane = node.pane;
// no anchor
if (node.childs.isEmpty()) {
if (postponesPane != null) {
postponesPane.setPosition(layerOffsets[i], curY);
curY += postponesPane.getHeight() + nodeVerticalDistance;
}
postponesPane = pane;
continue;
}
final int childTop = node.childs.get(0).pane.getY();
final Pane childBotNode = node.childs.get(node.childs.size() - 1).pane;
final int childBot = childBotNode.getY() + childBotNode.getHeight();
int newCurY = (childTop + childBot - pane.getHeight()) / 2;
newCurY = Math.max(curY, newCurY);
if (postponesPane != null) {
int postY = (curY + newCurY - nodeVerticalDistance - postponesPane.getHeight()) / 2;
if (postY < curY) {
postY = curY;
newCurY = curY + postponesPane.getHeight() + nodeVerticalDistance;
}
postponesPane.setPosition(layerOffsets[i], postY);
postponesPane = null;
}
// set pos
pane.setPosition(layerOffsets[i], newCurY);
int x = pane.getX() + pane.getWidth();
hLine(bufferBuilder, x, x + nodeToLineDistance + lineSize / 2, newCurY + pane.getHeight() / 2);
x += nodeToLineDistance + lineSize / 2;
int minY = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE;
for (final TreeViewNode child : node.childs) {
final Pane childPane = child.pane;
final int y = childPane.getY() + childPane.getHeight() / 2;
hLine(bufferBuilder, x, childPane.getX(), y);
minY = Math.min(minY, y);
maxY = Math.max(maxY, y);
}
vLine(bufferBuilder, x, minY - lineSize / 2, maxY + lineSize / 2);
curY = newCurY + pane.getHeight() + nodeVerticalDistance;
}
}
// set up positions and lines after tallest layer
for (int i = maxId; i < layers.size(); i++) {
curY = 0;
for (final TreeViewNode node : layers.get(i)) {
if (node.childs.isEmpty()) {
continue;
}
final Pane pane = node.pane;
int childBranchHeight = 0;
for (final TreeViewNode child : node.childs) {
childBranchHeight += child.pane.getHeight() + nodeVerticalDistance;
}
childBranchHeight -= nodeVerticalDistance;
curY = Math.max(curY, pane.getY() + pane.getHeight() / 2 - childBranchHeight / 2);
int x = pane.getX() + pane.getWidth();
hLine(bufferBuilder, x, x + nodeToLineDistance + lineSize / 2, pane.getY() + pane.getHeight() / 2);
x += nodeToLineDistance + lineSize / 2;
int minY = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE;
for (final TreeViewNode child : node.childs) {
final Pane childPane = child.pane;
childPane.setPosition(layerOffsets[i + 1], curY);
final int y = curY + childPane.getHeight() / 2;
hLine(bufferBuilder, x, childPane.getX(), y);
minY = Math.min(minY, y);
maxY = Math.max(maxY, y);
curY += childPane.getHeight() + nodeVerticalDistance;
}
vLine(bufferBuilder, x, minY - lineSize / 2, maxY + lineSize / 2);
}
}
// update super
computeContentSize();
// complete line buffer
bufferBuilder.end();
lineBuffer = bufferBuilder.popNextBuffer();
}
use of com.ldtteam.blockout.Pane in project Structurize by ldtteam.
the class TreeView method construct.
private void construct(final List<List<TreeViewNode>> layers, final int layer, final TreeViewNode root) {
if (root == null) {
return;
}
List<TreeViewNode> paneLayer = layer < layers.size() ? layers.get(layer) : null;
if (paneLayer == null) {
paneLayer = new ArrayList<>();
layers.add(paneLayer);
}
if (templates.get(root.typeId) == null) {
throw new RuntimeException("Invalid type id for node, type id: " + root.typeId);
}
if (root.pane == null) {
final Pane rootPane = Loader.createFromPaneParams(templates.get(root.typeId), this);
super.treeViewHelperAddChild(rootPane);
root.pane = rootPane;
root.paneUpdater.accept(rootPane);
}
paneLayer.add(root);
for (final TreeViewNode child : root.childs) {
construct(layers, layer + 1, child);
}
}
use of com.ldtteam.blockout.Pane in project Structurize by ldtteam.
the class ScrollingContainer method computeContentHeight.
/**
* Compute the height in pixels of the container.
*/
public void computeContentHeight() {
contentHeight = 0;
for (final Pane child : children) {
if (child != null) {
contentHeight = Math.max(contentHeight, child.getY() + child.getHeight());
}
}
// Recompute scroll
setScrollY(scrollY);
}
use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.
the class WindowBuildDecoration method updateResourceList.
public void updateResourceList() {
final ScrollingList recourseList = findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class);
recourseList.enable();
recourseList.show();
final List<ItemStorage> tempRes = new ArrayList<>(resources.values());
// Creates a dataProvider for the unemployed recourseList.
recourseList.setDataProvider(new ScrollingList.DataProvider() {
/**
* The number of rows of the list.
* @return the number.
*/
@Override
public int getElementCount() {
return tempRes.size();
}
/**
* Inserts the elements into each row.
* @param index the index of the row/list element.
* @param rowPane the parent Pane for the row, containing the elements to update.
*/
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
final ItemStorage resource = tempRes.get(index);
final Text resourceLabel = rowPane.findPaneOfTypeByID(RESOURCE_NAME, Text.class);
final Text quantityLabel = rowPane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Text.class);
resourceLabel.setText(resource.getItemStack().getHoverName().getString());
quantityLabel.setText(Integer.toString(resource.getAmount()));
resourceLabel.setColors(WHITE);
quantityLabel.setColors(WHITE);
final ItemStack itemIcon = new ItemStack(resource.getItem(), 1);
itemIcon.setTag(resource.getItemStack().getTag());
rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(itemIcon);
}
});
}
Aggregations