Search in sources :

Example 36 with Label

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

the class ScrollPaneScrollBarsTest method create.

public void create() {
    float width = Gdx.graphics.getWidth();
    float height = Gdx.graphics.getHeight();
    float btnWidth = 200;
    float btnHeight = 40;
    stage = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Gdx.input.setInputProcessor(stage);
    final TextButton fadeBtn = new TextButton("Fade: " + doFade, skin);
    fadeBtn.setSize(btnWidth, btnHeight);
    fadeBtn.setPosition(0, height - fadeBtn.getHeight());
    stage.addActor(fadeBtn);
    fadeBtn.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            doFade = !doFade;
            fadeBtn.setText("Fade: " + doFade);
            for (ScrollPane pane : scrollPanes) {
                pane.setFadeScrollBars(doFade);
            }
        }
    });
    final TextButton onTopBtn = new TextButton("ScrollbarsOnTop: " + doOnTop, skin);
    onTopBtn.setSize(btnWidth, btnHeight);
    onTopBtn.setPosition(0 + fadeBtn.getWidth() + 20, height - onTopBtn.getHeight());
    stage.addActor(onTopBtn);
    onTopBtn.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            doOnTop = !doOnTop;
            onTopBtn.setText("ScrollbarOnTop: " + doOnTop);
            onTopBtn.invalidate();
            for (ScrollPane pane : scrollPanes) {
                pane.setScrollbarsOnTop(doOnTop);
            }
        }
    });
    // Gdx.graphics.setVSync(false);
    float gap = 8;
    float x = gap;
    float y = gap;
    float contWidth = width / 2 - gap * 1.5f;
    float contHeight = height / 4.5f - gap * 1.25f;
    bottomLeft = new Table();
    bottomLeft.setPosition(x, y);
    bottomLeft.setSize(contWidth, contHeight);
    stage.addActor(bottomLeft);
    bottomRight = new Table();
    bottomRight.setSize(contWidth, contHeight);
    x = bottomLeft.getX() + bottomLeft.getWidth() + gap;
    bottomRight.setPosition(x, y);
    stage.addActor(bottomRight);
    topLeft = new Table();
    topLeft.setSize(contWidth, contHeight);
    x = bottomLeft.getX();
    y = bottomLeft.getY() + bottomLeft.getHeight() + gap;
    topLeft.setPosition(x, y);
    stage.addActor(topLeft);
    topRight = new Table();
    topRight.setSize(contWidth, contHeight);
    x = bottomRight.getX();
    y = topLeft.getY();
    topRight.setPosition(x, y);
    stage.addActor(topRight);
    horizOnlyTop = new Table();
    horizOnlyTop.setSize(contWidth, contHeight);
    x = topRight.getX();
    y = topRight.getY() + topRight.getHeight() + gap;
    horizOnlyTop.setPosition(x, y);
    stage.addActor(horizOnlyTop);
    horizOnlyBottom = new Table();
    horizOnlyBottom.setSize(contWidth, contHeight);
    x = topLeft.getX();
    y = topLeft.getY() + topLeft.getHeight() + gap;
    horizOnlyBottom.setPosition(x, y);
    stage.addActor(horizOnlyBottom);
    vertOnlyLeft = new Table();
    vertOnlyLeft.setSize(contWidth, contHeight);
    x = horizOnlyBottom.getX();
    y = horizOnlyBottom.getY() + horizOnlyBottom.getHeight() + gap;
    vertOnlyLeft.setPosition(x, y);
    stage.addActor(vertOnlyLeft);
    vertOnlyRight = new Table();
    vertOnlyRight.setSize(contWidth, contHeight);
    x = horizOnlyTop.getX();
    y = horizOnlyTop.getY() + horizOnlyTop.getHeight() + gap;
    vertOnlyRight.setPosition(x, y);
    stage.addActor(vertOnlyRight);
    Table bottomLeftTable = new Table();
    Table bottomRightTable = new Table();
    Table topLeftTable = new Table();
    Table topRightTable = new Table();
    Table horizOnlyTopTable = new Table();
    Table horizOnlyBottomTable = new Table();
    Table vertOnlyLeftTable = new Table();
    Table vertOnlyRightTable = new Table();
    final ScrollPane bottomLeftScroll = new ScrollPane(bottomLeftTable, skin);
    bottomLeftScroll.setScrollBarPositions(true, false);
    final ScrollPane bottomRightScroll = new ScrollPane(bottomRightTable, skin);
    bottomRightScroll.setScrollBarPositions(true, true);
    final ScrollPane topLeftScroll = new ScrollPane(topLeftTable, skin);
    topLeftScroll.setScrollBarPositions(false, false);
    final ScrollPane topRightScroll = new ScrollPane(topRightTable, skin);
    topRightScroll.setScrollBarPositions(false, true);
    final ScrollPane horizOnlyTopScroll = new ScrollPane(horizOnlyTopTable, skin);
    horizOnlyTopScroll.setScrollBarPositions(false, true);
    final ScrollPane horizOnlyBottomScroll = new ScrollPane(horizOnlyBottomTable, skin);
    horizOnlyBottomScroll.setScrollBarPositions(true, true);
    final ScrollPane vertOnlyLeftScroll = new ScrollPane(vertOnlyLeftTable, skin);
    vertOnlyLeftScroll.setScrollBarPositions(true, false);
    final ScrollPane vertOnlyRightScroll = new ScrollPane(vertOnlyRightTable, skin);
    vertOnlyRightScroll.setScrollBarPositions(true, true);
    ScrollPane[] panes = new ScrollPane[] { bottomLeftScroll, bottomRightScroll, topLeftScroll, topRightScroll, horizOnlyTopScroll, horizOnlyBottomScroll, vertOnlyLeftScroll, vertOnlyRightScroll };
    for (ScrollPane pane : panes) {
        scrollPanes.add(pane);
    }
    Table[] tables = new Table[] { bottomLeftTable, bottomRightTable, topLeftTable, topRightTable, horizOnlyTopTable, horizOnlyBottomTable, vertOnlyLeftTable, vertOnlyRightTable };
    for (Table t : tables) t.defaults().expandX().fillX();
    horizOnlyTopTable.add(new Label("HORIZONTAL-ONLY-TOP verify HORIZONTAL scroll bar is on the TOP and properly aligned", skin)).row();
    horizOnlyTopTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
    horizOnlyBottomTable.add(new Label("HORIZONTAL-ONLY-BOTTOM verify HORIZONTAL scroll bar is on the BOTTOM and properly aligned", skin)).row();
    horizOnlyBottomTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
    for (int i = 0; i < 12; i++) {
        bottomLeftTable.add(new Label(i + " BOTTOM-LEFT verify scroll bars are on the BOTTOM and the LEFT, and are properly aligned", skin)).row();
        bottomLeftTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
        bottomRightTable.add(new Label(i + " BOTTOM-RIGHT verify scroll bars are on the BOTTOM and the RIGHT, and are properly aligned", skin)).row();
        bottomRightTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
        topLeftTable.add(new Label(i + " TOP-LEFT verify scroll bars are on the TOP and the LEFT, and are properly aligned", skin)).row();
        topLeftTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
        topRightTable.add(new Label(i + " TOP-RIGHT verify scroll bars are on the TOP and the RIGHT, and are properly aligned", skin)).row();
        topRightTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
        vertOnlyLeftTable.add(new Label("VERT-ONLY-LEFT", skin)).row();
        vertOnlyLeftTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
        vertOnlyRightTable.add(new Label("VERT-ONLY-RIGHT", skin)).row();
        vertOnlyRightTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
    }
    bottomLeft.add(bottomLeftScroll).expand().fill().colspan(4);
    bottomRight.add(bottomRightScroll).expand().fill().colspan(4);
    topLeft.add(topLeftScroll).expand().fill().colspan(4);
    topRight.add(topRightScroll).expand().fill().colspan(4);
    horizOnlyTop.add(horizOnlyTopScroll).expand().fill().colspan(4);
    horizOnlyBottom.add(horizOnlyBottomScroll).expand().fill().colspan(4);
    vertOnlyLeft.add(vertOnlyLeftScroll).expand().fill().colspan(4);
    vertOnlyRight.add(vertOnlyRightScroll).expand().fill().colspan(4);
    for (ScrollPane pane : scrollPanes) {
        pane.setFadeScrollBars(doFade);
        pane.setScrollbarsOnTop(doOnTop);
    }
}
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) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 37 with Label

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

