Skip to content

Instantly share code, notes, and snippets.

@Tom-Ski
Created August 14, 2019 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tom-Ski/da3d3ef1178022fabcb975563c884b5f to your computer and use it in GitHub Desktop.
Save Tom-Ski/da3d3ef1178022fabcb975563c884b5f to your computer and use it in GitHub Desktop.
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
public class SimpleTest extends ApplicationAdapter {
Stage stage;
@Override
public void create () {
super.create();
stage = new Stage();
Pixmap pixmap = new Pixmap(10, 10, Pixmap.Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fill();
Texture tex = new Texture(pixmap);
pixmap.dispose();
Label.LabelStyle labelStyle = new Label.LabelStyle();
labelStyle.font = new BitmapFont();
Label label = new Label("Hey! This is the label I'm talking about. As you can see, the label has the wrapped property set to true and I would like the container to fit exactly the size of the label", labelStyle);
label.setWrap(true);
Table table = new Table();
table.setBackground(new TextureRegionDrawable(new TextureRegion(tex)));
table.add(label).width(200).left();
table.pack();
table.debug();
table.setPosition(Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f);
stage.addActor(table);
}
@Override
public void render () {
super.render();
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
}
public static void main (String[] args) {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setWindowedMode(1280, 720);
new Lwjgl3Application(new SimpleTest(), config);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment