package zero1hd.polyjet.ui.pages;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.Array;

import zero1hd.polyjet.util.MiniEvents;
import zero1hd.polyjet.util.MiniListener;

public class Page extends Group {
	private Label pageTitle;
	
	private Array<MiniListener> listeners;

	public Page() {
		setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		setTouchable(Touchable.childrenOnly);
	}
	
	public Page(String titleText, Skin skin) {
		setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		setTouchable(Touchable.childrenOnly);
		pageTitle = new Label(titleText, skin, "large-font", skin.getColor("default"));
		pageTitle.setPosition(18f, getHeight()-pageTitle.getHeight()-15f);
		addActor(pageTitle);
	}
	
	public float getHeightBelowTitle() {
		return pageTitle.getY();
	}
	
	public void send(MiniEvents ID) {
		while (listeners.iterator().hasNext()) {
			listeners.iterator().next().handle(ID);
		}
	}
	
	public void addListener(MiniListener handler) {
		listeners.add(handler);
	}
}
