You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.2 KiB
59 lines
1.2 KiB
package mightypork.gamecore.gui.components.layout;
|
|
|
|
|
|
import mightypork.gamecore.control.AppAccess;
|
|
import mightypork.gamecore.gui.components.LayoutComponent;
|
|
import mightypork.gamecore.gui.components.Component;
|
|
import mightypork.utils.math.constraints.rect.builders.TiledRect;
|
|
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
|
|
|
|
|
/**
|
|
* Holder with evenly spaced columns
|
|
*
|
|
* @author MightyPork
|
|
*/
|
|
public class ColumnHolder extends LayoutComponent {
|
|
|
|
private final TiledRect tiler;
|
|
private int col = 0;
|
|
|
|
|
|
/**
|
|
* @param app app access
|
|
* @param context context
|
|
* @param cols number of columns
|
|
*/
|
|
public ColumnHolder(AppAccess app, RectBound context, int cols) {
|
|
super(app, context);
|
|
this.tiler = columns(cols).zeroBased();
|
|
}
|
|
|
|
|
|
/**
|
|
* make a new holder.<br>
|
|
* Context must be assigned before rendering.
|
|
*
|
|
* @param app app access
|
|
* @param cols number of columns
|
|
*/
|
|
public ColumnHolder(AppAccess app, int cols) {
|
|
this(app, null, cols);
|
|
}
|
|
|
|
|
|
/**
|
|
* Add a row to the holder.
|
|
*
|
|
* @param elem
|
|
*/
|
|
public void add(final Component elem)
|
|
{
|
|
if (elem == null) return;
|
|
|
|
elem.setRect(tiler.column(col++));
|
|
|
|
attach(elem);
|
|
}
|
|
|
|
}
|
|
|