com.badlogic.gdx.scenes.scene2d.ui
Class Table

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
      extended by com.badlogic.gdx.scenes.scene2d.Group
          extended by com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
              extended by com.badlogic.gdx.scenes.scene2d.ui.Table
All Implemented Interfaces:
Cullable, Layout
Direct Known Subclasses:
Button, Window

public class Table
extends WidgetGroup

A group that sizes and positions children using table constraints. By default, Actor.getTouchable() is Touchable.childrenOnly.

The preferred and minimum sizes are that of the children when laid out in columns and rows.

Author:
Nathan Sweet

Constructor Summary
Table()
           
Table(Skin skin)
          Creates a table with a skin, which enables the add(String) and add(String, String) methods to be used.
 
Method Summary
 Cell<Actor> add()
          Adds a cell without a widget.
 void add(Actor... actors)
           
 Cell<Label> add(String text)
          Adds a new cell with a label.
 Cell<Label> add(String text, String labelStyleName)
          Adds a new cell with a label.
 Cell<Label> add(String text, String fontName, Color color)
          Adds a new cell with a label.
 Cell<Label> add(String text, String fontName, String colorName)
          Adds a new cell with a label.
<T extends Actor>
Cell<T>
add(T actor)
          Adds a new cell to the table with the specified actor.
 Table align(int align)
          Sets the alignment of the logical table within the table widget.
 Table background(Drawable background)
           
 Table background(String drawableName)
           
 Table bottom()
          Adds Align.bottom and clears Align.top for the alignment of the logical table within the table widget.
 Table center()
          Sets the alignment of the logical table within the table widget to Align.center.
 void clearChildren()
          Removes all actors and cells from the table.
 Cell columnDefaults(int column)
          Gets the cell values that will be used as the defaults for all cells in the specified column.
 Table debug()
          Turns on all debug lines.
 Table debug(BaseTableLayout.Debug debug)
          Turns on debug lines.
 Table debugCell()
          Turns on cell debug lines.
 Table debugTable()
          Turns on table debug lines.
 Table debugWidget()
          Turns on widget debug lines.
 Cell defaults()
          The cell values that will be used as the defaults for all cells.
 void draw(Batch batch, float parentAlpha)
          If this method is overridden, the super method or WidgetGroup.validate() should be called to ensure the widget group is laid out.
static void drawDebug(Stage stage)
          Draws the debug lines for all tables in the stage.
 int getAlign()
           
 Drawable getBackground()
           
<T extends Actor>
Cell<T>
getCell(T actor)
          Returns the cell for the specified widget in this table, or null.
 List<Cell> getCells()
          Returns the cells for this table.
 boolean getClip()
           
 BaseTableLayout.Debug getDebug()
           
 float getMinHeight()
           
 float getMinWidth()
           
 float getPadBottom()
           
 Value getPadBottomValue()
           
 float getPadLeft()
           
 Value getPadLeftValue()
           
 float getPadRight()
           
 Value getPadRightValue()
           
 float getPadTop()
           
 Value getPadTopValue()
           
 float getPadX()
          Returns getPadLeft() plus getPadRight().
 float getPadY()
          Returns getPadTop() plus getPadBottom().
 float getPrefHeight()
           
 float getPrefWidth()
           
 int getRow(float y)
          Returns the row index for the y coordinate.
 Actor hit(float x, float y, boolean touchable)
          Returns the deepest actor that contains the specified point and is touchable and visible, or null if no actor was hit.
 void invalidate()
          Invalidates this actor's layout, causing Layout.layout() to happen the next time Layout.validate() is called.
 void layout()
          Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls Layout.invalidate() any each child whose width or height has changed, and calls Layout.validate() on each child.
 Table left()
          Adds Align.left and clears Align.right for the alignment of the logical table within the table widget.
 Table pad(float pad)
          Sets the padTop, padLeft, padBottom, and padRight around the table to the specified value.
 Table pad(float top, float left, float bottom, float right)
           
 Table pad(Value pad)
          Sets the padTop, padLeft, padBottom, and padRight around the table to the specified value.
 Table pad(Value top, Value left, Value bottom, Value right)
           
 Table padBottom(float padBottom)
          Padding at the bottom edge of the table.
 Table padBottom(Value padBottom)
          Padding at the bottom edge of the table.
 Table padLeft(float padLeft)
          Padding at the left edge of the table.
 Table padLeft(Value padLeft)
          Padding at the left edge of the table.
 Table padRight(float padRight)
          Padding at the right edge of the table.
 Table padRight(Value padRight)
          Padding at the right edge of the table.
 Table padTop(float padTop)
          Padding at the top edge of the table.
 Table padTop(Value padTop)
          Padding at the top edge of the table.
 boolean removeActor(Actor actor)
          Removes an actor from this group.
 void reset()
          Removes all actors and cells from the table (same as clearChildren()) and additionally resets all table properties and cell, column, and row defaults.
 Table right()
          Adds Align.right and clears Align.left for the alignment of the logical table within the table widget.
 Cell row()
          Indicates that subsequent cells should be added to a new row and returns the cell values that will be used as the defaults for all cells in the new row.
 void setBackground(Drawable background)
          Sets the background drawable and adjusts the table's padding to match the background.
 void setBackground(Drawable background, boolean adjustPadding)
          Sets the background drawable and, if adjustPadding is true, sets the table's padding to Drawable.getBottomHeight() , Drawable.getTopHeight(), Drawable.getLeftWidth(), and Drawable.getRightWidth().
 void setBackground(String drawableName)
          Sets the background drawable from the skin and adjusts the table's padding to match the background.
 void setClip(boolean enabled)
          Causes the contents to be clipped if they exceed the table widget bounds.
 void setRound(boolean round)
          If true (the default), positions and sizes are rounded to integers.
 void setSkin(Skin skin)
           
 Cell<Stack> stack(Actor... actors)
          Adds a new cell to the table with the specified actors in a Stack.
 Table top()
          Adds Align.top and clears Align.bottom for the alignment of the logical table within the table widget.
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
getMaxHeight, getMaxWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, validate
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Group
act, addActor, addActorAfter, addActorAt, addActorBefore, clear, findActor, getChildren, hasChildren, isTransform, localToDescendantCoordinates, print, setCullingArea, setTransform, swapActor, swapActor
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getY, getZIndex, hasParent, isAscendantOf, isDescendantOf, isTouchable, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotateBy, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOriginX, setOriginY, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Table

