package speiger.src.coreengine.rendering.gui.helper.constrains;

import speiger.src.coreengine.utils.functions.FloatSupplier;

public class DynamicConstrain extends Constrain
{
	FloatSupplier function;
	boolean invert = false;
	
	public DynamicConstrain(FloatSupplier function)
	{
		this.function = function;
	}
	
	public DynamicConstrain setInverted(boolean invert)
	{
		this.invert = invert;
		return this;
	}
	
	@Override
	public void apply()
	{
		set(invert ? get(target.toWidth()) - function.getAsFloat() : function.getAsFloat());
	}
	
}
