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.
91 lines
2.0 KiB
91 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.AlignX;
|
||
|
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 columns, aligned to left or right
|
||
|
*
|
||
|
* @author MightyPork
|
||
|
*/
|
||
10 years ago
|
public class FlowColumnLayout extends LayoutComponent {
|
||
10 years ago
|
|
||
|
private int col = 0;
|
||
10 years ago
|
private Num elementWidth;
|
||
10 years ago
|
private final AlignX align;
|
||
10 years ago
|
|
||
|
|
||
|
/**
|
||
|
* @param app app access
|
||
|
* @param context context
|
||
|
* @param elementWidth width of all elements
|
||
|
* @param align component align. Legal values are LEFT and RIGHT.
|
||
|
*/
|
||
10 years ago
|
public FlowColumnLayout(AppAccess app, RectBound context, Num elementWidth, AlignX align)
|
||
10 years ago
|
{
|
||
10 years ago
|
super(app, context);
|
||
10 years ago
|
this.elementWidth = elementWidth;
|
||
10 years ago
|
this.align = align;
|
||
|
|
||
10 years ago
|
if (align != AlignX.LEFT && align != AlignX.RIGHT) {
|
||
|
throw new IllegalArgumentException("Can align only left or right.");
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* make a new holder.<br>
|
||
|
* Context must be assigned before rendering.
|
||
|
*
|
||
|
* @param app app access
|
||
|
* @param elementWidth width of all elements
|
||
|
* @param align component align. Legal values are LEFT and RIGHT.
|
||
|
*/
|
||
10 years ago
|
public FlowColumnLayout(AppAccess app, Num elementWidth, AlignX align)
|
||
10 years ago
|
{
|
||
10 years ago
|
this(app, null, elementWidth, align);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Add an item
|
||
|
*
|
||
|
* @param elem
|
||
|
*/
|
||
|
public void add(final Component elem)
|
||
|
{
|
||
|
if (elem == null) return;
|
||
|
|
||
|
final Rect r;
|
||
|
|
||
|
switch (align) {
|
||
|
case LEFT:
|
||
10 years ago
|
r = leftEdge().growRight(elementWidth).moveX(elementWidth.mul(col++));
|
||
10 years ago
|
break;
|
||
|
case RIGHT:
|
||
10 years ago
|
r = rightEdge().growLeft(elementWidth).moveX(elementWidth.mul(-(col++)));
|
||
10 years ago
|
break;
|
||
|
default:
|
||
|
throw new IllegalArgumentException("Bad align.");
|
||
|
}
|
||
|
|
||
|
elem.setRect(r);
|
||
|
|
||
|
attach(elem);
|
||
|
}
|
||
|
|
||
10 years ago
|
|
||
|
public void setElementWidth(Num elementWidth)
|
||
|
{
|
||
|
this.elementWidth = elementWidth;
|
||
|
}
|
||
|
|
||
10 years ago
|
}
|