the class ScrollPaneTest method create.

public void create() {
    stage = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Gdx.input.setInputProcessor(stage);
    // Gdx.graphics.setVSync(false);
    container = new Table();
    stage.addActor(container);
    container.setFillParent(true);
    Table table = new Table();
    // table.debug();
    final ScrollPane scroll = new ScrollPane(table, skin);
    InputListener stopTouchDown = new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return false;
        }
    };
    table.pad(10).defaults().expandX().space(4);
    for (int i = 0; i < 100; i++) {
        table.row();
        table.add(new Label(i + "uno", skin)).expandX().fillX();
        TextButton button = new TextButton(i + "dos", skin);
        table.add(button);
        button.addListener(new ClickListener() {

            public void clicked(InputEvent event, float x, float y) {
                System.out.println("click " + x + ", " + y);
            }
        });
        Slider slider = new Slider(0, 100, 1, false, skin);
        // Stops touchDown events from propagating to the FlickScrollPane.
        slider.addListener(stopTouchDown);
        table.add(slider);
        table.add(new Label(i + "tres long0 long1 long2 long3 long4 long5 long6 long7 long8 long9 long10 long11 long12", skin));
    }
    final TextButton flickButton = new TextButton("Flick Scroll", skin.get("toggle", TextButtonStyle.class));
    flickButton.setChecked(true);
    flickButton.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            scroll.setFlickScroll(flickButton.isChecked());
        }
    });
    final TextButton fadeButton = new TextButton("Fade Scrollbars", skin.get("toggle", TextButtonStyle.class));
    fadeButton.setChecked(true);
    fadeButton.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            scroll.setFadeScrollBars(fadeButton.isChecked());
        }
    });
    final TextButton smoothButton = new TextButton("Smooth Scrolling", skin.get("toggle", TextButtonStyle.class));
    smoothButton.setChecked(true);
    smoothButton.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            scroll.setSmoothScrolling(smoothButton.isChecked());
        }
    });
    final TextButton onTopButton = new TextButton("Scrollbars On Top", skin.get("toggle", TextButtonStyle.class));
    onTopButton.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            scroll.setScrollbarsOnTop(onTopButton.isChecked());
        }
    });
    container.add(scroll).expand().fill().colspan(4);
    container.row().space(10).padBottom(10);
    container.add(flickButton).right().expandX();
    container.add(onTopButton);
    container.add(smoothButton);
    container.add(fadeButton).left().expandX();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 38 with Label

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

