44 lines
909 B
Java
44 lines
909 B
Java
package speiger.src.coreengine.rendering.gui.helper.constrains;
|
|
|
|
import speiger.src.coreengine.rendering.gui.helper.Align;
|
|
import speiger.src.coreengine.utils.functions.FloatSupplier;
|
|
|
|
public class CenterConstrain extends Constrain
|
|
{
|
|
@Override
|
|
public void apply()
|
|
{
|
|
set((get(target.toWidth()) * 0.5F) - (getOwner(target.toWidth()) * 0.5F));
|
|
}
|
|
|
|
public static class CustomCenterConstrain extends Constrain
|
|
{
|
|
FloatSupplier width;
|
|
boolean inverted;
|
|
|
|
public CustomCenterConstrain(FloatSupplier width)
|
|
{
|
|
this.width = width;
|
|
}
|
|
|
|
public CustomCenterConstrain setInverted(boolean value)
|
|
{
|
|
inverted = value;
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public void apply()
|
|
{
|
|
if(inverted)
|
|
{
|
|
set(Align.CENTER.align(getOwner(target.toWidth()) * 0.5F, width.getAsFloat() * 0.5F));
|
|
return;
|
|
}
|
|
set((width.getAsFloat() * 0.5F) - (getOwner(target.toWidth()) * 0.5F));
|
|
}
|
|
|
|
}
|
|
|
|
}
|