public Table()

Table

public Table(Skin skin)
Creates a table with a skin, which enables the add(String) and add(String, String) methods to be used.

Method Detail

draw

public void draw(Batch batch,
                 float parentAlpha)
Description copied from class: WidgetGroup
If this method is overridden, the super method or WidgetGroup.validate() should be called to ensure the widget group is laid out.

Overrides:
draw in class WidgetGroup
parentAlpha - Should be multiplied with the actor's alpha, allowing a parent's alpha to affect all children.

invalidate

public void invalidate()
Description copied from interface: Layout
Invalidates this actor's layout, causing Layout.layout() to happen the next time Layout.validate() is called. This method should be called when state changes in the actor that requires a layout but does not change the minimum, preferred, maximum, or actual size of the actor (meaning it does not affect the parent actor's layout).

Specified by:
invalidate in interface Layout
Overrides:
invalidate in class WidgetGroup

getPrefWidth

public float getPrefWidth()
Specified by:
getPrefWidth in interface Layout
Overrides:
getPrefWidth in class WidgetGroup

getPrefHeight

public float getPrefHeight()
Specified by:
getPrefHeight in interface Layout
Overrides:
getPrefHeight in class WidgetGroup

getMinWidth

public float getMinWidth()
Specified by:
getMinWidth in interface Layout
Overrides:
getMinWidth in class WidgetGroup

getMinHeight

public float getMinHeight()
Specified by:
getMinHeight in interface Layout
Overrides:
getMinHeight in class WidgetGroup

setBackground

public void setBackground(String drawableName)
Sets the background drawable from the skin and adjusts the table's padding to match the background. This may only be called if Table(Skin) or setSkin(Skin) was used.

See Also:
setBackground(Drawable, boolean)

setBackground

public void setBackground(Drawable background)
Sets the background drawable and adjusts the table's padding to match the background.

See Also:
setBackground(Drawable, boolean)

setBackground

public void setBackground(Drawable background,
                          boolean adjustPadding)
Sets the background drawable and, if adjustPadding is true, sets the table's padding to Drawable.getBottomHeight() , Drawable.getTopHeight(), Drawable.getLeftWidth(), and Drawable.getRightWidth().

Parameters:
background - If null, the background will be cleared and padding removed.

background

public Table background(Drawable background)
See Also:
setBackground(Drawable)

background

public Table background(String drawableName)
See Also:
setBackground(String)

getBackground

public Drawable getBackground()

hit

public Actor hit(float x,
                 float y,
                 boolean touchable)
Description copied from class: Actor
Returns the deepest actor that contains the specified point and is touchable and visible, or null if no actor was hit. The point is specified in the actor's local coordinate system (0,0 is the bottom left of the actor and width,height is the upper right).

This method is used to delegate touchDown, mouse, and enter/exit events. If this method returns null, those events will not occur on this Actor.

The default implementation returns this actor if the point is within this actor's bounds.

Overrides:
hit in class Group
touchable - If true, the hit detection will respect the touchability.
See Also:
Touchable

setClip

public void setClip(boolean enabled)
Causes the contents to be clipped if they exceed the table widget bounds. Enabling clipping will set Group.setTransform(boolean) to true.


getClip

public boolean getClip()

getRow

public int getRow(float y)
Returns the row index for the y coordinate.


clearChildren

public void clearChildren()
Removes all actors and cells from the table.

Overrides:
clearChildren in class Group

add

public Cell<Label> add(String text)
Adds a new cell with a label. This may only be called if Table(Skin) or setSkin(Skin) was used.


add

public Cell<Label> add(String text,
                       String labelStyleName)
Adds a new cell with a label. This may only be called if Table(Skin) or setSkin(Skin) was used.


add

public Cell<Label> add(String text,
                       String fontName,
                       Color color)
