Search in sources :

Example 16 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project commons-gdx by gemserk.

the class Actors method twoOptionsDialog.

public static Actor twoOptionsDialog(String[] texts, final DialogListener dialogListener, String titleText, String firstOption, String secondOption, Skin skin) {
    Window window = new Window(titleText, skin);
    window.setMovable(false);
    TextButton firstOptionButton = new TextButton(firstOption, skin);
    TextButton secondOptionButton = new TextButton(secondOption, skin);
    firstOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(0);
        }
    });
    secondOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(1);
        }
    });
    window.defaults().spaceBottom(10);
    window.row().fill().expandX();
    for (int i = 0; i < texts.length; i++) {
        window.row().padLeft(20);
        Label label = new Label(texts[i], skin);
        label.setWrap(true);
        window.add(label).align(Align.left).colspan(2).fillX();
    }
    window.row().fill().expandX();
    window.add(firstOptionButton).align(Align.center).padLeft(20).padRight(20).expandX();
    window.add(secondOptionButton).align(Align.center).padLeft(20).padRight(20).expandX();
    ScrollPane scrollPane = new ScrollPane(window);
    scrollPane.setWidth(Gdx.graphics.getWidth() * 0.95f);
    scrollPane.setHeight(Gdx.graphics.getHeight() * 0.95f);
    scrollPane.setX(Gdx.graphics.getWidth() * 0.5f - scrollPane.getWidth() * 0.5f);
    scrollPane.setY(Gdx.graphics.getHeight() * 0.5f - scrollPane.getHeight() * 0.5f);
    return scrollPane;
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 17 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project libgdx by libgdx.

the class ControllersTest method setupUi.

private void setupUi() {
    // setup a tiny ui with a console and a clear button.
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    stage = new Stage();
    ui = new Table();
    ui.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    console = new List(skin);
    scrollPane = new ScrollPane(console);
    scrollPane.setScrollbarsOnTop(true);
    TextButton clear = new TextButton("Clear", skin);
    ui.add(scrollPane).expand(true, true).fill();
    ui.row();
    ui.add(clear).expand(true, false).fill();
    stage.addActor(ui);
    clear.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            clear();
        }
    });
    Gdx.input.setInputProcessor(stage);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) List(com.badlogic.gdx.scenes.scene2d.ui.List) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 18 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project libgdx by libgdx.

the class NoncontinuousRenderingTest method populateTable.

private void populateTable() {
    Table root = new Table();
    stage.addActor(root);
    root.setFillParent(true);
    root.pad(5);
    root.defaults().left().space(5);
    Button button0 = new TextButton("Toggle continuous rendering", skin, "toggle");
    button0.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            boolean continuous = Gdx.graphics.isContinuousRendering();
            Gdx.graphics.setContinuousRendering(!continuous);
        }
    });
    root.add(button0).row();
    final String str1 = "2s sleep -> Application.postRunnable()";
    Button button1 = new TextButton(str1, skin);
    button1.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            new Thread(new Runnable() {

                public void run() {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ignored) {
                    }
                    nextColor();
                    Gdx.app.postRunnable(new Runnable() {

                        public void run() {
                            Gdx.app.log(str1, "Posted runnable to Gdx.app");
                        }
                    });
                }
            }).start();
        }
    });
    root.add(button1).row();
    final String str2 = "2s sleep -> Graphics.requestRendering()";
    Button button2 = new TextButton(str2, skin);
    button2.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            // caching necessary to ensure call on this window
            final Graphics graphics = Gdx.graphics;
            new Thread(new Runnable() {

                public void run() {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ignored) {
                    }
                    nextColor();
                    graphics.requestRendering();
                    Gdx.app.log(str2, "Called Gdx.graphics.requestRendering()");
                }
            }).start();
        }
    });
    root.add(button2).row();
    final String str3 = "2s Timer -> Application.postRunnable()";
    Button button3 = new TextButton(str3, skin);
    button3.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            Timer.schedule(new Task() {

                public void run() {
                    nextColor();
                    Gdx.app.postRunnable(new Runnable() {

                        public void run() {
                            Gdx.app.log(str3, "Posted runnable to Gdx.app");
                        }
                    });
                }
            }, 2f);
        }
    });
    root.add(button3).row();
    final String str4 = "2s DelayAction";
    Button button4 = new TextButton(str4, skin);
    button4.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            stage.addAction(Actions.sequence(Actions.delay(2), Actions.run(new Runnable() {

                public void run() {
                    nextColor();
                    Gdx.app.log(str4, "RunnableAction executed");
                }
            })));
        }
    });
    root.add(button4).row();
    final String str5 = "(2s sleep -> toggle continuous) 2X";
    Button button5 = new TextButton(str5, skin);
    button5.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            // caching necessary to ensure call on this window
            final Graphics graphics = Gdx.graphics;
            new Thread(new Runnable() {

                public void run() {
                    for (int i = 0; i < 2; i++) {
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException ignored) {
                        }
                        nextColor();
                        boolean continuous = graphics.isContinuousRendering();
                        graphics.setContinuousRendering(!continuous);
                        Gdx.app.log(str5, "Toggled continuous");
                    }
                }
            }).start();
        }
    });
    root.add(button5).row();
    final CheckBox actionsRequestRendering = new CheckBox("ActionsRequestRendering", skin);
    actionsRequestRendering.setChecked(true);
    actionsRequestRendering.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            stage.setActionsRequestRendering(actionsRequestRendering.isChecked());
        }
    });
    root.add(actionsRequestRendering).row();
    Drawable knobDown = skin.newDrawable("default-slider-knob", Color.GRAY);
    SliderStyle sliderStyle = skin.get("default-horizontal", SliderStyle.class);
    sliderStyle.knobDown = knobDown;
    Slider slider = new Slider(0, 100, 1, false, sliderStyle);
    root.add(slider).row();
    SelectBox<Pixmap.Format> selectBox = new SelectBox(skin);
    selectBox.setItems(Pixmap.Format.values());
    root.add(selectBox).row();
    root.add();
    root.add().grow();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Task(com.badlogic.gdx.utils.Timer.Task) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) Graphics(com.badlogic.gdx.Graphics) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) SliderStyle(com.badlogic.gdx.scenes.scene2d.ui.Slider.SliderStyle)

