1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.tests; 18 19 import com.badlogic.gdx.Gdx; 20 import com.badlogic.gdx.graphics.GL20; 21 import com.badlogic.gdx.graphics.g2d.BitmapFont; 22 import com.badlogic.gdx.graphics.g2d.TextureRegion; 23 import com.badlogic.gdx.scenes.scene2d.Actor; 24 import com.badlogic.gdx.scenes.scene2d.InputEvent; 25 import com.badlogic.gdx.scenes.scene2d.InputListener; 26 import com.badlogic.gdx.scenes.scene2d.Stage; 27 import com.badlogic.gdx.scenes.scene2d.ui.Label; 28 import com.badlogic.gdx.scenes.scene2d.ui.Skin; 29 import com.badlogic.gdx.scenes.scene2d.ui.Table; 30 import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 31 import com.badlogic.gdx.scenes.scene2d.ui.TextField; 32 import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; 33 import com.badlogic.gdx.tests.utils.GdxTest; 34 35 public class TableLayoutTest extends GdxTest { 36 Stage stage; 37 38 public void create () { 39 stage = new Stage(); 40 Gdx.input.setInputProcessor(stage); 41 Skin skin = new Skin(Gdx.files.internal("data/uiskin.json")); 42 43 Label nameLabel = new Label("Name:", skin); 44 TextField nameText = new TextField("", skin); 45 Label addressLabel = new Label("Address:", skin); 46 TextField addressText = new TextField("", skin); 47 48 Table table = new Table(); 49 stage.addActor(table); 50 table.setSize(260, 195); 51 table.setPosition(190, 142); 52 // table.align(Align.right | Align.bottom); 53 54 table.debug(); 55 56 TextureRegion upRegion = skin.getRegion("default-slider-knob"); 57 TextureRegion downRegion = skin.getRegion("default-slider-knob"); 58 BitmapFont buttonFont = skin.getFont("default-font"); 59 60 TextButton button = new TextButton("Button 1", skin); 61 button.addListener(new InputListener() { 62 public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { 63 System.out.println("touchDown 1"); 64 return false; 65 } 66 }); 67 table.add(button); 68 // table.setTouchable(Touchable.disabled); 69 70 Table table2 = new Table(); 71 stage.addActor(table2); 72 table2.setFillParent(true); 73 table2.bottom(); 74 75 TextButton button2 = new TextButton("Button 2", skin); 76 button2.addListener(new ChangeListener() { 77 public void changed (ChangeEvent event, Actor actor) { 78 System.out.println("2!"); 79 } 80 }); 81 button2.addListener(new InputListener() { 82 public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { 83 System.out.println("touchDown 2"); 84 return false; 85 } 86 }); 87 table2.add(button2); 88 } 89 90 public void render () { 91 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 92 stage.act(Gdx.graphics.getDeltaTime()); 93 stage.draw(); 94 } 95 96 public void resize (int width, int height) { 97 stage.getViewport().update(width, height, true); 98 } 99 100 public void dispose () { 101 stage.dispose(); 102 } 103 } 104