the class UITest method create.

@Override
public void create() {
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    texture1 = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture2 = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    TextureRegion image = new TextureRegion(texture1);
    TextureRegion imageFlipped = new TextureRegion(image);
    imageFlipped.flip(true, true);
    TextureRegion image2 = new TextureRegion(texture2);
    // stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false, new PolygonSpriteBatch());
    stage = new Stage(new ScreenViewport());
    Gdx.input.setInputProcessor(stage);
    // Group.debug = true;
    ImageButtonStyle style = new ImageButtonStyle(skin.get(ButtonStyle.class));
    style.imageUp = new TextureRegionDrawable(image);
    style.imageDown = new TextureRegionDrawable(imageFlipped);
    ImageButton iconButton = new ImageButton(style);
    Button buttonMulti = new TextButton("Multi\nLine\nToggle", skin, "toggle");
    Button imgButton = new Button(new Image(image), skin);
    Button imgToggleButton = new Button(new Image(image), skin, "toggle");
    Label myLabel = new Label("this is some text.", skin);
    myLabel.setWrap(true);
    Table t = new Table();
    t.row();
    t.add(myLabel);
    t.layout();
    final CheckBox checkBox = new CheckBox(" Continuous rendering", skin);
    checkBox.setChecked(true);
    final Slider slider = new Slider(0, 10, 1, false, skin);
    slider.setAnimateDuration(0.3f);
    TextField textfield = new TextField("", skin);
    textfield.setMessageText("Click here!");
    textfield.setAlignment(Align.center);
    final SelectBox selectBox = new SelectBox(skin);
    selectBox.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            System.out.println(selectBox.getSelected());
        }
    });
    selectBox.setItems("Android1", "Windows1 long text in item", "Linux1", "OSX1", "Android2", "Windows2", "Linux2", "OSX2", "Android3", "Windows3", "Linux3", "OSX3", "Android4", "Windows4", "Linux4", "OSX4", "Android5", "Windows5", "Linux5", "OSX5", "Android6", "Windows6", "Linux6", "OSX6", "Android7", "Windows7", "Linux7", "OSX7");
    selectBox.setSelected("Linux6");
    Image imageActor = new Image(image2);
    ScrollPane scrollPane = new ScrollPane(imageActor);
    List list = new List(skin);
    list.setItems(listEntries);
    list.getSelection().setMultiple(true);
    list.getSelection().setRequired(false);
    // list.getSelection().setToggle(true);
    ScrollPane scrollPane2 = new ScrollPane(list, skin);
    scrollPane2.setFlickScroll(false);
    SplitPane splitPane = new SplitPane(scrollPane, scrollPane2, false, skin, "default-horizontal");
    fpsLabel = new Label("fps:", skin);
    // configures an example of a TextField in password mode.
    final Label passwordLabel = new Label("Textfield in password mode: ", skin);
    final TextField passwordTextField = new TextField("", skin);
    passwordTextField.setMessageText("password");
    passwordTextField.setPasswordCharacter('*');
    passwordTextField.setPasswordMode(true);
    buttonMulti.addListener(new TextTooltip("This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip!", skin));
    Table tooltipTable = new Table(skin);
    tooltipTable.pad(10).background("default-round");
    tooltipTable.add(new TextButton("Fancy tooltip!", skin));
    imgButton.addListener(new Tooltip(tooltipTable));
    // window.debug();
    Window window = new Window("Dialog", skin);
    window.getTitleTable().add(new TextButton("X", skin)).height(window.getPadTop());
    window.setPosition(0, 0);
    window.defaults().spaceBottom(10);
    window.row().fill().expandX();
    window.add(iconButton);
    window.add(buttonMulti);
    window.add(imgButton);
    window.add(imgToggleButton);
    window.row();
    window.add(checkBox);
    window.add(slider).minWidth(100).fillX().colspan(3);
    window.row();
    window.add(selectBox).maxWidth(100);
    window.add(textfield).minWidth(100).expandX().fillX().colspan(3);
    window.row();
    window.add(splitPane).fill().expand().colspan(4).maxHeight(200);
    window.row();
    window.add(passwordLabel).colspan(2);
    window.add(passwordTextField).minWidth(100).expandX().fillX().colspan(2);
    window.row();
    window.add(fpsLabel).colspan(4);
    window.pack();
    // stage.addActor(new Button("Behind Window", skin));
    stage.addActor(window);
    textfield.setTextFieldListener(new TextFieldListener() {

        public void keyTyped(TextField textField, char key) {
            if (key == '\n')
                textField.getOnscreenKeyboard().show(false);
        }
    });
    slider.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            Gdx.app.log("UITest", "slider: " + slider.getValue());
        }
    });
    iconButton.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            new Dialog("Some Dialog", skin, "dialog") {

                protected void result(Object object) {
                    System.out.println("Chosen: " + object);
                }
            }.text("Are you enjoying this demo?").button("Yes", true).button("No", false).key(Keys.ENTER, true).key(Keys.ESCAPE, false).show(stage);
        }
    });
    checkBox.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            Gdx.graphics.setContinuousRendering(checkBox.isChecked());
        }
    });
}
Also used : Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) SplitPane(com.badlogic.gdx.scenes.scene2d.ui.SplitPane) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) List(com.badlogic.gdx.scenes.scene2d.ui.List) TextFieldListener(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) ButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) Tooltip(com.badlogic.gdx.scenes.scene2d.ui.Tooltip) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 39 with Label

use of com.badlogic.gdx.scenes.scene2d.ui.Label 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 40 with Label

use of com.badlogic.gdx.scenes.scene2d.ui.Label 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)

Aggregations

Label (com.badlogic.gdx.scenes.scene2d.ui.Label)43 Stage (com.badlogic.gdx.scenes.scene2d.Stage)25 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)24 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)23 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)20 Actor (com.badlogic.gdx.scenes.scene2d.Actor)18 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)16 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)16 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)10 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)10 Texture (com.badlogic.gdx.graphics.Texture)9 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)9 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)9 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)8 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)8 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)7 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)7 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)6 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)5 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)5