Libgdx: TextField๋Š” SelectBox๋ฅผ ํด๋ฆญํ•˜๊ณ  ํ™•์žฅํ•  ๋•Œ ํฌ์ปค์Šค๋ฅผ ์žƒ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2014๋…„ 07์›” 28์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: libgdx/libgdx

์šด์˜ ์ฒด์ œ: Windows 8.1, x64
gdx๋ฒ„์ „: 1.2.0
ํƒ€๊ฒŸํŒ…: ๋ฐ์Šคํฌํ†ฑ ์ „์šฉ(๋‹ค๋ฅธ ํ”Œ๋žซํผ์—์„œ๋Š” ํ…Œ์ŠคํŠธ๋˜์ง€ ์•Š์Œ)

SelectBox๋ฅผ ํด๋ฆญํ•˜์—ฌ ๋“œ๋กญ๋‹ค์šด ๋ชฉ๋ก์„ ํ‘œ์‹œํ•  ๋•Œ; ์ธ์ ‘ํ•œ ํ…Œ์ด๋ธ” ์…€์˜ TextField๋Š” ํฌ์ปค์Šค๋ฅผ ์žƒ์–ด์•ผ ํ•˜์ง€๋งŒ ๊ทธ๋ ‡์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๊ตฌ์„ฑ ์š”์†Œ๋Š” ํ…Œ์ด๋ธ”๊ณผ ์Šคํ…Œ์ด์ง€๋ฅผ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค. ์ƒํ˜ธ ๋‹จ๊ณ„๋Š” ์ž…๋ ฅ์„ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

์ด๊ฒƒ์€ ์‹ค์ œ๋กœ ์•„๋ฌด ๊ฒƒ๋„ ์†์ƒ์‹œํ‚ค์ง€ ์•Š์ง€๋งŒ ๋ฐ”๋žŒ์งํ•˜์ง€ ์•Š์€ ๋™์ž‘์ด๋ฉฐ ๊ฒŒ์ž„์„ ๋น„์ „๋ฌธ์ ์œผ๋กœ ๋ณด์ด๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์žฌํ˜„ํ•  ๊ด€๋ จ ์ฝ”๋“œ:

    import com.badlogic.gdx.scenes.scene2d.ui.*;

    final Label titleLabel = new Label(
            "Title: ", skin, "heading");

    final Label typeLabel = new Label(
            "Type: ", skin, "heading");

    final TextField textField = new TextField("", skin);

    final SelectBox<String> contextSelector = new SelectBox<String>(skin);
    contextSelector.setItems("Weapon", "Tool", "Crop", "Machine", "World Rule");

    table.row();
        table.add(titleLabel).right();
        table.add(textField).fill().prefWidth(Gdx.graphics.getWidth() / 5.0f).space(1.0f);
    table.row();
        table.add(typeLabel).right();
        table.add(contextSelector).fill().prefWidth(Gdx.graphics.getWidth() / 5.0f).space(1.0f);
    table.row().height(15.0f); table.add().fill();
    table.row();
        table.add(placeHolderLabel1);
        table.add(startButton).right();

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๋‹ค๋ฅธ ์•กํ„ฐ๋ฅผ ํด๋ฆญํ•  ๋•Œ TextField๊ฐ€ ํ•ญ์ƒ ํฌ์ปค์Šค๋ฅผ ์žƒ๊ธฐ๋ฅผ ์›ํ•˜๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋™์ž‘์„ ์ง์ ‘ ์‚ฌ์šฉ์ž ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

stage.getRoot().addCaptureListener(new InputListener() {
    public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        if (!(event.getTarget() instanceof TextField)) stage.setKeyboardFocus(null);
        return false;
    }
}

๋ชจ๋“  3 ๋Œ“๊ธ€

๋‹ค๋ฅธ ์•กํ„ฐ๋ฅผ ํด๋ฆญํ•  ๋•Œ TextField๊ฐ€ ํ•ญ์ƒ ํฌ์ปค์Šค๋ฅผ ์žƒ๊ธฐ๋ฅผ ์›ํ•˜๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋™์ž‘์„ ์ง์ ‘ ์‚ฌ์šฉ์ž ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

stage.getRoot().addCaptureListener(new InputListener() {
    public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        if (!(event.getTarget() instanceof TextField)) stage.setKeyboardFocus(null);
        return false;
    }
}

๊ธ€์Ž„, ๊ทธ๊ฒƒ์€ ํ™•์‹คํžˆ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค. ๊ฑด๋ฐฐ. :-)

๋‹ค์‹œ ํ•œ ๋ฒˆ ๋‚ด ๋ฌธ์ œ์— ๋Œ€ํ•œ ์šฐ์•„ํ•œ ์†”๋ฃจ์…˜์„ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค. scene2d๋Š” ๊ต‰์žฅํ•ฉ๋‹ˆ๋‹ค :)

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