package eu.jonahbauer.wizard.client.libgdx.actors;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;

@SuppressWarnings("unused")
public class AutoFocusScrollPane extends ScrollPane {

    public AutoFocusScrollPane(Actor widget) {
        super(widget);
        init();
    }

    public AutoFocusScrollPane(Actor widget, Skin skin) {
        super(widget, skin);
        init();
    }

    public AutoFocusScrollPane(Actor widget, Skin skin, String styleName) {
        super(widget, skin, styleName);
        init();
    }

    public AutoFocusScrollPane(Actor widget, ScrollPaneStyle style) {
        super(widget, style);
        init();
    }

    private void init() {
        addListener(new InputListener() {
            public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
                getStage().setScrollFocus(AutoFocusScrollPane.this);
            }

            public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
                getStage().setScrollFocus(null);
            }
        });
    }
}