package net.alcuria.umbracraft.editor.widget;

import net.alcuria.umbracraft.Listener;
import net.alcuria.umbracraft.editor.Drawables;
import net.alcuria.umbracraft.editor.layout.EditorLayout;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.kotcrab.vis.ui.widget.VisLabel;
import com.kotcrab.vis.ui.widget.VisTextButton;

/** Some utility functions to display recurring UI elements in the
 * {@link EditorLayout}.
 * @author Andrew Keturi */
public class WidgetUtils {

	/** A convenience function that returns a button with an action
	 * @param text a {@link String} to display on the button
	 * @param listener the {@link Listener} to invoke on click
	 * @return the {@link VisTextButton} */
	public static Actor button(final String text, final Listener listener) {
		return new VisTextButton(text) {
			{
				addListener(new ClickListener() {
					@Override
					public void clicked(InputEvent event, float x, float y) {
						listener.invoke();
					};
				});
			}
		};
	}

	/** Adds a divider to a table
	 * @param table the {@link Table} to add the divider to
	 * @param drawable the {@link Drawable} string, eg "yellow" or "blue" */
	public static void divider(Table table, final String drawable) {
		assert (table != null);
		table.add(new Table() {
			{
				setBackground(Drawables.get(drawable));
			}
		}).expandX().fill().height(1).row();
	}

	/** Adds a popup-style title to a table
	 * @param table the {@link Table} that gets the popup title
	 * @param title a {@link String} to display on the title
	 * @param closeListener the {@link Listener} to invoke when the close button
	 *        is pressed */
	public static void popupTitle(final Table table, final String title, final Listener closeListener) {
		table.add(new Table() {
			{
				setBackground(Drawables.get("blue"));
				add(new VisTextButton("X") {
					{
						addListener(new ClickListener() {
							@Override
							public void clicked(InputEvent event, float x, float y) {
								if (closeListener != null) {
									closeListener.invoke();
								}
							};
						});
					}
				});
				add(new VisLabel(title)).expand().center();
			}
		}).expand().fillX().top().row();
	}

}

@@ -2012,16 +2012,64 @@
 lue%22));%0A
+%09%09%09%09add(new VisLabel(title)).expand().center();%0A
 %09%09%09%09add(
@@ -2341,56 +2341,8 @@
 %7D);%0A
-%09%09%09%09add(new VisLabel(title)).expand().center();%0A
 %09%09%09%7D

Move the close button to the right side of the popup title bar