Search in sources :

Example 6 with TextField

use of com.badlogic.gdx.scenes.scene2d.ui.TextField in project gdx-skineditor by cobolfoo.

the class OptionsPane method showFloatInputDialog.

/**
	 * 
	 * Display a input dialog asking for a float value
	 * 
	 */
public void showFloatInputDialog(final Field field) {
    try {
        final TextField textValue = new TextField(String.valueOf((Float) field.get(currentStyle)), game.skin);
        Dialog dlg = new Dialog("Change Value", game.skin) {

            @Override
            protected void result(Object object) {
                if ((Boolean) object == false) {
                    return;
                }
                float value = 0;
                String text = textValue.getText();
                if (text.isEmpty() == false) {
                    value = Float.valueOf(text);
                }
                try {
                    field.set(currentStyle, value);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                game.screenMain.saveToSkin();
                refresh();
                game.screenMain.paneOptions.updateSelectedTableFields();
                game.screenMain.panePreview.refresh();
            }
        };
        dlg.pad(20);
        dlg.getContentTable().add("Float Value:");
        dlg.getContentTable().add(textValue).pad(20);
        dlg.button("OK", true);
        dlg.button("Cancel", false);
        dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
        dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
        dlg.show(getStage());
        getStage().setKeyboardFocus(textValue);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DrawablePickerDialog(org.shadebob.skineditor.DrawablePickerDialog) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) FontPickerDialog(org.shadebob.skineditor.FontPickerDialog) ColorPickerDialog(org.shadebob.skineditor.ColorPickerDialog) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField)

Example 7 with TextField

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

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

use of com.badlogic.gdx.scenes.scene2d.ui.TextField in project gdx-skineditor by cobolfoo.

the class OptionsPane method createNewStyle.

/**
	 * 
	 */
protected void createNewStyle() {
    final TextField textStyleName = new TextField("", game.skin);
    Dialog dlgStyle = new Dialog("New Style", game.skin) {

        @Override
        protected void result(Object object) {
            if ((Boolean) object == false) {
                return;
            }
            String styleName = textStyleName.getText();
            if (styleName.length() == 0) {
                game.showNotice("Warning", "No style name entered!", game.screenMain.stage);
                return;
            }
            // Check if the style name is already in use
            if (listItems.contains(styleName, false)) {
                game.showNotice("Warning", "Style name already in use!", game.screenMain.stage);
                return;
            }
            try {
                game.skinProject.add(styleName, currentStyle.getClass().newInstance());
            } catch (Exception e) {
                e.printStackTrace();
            }
            //game.skinProject.add(text, game.skin.get("default", currentStyle.getClass()), currentStyle.getClass());
            game.screenMain.saveToSkin();
            refresh();
            game.screenMain.panePreview.refresh();
        }
    };
    dlgStyle.pad(20);
    dlgStyle.getContentTable().add("Style Name:");
    dlgStyle.getContentTable().add(textStyleName).pad(20);
    dlgStyle.button("OK", true);
    dlgStyle.button("Cancel", false);
    dlgStyle.key(com.badlogic.gdx.Input.Keys.ENTER, true);
    dlgStyle.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
    dlgStyle.show(getStage());
    getStage().setKeyboardFocus(textStyleName);
}
Also used : DrawablePickerDialog(org.shadebob.skineditor.DrawablePickerDialog) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) FontPickerDialog(org.shadebob.skineditor.FontPickerDialog) ColorPickerDialog(org.shadebob.skineditor.ColorPickerDialog) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField)

Example 10 with TextField

use of com.badlogic.gdx.scenes.scene2d.ui.TextField in project gdx-skineditor by cobolfoo.

the class WelcomeScreen method showNewProjectDialog.

/**
	 * 
	 */
private void showNewProjectDialog() {
    final TextField textProject = new TextField("", game.skin);
    Dialog dlg = new Dialog("New Project", game.skin) {

        @Override
        protected void result(Object object) {
            if ((Boolean) object == false) {
                return;
            }
            String projectName = textProject.getText();
            projectName = projectName.replace(".", "_");
            projectName = projectName.replace("/", "_");
            projectName = projectName.replace("\\", "_");
            projectName = projectName.replace("-", "_");
            if (projectName.isEmpty() == true)
                return;
            createProject(projectName);
        }
    };
    dlg.pad(20);
    dlg.getContentTable().add("Project Name:");
    dlg.getContentTable().add(textProject).pad(20);
    dlg.button("OK", true);
    dlg.button("Cancel", false);
    dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
    dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
    dlg.setWidth(480);
    dlg.show(stage);
    stage.setKeyboardFocus(textProject);
}
Also used : NinePatchEditorDialog(org.shadebob.skineditor.NinePatchEditorDialog) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField)

Aggregations

TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)10 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)6 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)5 Actor (com.badlogic.gdx.scenes.scene2d.Actor)4 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)4 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)4 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)4 Stage (com.badlogic.gdx.scenes.scene2d.Stage)3 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)3 ColorPickerDialog (org.shadebob.skineditor.ColorPickerDialog)3 DrawablePickerDialog (org.shadebob.skineditor.DrawablePickerDialog)3 FontPickerDialog (org.shadebob.skineditor.FontPickerDialog)3 FileHandle (com.badlogic.gdx.files.FileHandle)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)2 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)2 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)2 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)2