Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing table borders in libgdx 0.9.7

I am drawing a table in using libgdx game framework. Everything is rendered perfectly what I was trying to achieve. All I need now is to display cell borders of the table but I found nothing regarding this so far. I am also inclined to use the debug border lines to fullfill the purpose but also could not change the color of them.

Here is my code.

Table table = new Table();
table.setFillParent(true);
table.left().top();

table.add(new Label("Results", new LabelStyle(font, Color.BLACK))).colspan(2).expandX();
table.row();
table.add(new Label(text_you_score, new LabelStyle(font, Color.BLACK)));
table.add(new Label(text_actual_score, new LabelStyle(font, Color.BLACK)));
return table;

There are many properties available for the table and cell but not the border property. We can also draw grid lines manually but that won't work perfectly on every device resolution I think. Any help or idea is highly appreciated. Thanks

like image 478
ktk Avatar asked Dec 11 '12 21:12

ktk


2 Answers

This is based on libGDX 1.5.3:

A solution to this is to use a NinePatch as the background image for your Table.

NinePatch patch = new NinePatch(new Texture(Gdx.files.internal("background.png")),
     3, 3, 3, 3);
NinePatchDrawable background = new NinePatchDrawable(patch);

Table table = new Table();
table.setBackground(background);

Using the number variables, you can modify the border radius. Make sure that this matches the png file.

like image 156
Simon Forsberg Avatar answered Nov 17 '22 20:11

Simon Forsberg


  1. Register your table for debug mode

    table.debug();

  2. Call in render() method

    Table.drawDebug(stage);

Example

like image 3
Slavik Voloshyn Avatar answered Nov 17 '22 20:11

Slavik Voloshyn