Adds a new cell with a label. This may only be called if Table(Skin) or setSkin(Skin) was used.


add

public Cell<Label> add(String text,
                       String fontName,
                       String colorName)
Adds a new cell with a label. This may only be called if Table(Skin) or setSkin(Skin) was used.


add

public Cell<Actor> add()
Adds a cell without a widget.


add

public <T extends Actor> Cell<T> add(T actor)
Adds a new cell to the table with the specified actor.

Parameters:
actor - May be null to add a cell without an actor.

add

public void add(Actor... actors)

removeActor

public boolean removeActor(Actor actor)
Description copied from class: Group
Removes an actor from this group. If the actor will not be used again and has actions, they should be cleared so the actions will be returned to their pool, if any. This is not done automatically.

Overrides:
removeActor in class Group

stack

public Cell<Stack> stack(Actor... actors)
Adds a new cell to the table with the specified actors in a Stack.

Parameters:
actors - May be null to add a stack without any actors.

row

public Cell row()
Indicates that subsequent cells should be added to a new row and returns the cell values that will be used as the defaults for all cells in the new row.


columnDefaults

public Cell columnDefaults(int column)
Gets the cell values that will be used as the defaults for all cells in the specified column. Columns are indexed starting at 0.


defaults

public Cell defaults()
The cell values that will be used as the defaults for all cells.


layout

public void layout()
Description copied from interface: Layout
Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls Layout.invalidate() any each child whose width or height has changed, and calls Layout.validate() on each child. This method should almost never be called directly, instead Layout.validate() should be used.

Specified by:
layout in interface Layout
Overrides:
layout in class WidgetGroup

reset

public void reset()
Removes all actors and cells from the table (same as clearChildren()) and additionally resets all table properties and cell, column, and row defaults.


getCell

public <T extends Actor> Cell<T> getCell(T actor)
Returns the cell for the specified widget in this table, or null.


getCells

public List<Cell> getCells()
Returns the cells for this table.


pad

public Table pad(Value pad)
Sets the padTop, padLeft, padBottom, and padRight around the table to the specified value.


pad

public Table pad(Value top,
                 Value left,
                 Value bottom,
                 Value right)

padTop

public Table padTop(Value padTop)
Padding at the top edge of the table.


padLeft

public Table padLeft(Value padLeft)
Padding at the left edge of the table.


padBottom

public Table padBottom(Value padBottom)
Padding at the bottom edge of the table.


padRight

public Table padRight(Value padRight)
Padding at the right edge of the table.


pad

public Table pad(float pad)
Sets the padTop, padLeft, padBottom, and padRight around the table to the specified value.


pad

public Table pad(float top,
                 float left,
                 float bottom,
                 float right)

padTop

public Table padTop(float padTop)
Padding at the top edge of the table.


padLeft

public Table padLeft(float padLeft)
Padding at the left edge of the table.


padBottom

public Table padBottom(float padBottom)
Padding at the bottom edge of the table.


padRight

public Table padRight(float padRight)
Padding at the right edge of the table.


align

public Table align(int align)
Sets the alignment of the logical table within the table widget. Set to Align.center, Align.top, Align.bottom , Align.left , Align.right, or any combination of those.


center

public Table center()
Sets the alignment of the logical table within the table widget to Align.center. This clears any other alignment.


top

public Table top()
Adds Align.top and clears Align.bottom for the alignment of the logical table within the table widget.


left

public Table left()
Adds Align.left and clears Align.right for the alignment of the logical table within the table widget.


bottom

public Table bottom()
Adds Align.bottom and clears Align.top for the alignment of the logical table within the table widget.


right

public Table right()
Adds Align.right and clears Align.left for the alignment of the logical table within the table widget.


debug

public Table debug()
Turns on all debug lines.


debugTable

public Table debugTable()
Turns on table debug lines.


debugCell

public Table debugCell()
Turns on cell debug lines.


debugWidget

public Table debugWidget()
Turns on widget debug lines.


debug

public Table debug(BaseTableLayout.Debug debug)
Turns on debug lines.


getDebug

public BaseTableLayout.Debug getDebug()

getPadTopValue

public Value getPadTopValue()

getPadTop

public float getPadTop()

getPadLeftValue

public Value getPadLeftValue()

getPadLeft

public float getPadLeft()

getPadBottomValue

public Value getPadBottomValue()

getPadBottom

public float getPadBottom()

getPadRightValue

public Value getPadRightValue()

getPadRight

public float getPadRight()

getPadX

public float getPadX()
Returns getPadLeft() plus getPadRight().


getPadY

public float getPadY()
Returns getPadTop() plus getPadBottom().


getAlign

public int getAlign()

setSkin

public void setSkin(Skin skin)

setRound

public void setRound(boolean round)
If true (the default), positions and sizes are rounded to integers.


drawDebug

public static void drawDebug(Stage stage)
Draws the debug lines for all tables in the stage. If this method is not called each frame, no debug lines will be drawn. If debug is never turned on for any table in the application, calling this method will have no effect. If a table has ever had debug set, calling this method causes an expensive traversal of all actors in the stage.



Copyright © 2014. All Rights Reserved.