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.
90 lines
2.0 KiB
90 lines
2.0 KiB
10 years ago
|
package mightypork.gamecore.gui.components.layout;
|
||
|
|
||
|
|
||
10 years ago
|
import mightypork.gamecore.app.AppAccess;
|
||
10 years ago
|
import mightypork.gamecore.gui.AlignY;
|
||
|
import mightypork.gamecore.gui.components.Component;
|
||
10 years ago
|
import mightypork.gamecore.gui.components.LayoutComponent;
|
||
10 years ago
|
import mightypork.gamecore.util.math.constraints.num.Num;
|
||
|
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||
|
import mightypork.gamecore.util.math.constraints.rect.proxy.RectBound;
|
||
10 years ago
|
|
||
|
|
||
|
/**
|
||
|
* Holder with same-sized rows, aligned to top or bottom
|
||
|
*
|
||
|
* @author MightyPork
|
||
|
*/
|
||
10 years ago
|
public class FlowRowLayout extends LayoutComponent {
|
||
10 years ago
|
|
||
|
private int row = 0;
|
||
10 years ago
|
private Num elementHeight;
|
||
10 years ago
|
private final AlignY align;
|
||
10 years ago
|
|
||
|
|
||
|
/**
|
||
|
* @param app app access
|
||
|
* @param context context
|
||
|
* @param elementHeight height of all elements
|
||
|
* @param align component align. Legal values are TOP and BOTTOM.
|
||
|
*/
|
||
10 years ago
|
public FlowRowLayout(AppAccess app, RectBound context, Num elementHeight, AlignY align)
|
||
10 years ago
|
{
|
||
10 years ago
|
super(app, context);
|
||
10 years ago
|
this.elementHeight = elementHeight;
|
||
10 years ago
|
this.align = align;
|
||
|
|
||
10 years ago
|
if (align != AlignY.TOP && align != AlignY.BOTTOM) {
|
||
|
throw new IllegalArgumentException("Can align only to top or bottom.");
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* make a new holder.<br>
|
||
|
* Context must be assigned before rendering.
|
||
|
*
|
||
|
* @param app app access
|
||
|
* @param elementHeight height of all elements
|
||
|
* @param align component align. Legal values are TOP and BOTTOM.
|
||
|
*/
|
||
10 years ago
|
public FlowRowLayout(AppAccess app, Num elementHeight, AlignY align)
|
||
10 years ago
|
{
|
||
10 years ago
|
this(app, null, elementHeight, align);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Add an item
|
||
|
*
|
||
|
* @param elem
|
||
|
*/
|
||
|
public void add(final Component elem)
|
||
|
{
|
||
|
if (elem == null) return;
|
||
|
|
||
|
final Rect r;
|
||
|
|
||
|
switch (align) {
|
||
|
case TOP:
|
||
10 years ago
|
r = topEdge().growDown(elementHeight).moveY(elementHeight.mul(row++));
|
||
10 years ago
|
break;
|
||
|
case BOTTOM:
|
||
10 years ago
|
r = bottomEdge().growUp(elementHeight).moveY(elementHeight.mul(-(row++)));
|
||
10 years ago
|
break;
|
||
|
default:
|
||
|
throw new IllegalArgumentException("Bad align.");
|
||
|
}
|
||
|
|
||
|
elem.setRect(r);
|
||
|
|
||
|
attach(elem);
|
||
|
}
|
||
|
|
||
10 years ago
|
|
||
|
public void setElementHeight(Num elementHeight)
|
||
|
{
|
||
|
this.elementHeight = elementHeight;
|
||
|
}
|
||
10 years ago
|
}
|