package speiger.src.coreengine.rendering.gui.components.layouts; import java.util.List; import java.util.function.Consumer; import speiger.src.coreengine.math.vector.floats.Vec2f; import speiger.src.coreengine.rendering.gui.GuiComponent; import speiger.src.coreengine.rendering.gui.helper.box.IGuiBox; public class FlowLayout implements Consumer { IGuiBox box; List components; Vec2f padding; public FlowLayout(IGuiBox box, Vec2f padding, List components) { this.padding = padding; this.box = box; this.components = components; } @Override public void accept(GuiComponent t) { float minX = box.getRelativeX(); float minY = box.getRelativeY(); float maxWidth = box.getWidth(); int xInserted = 0; int yInserted = 0; float widthUsed = 0F; float heightOffset = 0F; float maxHeight = 0F; for(int i = 0,m=components.size();i= maxWidth && xInserted > 0) { xInserted = 0; maxHeight += heightOffset; heightOffset = 0F; widthUsed = 0F; yInserted++; } component.set(minX + widthUsed + padding.getX(), minY + maxHeight + (padding.getY() * yInserted)); heightOffset = Math.max(heightOffset, bounds[3] - bounds[1]); widthUsed += width + padding.getX(); xInserted++; } } }