Versatile Java game engine with pluggable backends (this was used in Rogue, I think)
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.

80 lines
1.5 KiB

package mightypork.gamecore.gui.components.layout;
import mightypork.gamecore.gui.components.Component;
import mightypork.gamecore.gui.components.LayoutComponent;
import mightypork.utils.math.constraints.rect.RectBound;
import mightypork.utils.math.constraints.rect.builders.TiledRect;
/**
* Holder with table cells
*
* @author Ondřej Hruška (MightyPork)
*/
public class GridLayout extends LayoutComponent {
private final TiledRect tiler;
/**
* @param context context
* @param rows number of rows
* @param cols number of columns
*/
public GridLayout(RectBound context, int rows, int cols)
{
super(context);
this.tiler = tiles(cols, rows);
}
/**
* make a new holder.<br>
* Context must be assigned before rendering.
*
* @param rows number of rows
* @param cols number of columns
*/
public GridLayout(int rows, int cols)
{
this(null, rows, cols);
}
/**
* Add a row to the holder.
*
* @param row row (one-based)
* @param column column (one-based)
* @param elem added component
*/
public void put(Component elem, int row, int column)
{
if (elem == null) return;
elem.setRect(tiler.tile(column, row));
attach(elem);
}
/**
* Put with span
*
* @param elem
* @param row
* @param column
* @param rowspan
* @param colspan
*/
public void put(Component elem, int row, int column, int rowspan, int colspan)
{
if (elem == null) return;
elem.setRect(tiler.span(column, row, colspan, rowspan));
attach(elem);
}
}