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.
78 lines
1.2 KiB
78 lines
1.2 KiB
package mightypork.gamecore.gui.components;
|
|
|
|
|
|
import mightypork.dynmath.num.Num;
|
|
import mightypork.dynmath.rect.Rect;
|
|
import mightypork.dynmath.rect.proxy.RectBound;
|
|
import mightypork.dynmath.vect.Vect;
|
|
import mightypork.dynmath.vect.proxy.VectAdapter;
|
|
|
|
|
|
public abstract class LinearComponent extends BaseComponent implements DynamicWidthComponent {
|
|
|
|
private final Rect rect = new Rect() {
|
|
|
|
@Override
|
|
public Vect size()
|
|
{
|
|
return new Vect() {
|
|
|
|
@Override
|
|
public double x()
|
|
{
|
|
return computeWidth(y());
|
|
}
|
|
|
|
|
|
@Override
|
|
public double y()
|
|
{
|
|
return height.value();
|
|
}
|
|
|
|
};
|
|
}
|
|
|
|
|
|
@Override
|
|
public Vect origin()
|
|
{
|
|
return new VectAdapter() {
|
|
|
|
@Override
|
|
protected Vect getSource()
|
|
{
|
|
return origin;
|
|
}
|
|
};
|
|
}
|
|
};
|
|
|
|
private Vect origin;
|
|
private Num height;
|
|
|
|
|
|
public LinearComponent()
|
|
{
|
|
super.setRect(rect);
|
|
}
|
|
|
|
|
|
@Override
|
|
public void setRect(RectBound rect)
|
|
{
|
|
throw new RuntimeException("Cannot assign a rect to a linear component. Set origin and height instead.");
|
|
}
|
|
|
|
|
|
public void setHeight(Num height)
|
|
{
|
|
this.height = height;
|
|
}
|
|
|
|
|
|
public void setOrigin(Vect origin)
|
|
{
|
|
this.origin = origin;
|
|
}
|
|
}
|
|
|