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

import speiger.src.coreengine.rendering.guiOld.components.TextComponent;

public class TextConstrain extends Constrain
{
	TextComponent comp;
	boolean horizontal;
	boolean inverted;
	float padding;
	
	private TextConstrain(TextComponent comp, boolean horizontal)
	{
		this.comp = comp;
		this.horizontal = horizontal;
	}
	
	public static TextConstrain width(TextComponent comp)
	{
		return new TextConstrain(comp, true);
	}
	
	public static TextConstrain height(TextComponent comp)
	{
		return new TextConstrain(comp, false);
	}
	
	public TextConstrain setPadding(float padding)
	{
		this.padding = padding;
		return this;
	}
	
	public TextConstrain invert()
	{
		inverted = true;
		return this;
	}
	
	@Override
	public void apply()
	{
		float value = (horizontal ? comp.getMetadata().getMaxWidth() : comp.getMetadata().getMaxHeight()) + padding + (1F * comp.getTextScale());
		set(inverted ? get(target.toWidth()) - value : value);
	}
}
