Search in sources :

Example 21 with TextButton

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

the class StageDebugTest method create.

@Override
public void create() {
    textureRegion = new TextureRegion(new Texture("data/badlogic.jpg"));
    Gdx.input.setInputProcessor(this);
    stage1 = new Stage();
    stage1.getCamera().position.set(100, 100, 0);
    Group group = new Group();
    // group.setBounds(0, 0, 10, 10);
    // group.setOrigin(25, 50);
    group.setRotation(10);
    group.setScale(1.2f);
    stage1.addActor(group);
    DebugActor actor = new DebugActor();
    actor.setBounds(300, 140, 50, 100);
    actor.setOrigin(25, 50);
    actor.setRotation(-45);
    actor.setScale(2f);
    actor.addAction(forever(rotateBy(360, 8f)));
    group.addActor(actor);
    group.debugAll();
    stage2 = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    TextButton shortButton = new TextButton("Button short", skin);
    shortButton.debug();
    TextButton longButton = new TextButton("Button loooooooooong", skin);
    longButton.debug();
    Table root = new Table(skin);
    root.setFillParent(true);
    root.setBackground(skin.getDrawable("default-pane"));
    root.defaults().space(6);
    root.setTransform(true);
    root.rotateBy(10);
    root.setScale(1.3f, 1);
    root.debug();
    stage2.addActor(root);
    root.add(shortButton).pad(5);
    root.add(longButton).row();
    root.add("Colspan").colspan(2).row();
    switchStage();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Group(com.badlogic.gdx.scenes.scene2d.Group) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Texture(com.badlogic.gdx.graphics.Texture)

Example 22 with TextButton

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

the class TableLayoutTest method create.

public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Label nameLabel = new Label("Name:", skin);
    TextField nameText = new TextField("", skin);
    Label addressLabel = new Label("Address:", skin);
    TextField addressText = new TextField("", skin);
    Table table = new Table();
    stage.addActor(table);
    table.setSize(260, 195);
    table.setPosition(190, 142);
    // table.align(Align.right | Align.bottom);
    table.debug();
    TextureRegion upRegion = skin.getRegion("default-slider-knob");
    TextureRegion downRegion = skin.getRegion("default-slider-knob");
    BitmapFont buttonFont = skin.getFont("default-font");
    TextButton button = new TextButton("Button 1", skin);
    button.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("touchDown 1");
            return false;
        }
    });
    table.add(button);
    // table.setTouchable(Touchable.disabled);
    Table table2 = new Table();
    stage.addActor(table2);
    table2.setFillParent(true);
    table2.bottom();
    TextButton button2 = new TextButton("Button 2", skin);
    button2.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            System.out.println("2!");
        }
    });
    button2.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("touchDown 2");
            return false;
        }
    });
    table2.add(button2);
}
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) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 23 with TextButton

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

the class TableTest method create.

@Override
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    TextureRegion region = new TextureRegion(texture);
    NinePatch patch = skin.getPatch("default-round");
    Label label = new Label("This is some text.", skin);
    root = new Table() {

        public void draw(Batch batch, float parentAlpha) {
            super.draw(batch, parentAlpha);
        }
    };
    stage.addActor(root);
    // root.setTransform(true);
    Table table = new Table();
    table.setTransform(true);
    table.setPosition(100, 100);
    table.setOrigin(0, 0);
    table.setRotation(45);
    table.setScaleY(2);
    table.add(label);
    table.add(new TextButton("Text Button", skin));
    table.pack();
    // table.debug();
    table.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            System.out.println("click!");
        }
    });
    //		root.addActor(table);
    TextButton button = new TextButton("Text Button", skin);
    Table table2 = new Table();
    // table2.debug()
    table2.add(button);
    table2.setTransform(true);
    table2.setScaleX(1.5f);
    table2.setOrigin(table2.getPrefWidth() / 2, table2.getPrefHeight() / 2);
    // Test colspan with expandX.
    // root.setPosition(10, 10);
    root.debug();
    root.setFillParent(true);
    root.add(new Label("meow meow meow meow meow meow meow meow meow meow meow meow", skin)).colspan(3).expandX();
    root.add(new TextButton("Text Button", skin));
    root.row();
    root.add(new TextButton("Text Button", skin));
    root.add(new TextButton("Toggle Button", skin.get("toggle", TextButtonStyle.class)));
    root.add(new CheckBox("meow meow meow meow meow meow meow meow", skin));
// root.pack();
// root.add(new Button(new Image(region), skin));
// root.add(new LabelButton("Toggley", skin.getStyle("toggle", LabelButtonStyle.class)));
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Batch(com.badlogic.gdx.graphics.g2d.Batch) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 24 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 25 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)

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