Example 19 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project libgdx by libgdx.

the class ParticleEmittersTest method setupUI.

private void setupUI() {
    ui = new Stage(new ExtendViewport(640, 480));
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    skipCleanup = new CheckBox("Skip blend function clean-up", skin);
    skipCleanup.setTransform(false);
    skipCleanup.addListener(listener);
    logLabel = new Label("", skin.get(LabelStyle.class));
    clearEmitters = new TextButton("Clear screen", skin);
    clearEmitters.setTransform(false);
    clearEmitters.addListener(listener);
    Table table = new Table();
    table.setTransform(false);
    table.setFillParent(true);
    table.defaults().padTop(5).left();
    table.top().left().padLeft(5);
    table.add(skipCleanup).row();
    table.add(clearEmitters).row();
    table.add(logLabel);
    ui.addActor(table);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 20 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project libgdx by libgdx.

the class GwtTestWrapper method create.

@Override
public void create() {
    Gdx.app.setLogLevel(Application.LOG_DEBUG);
    Gdx.app.log("GdxTestGwt", "Setting up for " + tests.length + " tests.");
    ui = new Stage();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    container = new Table();
    ui.addActor(container);
    container.debug();
    Table table = new Table();
    ScrollPane scroll = new ScrollPane(table);
    container.add(scroll).expand().fill();
    table.pad(10).defaults().expandX().space(4);
    Arrays.sort(tests, new Comparator<Instancer>() {

        @Override
        public int compare(Instancer o1, Instancer o2) {
            return o1.instance().getClass().getName().compareTo(o2.instance().getClass().getName());
        }
    });
    for (final Instancer instancer : tests) {
        table.row();
        TextButton button = new TextButton(instancer.instance().getClass().getName(), skin);
        button.addListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                ((InputWrapper) Gdx.input).multiplexer.removeProcessor(ui);
                test = instancer.instance();
                Gdx.app.log("GdxTestGwt", "Clicked on " + test.getClass().getName());
                test.create();
                test.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
        });
        table.add(button).expandX().fillX();
    }
    container.row();
    container.add(new Label("Click on a test to start it, press ESC to close it.", new LabelStyle(font, Color.WHITE))).pad(5, 5, 5, 5);
    Gdx.input = new InputWrapper(Gdx.input) {

        @Override
        public boolean keyUp(int keycode) {
            if (keycode == Keys.ESCAPE) {
                if (test != null) {
                    Gdx.app.log("GdxTestGwt", "Exiting current test.");
                    dispose = true;
                }
            }
            return false;
        }

        @Override
        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            if (screenX < Gdx.graphics.getWidth() / 10.0 && screenY < Gdx.graphics.getHeight() / 10.0) {
                if (test != null) {
                    dispose = true;
                }
            }
            return false;
        }
    };
    ((InputWrapper) Gdx.input).multiplexer.addProcessor(ui);
    Gdx.app.log("GdxTestGwt", "Test picker UI setup complete.");
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)35 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)23 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)23 Stage (com.badlogic.gdx.scenes.scene2d.Stage)20 Actor (com.badlogic.gdx.scenes.scene2d.Actor)18 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)17 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)17 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)16 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)12 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)9 Texture (com.badlogic.gdx.graphics.Texture)6 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)6 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)6 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)5 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)5 Slider (com.badlogic.gdx.scenes.scene2d.ui.Slider)5 TextButtonStyle (com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle)5 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)5 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)5