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

import java.util.function.BooleanSupplier;

import speiger.src.coreengine.rendering.gui.GuiComponent;

public class ConditionalConstraint extends Constrain
{
	BooleanSupplier provider;
	Constrain[] target;
	
	public ConditionalConstraint(BooleanSupplier provider, Constrain... target)
	{
		this.provider = provider;
		this.target = target;
	}

	@Override
	public void apply()
	{
		target[provider.getAsBoolean() ? 1 : 0].apply();
	}
	
	@Override
	public void setComponents(GuiComponent owner, GuiComponent parent, ConstrainTarget target)
	{
		super.setComponents(owner, parent, target);
		for(int i = 0,m=this.target.length;i<m;i++)
		{
			this.target[i].setComponents(owner, parent, target);
		}
	}
	
}
