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

import speiger.src.collections.floats.functions.FloatSupplier;
import speiger.src.coreengine.rendering.guiOld.helper.Align;

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));
		}
		
	}
	
}
