Skip to content

Instantly share code, notes, and snippets.

@thepaperpilot
Created February 8, 2015 01:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thepaperpilot/b85857813fc1c785df4b to your computer and use it in GitHub Desktop.
Save thepaperpilot/b85857813fc1c785df4b to your computer and use it in GitHub Desktop.
An extension of the LibGDX Table, that wraps actors added to it, based on the table's current width. Use setSize() before adding any actors.
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
/** Like a table, but wraps widgets to new rows once the preferred width has been reached
* @author The Paper Pilot */
public class FlowTable extends Table{
@Override
public <T extends Actor> Cell<T> add (T actor) {
float oldWith = getWidth();
Cell<T> cell = super.add(actor);
while(getWidth() > oldWith) {
removeActor(actor);
row();
cell = super.add(actor);
}
return cell;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment