Class Table
- java.lang.Object
-
- com.badlogic.gdx.scenes.scene2d.Actor
-
- com.badlogic.gdx.scenes.scene2d.Group
-
- com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
-
- com.badlogic.gdx.scenes.scene2d.ui.Table
-
public class Table extends WidgetGroup
A group that sizes and positions children using table constraints.Children added with
add(Actor...)(and similar methods returning aCell) are laid out in rows and columns. Other children may be added withGroup.addActor(Actor)(and similar methods) but are not laid out automatically and don't affect the preferred or minimum sizes.By default,
Actor.getTouchable()isTouchable.childrenOnly.The preferred and minimum sizes are that of the children laid out in columns and rows.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTable.Debugstatic classTable.DebugRect
-
Field Summary
Fields Modifier and Type Field Description static ValuebackgroundBottomValue that is the bottom padding of the table's background.static ValuebackgroundLeftValue that is the left padding of the table's background.static ValuebackgroundRightValue that is the right padding of the table's background.static ValuebackgroundTopValue that is the top padding of the table's background.static ColordebugActorColorstatic ColordebugCellColorstatic ColordebugTableColor
-
Constructor Summary
Constructors Constructor Description Table()Table(Skin skin)Creates a table with a skin, which is required to useadd(CharSequence)oradd(CharSequence, String).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Celladd()Adds a cell without an actor.Tableadd(Actor... actors)Cell<Label>add(java.lang.CharSequence text)Adds a new cell with a label.Cell<Label>add(java.lang.CharSequence text, java.lang.String labelStyleName)Adds a new cell with a label.Cell<Label>add(java.lang.CharSequence text, java.lang.String fontName, Color color)Adds a new cell with a label.Cell<Label>add(java.lang.CharSequence text, java.lang.String fontName, java.lang.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.Tablealign(int align)Alignment of the logical table within the table actor.Tablebackground(Drawable background)Tablebackground(java.lang.String drawableName)Tablebottom()AddsAlign.bottomand clearsAlign.topfor the alignment of the logical table within the table actor.Tablecenter()Sets the alignment of the logical table within the table actor toAlign.center.voidclearChildren(boolean unfocus)Removes all actors and cells from the table.Tableclip()SetssetClip(boolean)to true.Tableclip(boolean enabled)CellcolumnDefaults(int column)Gets the cell values that will be used as the defaults for all cells in the specified column.Tabledebug()CallsActor.setDebug(boolean)withtrue.Tabledebug(Table.Debug debug)Turns debug lines on or off.TabledebugActor()Turns on actor debug lines.TabledebugAll()CallsGroup.setDebug(boolean, boolean)withtrue, true.TabledebugCell()Turns on cell debug lines.TabledebugTable()Turns on table debug lines.Celldefaults()The cell values that will be used as the defaults for all cells.voiddraw(Batch batch, float parentAlpha)If this method is overridden, the super method orWidgetGroup.validate()should be called to ensure the widget group is laid out.protected voiddrawBackground(Batch batch, float parentAlpha, float x, float y)Called to draw the background, before clipping is applied (if enabled).voiddrawDebug(ShapeRenderer shapes)Draws this actor's debug lines ifActor.getDebug()is true and, regardless ofActor.getDebug(), callsActor.drawDebug(ShapeRenderer)on each child.protected voiddrawDebugBounds(ShapeRenderer shapes)Draws a rectangle for the bounds of this actor ifActor.getDebug()is true.intgetAlign()DrawablegetBackground()<T extends Actor>
Cell<T>getCell(T actor)Returns the cell for the specified actor in this table, or null.Array<Cell>getCells()Returns the cells for this table.booleangetClip()floatgetColumnMinWidth(int columnIndex)Returns the min height of the specified column.floatgetColumnPrefWidth(int columnIndex)Returns the pref height of the specified column.intgetColumns()floatgetColumnWidth(int columnIndex)Returns the width of the specified column, or 0 if the table layout has not been validated.floatgetMinHeight()floatgetMinWidth()floatgetPadBottom()ValuegetPadBottomValue()floatgetPadLeft()ValuegetPadLeftValue()floatgetPadRight()ValuegetPadRightValue()floatgetPadTop()ValuegetPadTopValue()floatgetPadX()ReturnsgetPadLeft()plusgetPadRight().floatgetPadY()ReturnsgetPadTop()plusgetPadBottom().floatgetPrefHeight()floatgetPrefWidth()intgetRow(float y)Returns the row index for the y coordinate, or -1 if not over a row.floatgetRowHeight(int rowIndex)Returns the height of the specified row, or 0 if the table layout has not been validated.floatgetRowMinHeight(int rowIndex)Returns the min height of the specified row.floatgetRowPrefHeight(int rowIndex)Returns the pref height of the specified row.intgetRows()SkingetSkin()Table.DebuggetTableDebug()Actorhit(float x, float y, boolean touchable)If this method is overridden, the super method orWidgetGroup.validate()should be called to ensure the widget group is laid out.voidinvalidate()Invalidates this actor's layout, causingLayout.layout()to happen the next timeLayout.validate()is called.voidlayout()Positions and sizes children of the table using the cell associated with each child.Tableleft()AddsAlign.leftand clearsAlign.rightfor the alignment of the logical table within the table actor.Tablepad(float pad)Sets the padTop, padLeft, padBottom, and padRight around the table to the specified value.Tablepad(float top, float left, float bottom, float right)Tablepad(Value pad)Sets the padTop, padLeft, padBottom, and padRight around the table to the specified value.Tablepad(Value top, Value left, Value bottom, Value right)TablepadBottom(float padBottom)Padding at the bottom edge of the table.TablepadBottom(Value padBottom)Padding at the bottom edge of the table.TablepadLeft(float padLeft)Padding at the left edge of the table.TablepadLeft(Value padLeft)Padding at the left edge of the table.TablepadRight(float padRight)Padding at the right edge of the table.TablepadRight(Value padRight)Padding at the right edge of the table.TablepadTop(float padTop)Padding at the top edge of the table.TablepadTop(Value padTop)Padding at the top edge of the table.booleanremoveActor(Actor actor)Removes an actor from this group and unfocuses it.booleanremoveActor(Actor actor, boolean unfocus)Removes an actor from this group.ActorremoveActorAt(int index, boolean unfocus)Removes an actor from this group.voidreset()Removes all actors and cells from the table (same asGroup.clearChildren()) and additionally resets all table properties and cell, column, and row defaults.Tableright()AddsAlign.rightand clearsAlign.leftfor the alignment of the logical table within the table actor.Cellrow()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.voidsetBackground(Drawable background)voidsetBackground(java.lang.String drawableName)Sets the background drawable from the skin and adjusts the table's padding to match the background.voidsetClip(boolean enabled)Causes the contents to be clipped if they exceed the table's bounds.voidsetDebug(boolean enabled)If true,Actor.drawDebug(ShapeRenderer)will be called for this actor.voidsetRound(boolean round)If true (the default), positions and sizes of child actors are rounded and ceiled to the nearest integer value.voidsetSkin(Skin skin)Cell<Stack>stack(Actor... actors)Adds a new cell to the table with the specified actors in aStack.Tabletop()AddsAlign.topand clearsAlign.bottomfor the alignment of the logical table within the table actor.-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
childrenChanged, getMaxHeight, getMaxWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Group
act, addActor, addActorAfter, addActorAt, addActorBefore, applyTransform, applyTransform, clear, clear, clearChildren, computeTransform, drawChildren, drawDebugChildren, findActor, getChild, getChildren, getCullingArea, hasChildren, isTransform, localToDescendantCoordinates, resetTransform, resetTransform, setCullingArea, setDebug, setStage, setTransform, swapActor, swapActor, toString
-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
-
-
-
-
Field Detail
-
debugTableColor
public static Color debugTableColor
-
debugCellColor
public static Color debugCellColor
-
debugActorColor
public static Color debugActorColor
-
backgroundTop
public static Value backgroundTop
Value that is the top padding of the table's background.
-
backgroundLeft
public static Value backgroundLeft
Value that is the left padding of the table's background.
-
backgroundBottom
public static Value backgroundBottom
Value that is the bottom padding of the table's background.
-
backgroundRight
public static Value backgroundRight
Value that is the right padding of the table's background.
-
-
Constructor Detail
-
Table
public Table()
-
Table
public Table(@Null Skin skin)
Creates a table with a skin, which is required to useadd(CharSequence)oradd(CharSequence, String).
-
-
Method Detail
-
draw
public void draw(Batch batch, float parentAlpha)
Description copied from class:WidgetGroupIf this method is overridden, the super method orWidgetGroup.validate()should be called to ensure the widget group is laid out.- Overrides:
drawin classWidgetGroupparentAlpha- The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.
-
drawBackground
protected void drawBackground(Batch batch, float parentAlpha, float x, float y)
Called to draw the background, before clipping is applied (if enabled). Default implementation draws the background drawable.
-
setBackground
public void setBackground(java.lang.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 a skin has been set withTable(Skin)orsetSkin(Skin).- See Also:
setBackground(Drawable)
-
setBackground
public void setBackground(@Null Drawable background)
- Parameters:
background- May be null to clear the background.
-
background
public Table background(@Null Drawable background)
- See Also:
setBackground(Drawable)
-
background
public Table background(java.lang.String drawableName)
- See Also:
setBackground(String)
-
hit
@Null public Actor hit(float x, float y, boolean touchable)
Description copied from class:WidgetGroupIf this method is overridden, the super method orWidgetGroup.validate()should be called to ensure the widget group is laid out.- Overrides:
hitin classWidgetGrouptouchable- If true, hit detection will respect thetouchability.- See Also:
Touchable
-
clip
public Table clip()
SetssetClip(boolean)to true.
-
clip
public Table clip(boolean enabled)
-
setClip
public void setClip(boolean enabled)
Causes the contents to be clipped if they exceed the table's bounds. Enabling clipping setsGroup.setTransform(boolean)to true.
-
getClip
public boolean getClip()
-
invalidate
public void invalidate()
Description copied from interface:LayoutInvalidates this actor's layout, causingLayout.layout()to happen the next timeLayout.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:
invalidatein interfaceLayout- Overrides:
invalidatein classWidgetGroup
-
add
public <T extends Actor> Cell<T> add(@Null T actor)
Adds a new cell to the table with the specified actor.
-
add
public Cell<Label> add(@Null java.lang.CharSequence text)
Adds a new cell with a label. This may only be called if a skin has been set withTable(Skin)orsetSkin(Skin).
-
add
public Cell<Label> add(@Null java.lang.CharSequence text, java.lang.String labelStyleName)
Adds a new cell with a label. This may only be called if a skin has been set withTable(Skin)orsetSkin(Skin).
-
add
public Cell<Label> add(@Null java.lang.CharSequence text, java.lang.String fontName, @Null Color color)
Adds a new cell with a label. This may only be called if a skin has been set withTable(Skin)orsetSkin(Skin).
-
add
public Cell<Label> add(@Null java.lang.CharSequence text, java.lang.String fontName, java.lang.String colorName)
Adds a new cell with a label. This may only be called if a skin has been set withTable(Skin)orsetSkin(Skin).
-
add
public Cell add()
Adds a cell without an actor.
-
stack
public Cell<Stack> stack(@Null Actor... actors)
Adds a new cell to the table with the specified actors in aStack.- Parameters:
actors- May be null or empty to add a stack without any actors.
-
removeActor
public boolean removeActor(Actor actor)
Description copied from class:GroupRemoves an actor from this group and unfocuses it. CallsGroup.removeActor(Actor, boolean)with true.- Overrides:
removeActorin classGroup
-
removeActor
public boolean removeActor(Actor actor, boolean unfocus)
Description copied from class:GroupRemoves an actor from this group. CallsGroup.removeActorAt(int, boolean)with the actor's child index.- Overrides:
removeActorin classGroup
-
removeActorAt
public Actor removeActorAt(int index, boolean unfocus)
Description copied from class:GroupRemoves an actor from this group. If the actor will not be used again and has actions, they should beclearedso the actions will be returned to theirpool, if any. This is not done automatically.- Overrides:
removeActorAtin classGroupunfocus- If true,Stage.unfocus(Actor)is called.- Returns:
- the actor removed from this group.
-
clearChildren
public void clearChildren(boolean unfocus)
Removes all actors and cells from the table.- Overrides:
clearChildrenin classGroup
-
reset
public void reset()
Removes all actors and cells from the table (same asGroup.clearChildren()) and additionally resets all table properties and cell, column, and row defaults.
-
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.
-
getCell
@Null public <T extends Actor> Cell<T> getCell(T actor)
Returns the cell for the specified actor in this table, or null.
-
getPrefWidth
public float getPrefWidth()
- Specified by:
getPrefWidthin interfaceLayout- Overrides:
getPrefWidthin classWidgetGroup
-
getPrefHeight
public float getPrefHeight()
- Specified by:
getPrefHeightin interfaceLayout- Overrides:
getPrefHeightin classWidgetGroup
-
getMinWidth
public float getMinWidth()
- Specified by:
getMinWidthin interfaceLayout- Overrides:
getMinWidthin classWidgetGroup
-
getMinHeight
public float getMinHeight()
- Specified by:
getMinHeightin interfaceLayout- Overrides:
getMinHeightin classWidgetGroup
-
defaults
public Cell defaults()
The cell values that will be used as the defaults for all cells.
-
pad
public Table pad(Value pad)
Sets the padTop, padLeft, padBottom, and padRight around the table to the specified value.
-
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)
Alignment of the logical table within the table actor. Set toAlign.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 actor toAlign.center. This clears any other alignment.
-
top
public Table top()
AddsAlign.topand clearsAlign.bottomfor the alignment of the logical table within the table actor.
-
left
public Table left()
AddsAlign.leftand clearsAlign.rightfor the alignment of the logical table within the table actor.
-
bottom
public Table bottom()
AddsAlign.bottomand clearsAlign.topfor the alignment of the logical table within the table actor.
-
right
public Table right()
AddsAlign.rightand clearsAlign.leftfor the alignment of the logical table within the table actor.
-
setDebug
public void setDebug(boolean enabled)
Description copied from class:ActorIf true,Actor.drawDebug(ShapeRenderer)will be called for this actor.
-
debug
public Table debug()
Description copied from class:ActorCallsActor.setDebug(boolean)withtrue.
-
debugAll
public Table debugAll()
Description copied from class:GroupCallsGroup.setDebug(boolean, boolean)withtrue, true.
-
debugTable
public Table debugTable()
Turns on table debug lines.
-
debugCell
public Table debugCell()
Turns on cell debug lines.
-
debugActor
public Table debugActor()
Turns on actor debug lines.
-
debug
public Table debug(Table.Debug debug)
Turns debug lines on or off.
-
getTableDebug
public Table.Debug getTableDebug()
-
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()
ReturnsgetPadLeft()plusgetPadRight().
-
getPadY
public float getPadY()
ReturnsgetPadTop()plusgetPadBottom().
-
getAlign
public int getAlign()
-
getRow
public int getRow(float y)
Returns the row index for the y coordinate, or -1 if not over a row.- Parameters:
y- The y coordinate, where 0 is the top of the table.
-
setRound
public void setRound(boolean round)
If true (the default), positions and sizes of child actors are rounded and ceiled to the nearest integer value.
-
getRows
public int getRows()
-
getColumns
public int getColumns()
-
getRowHeight
public float getRowHeight(int rowIndex)
Returns the height of the specified row, or 0 if the table layout has not been validated.
-
getRowMinHeight
public float getRowMinHeight(int rowIndex)
Returns the min height of the specified row.
-
getRowPrefHeight
public float getRowPrefHeight(int rowIndex)
Returns the pref height of the specified row.
-
getColumnWidth
public float getColumnWidth(int columnIndex)
Returns the width of the specified column, or 0 if the table layout has not been validated.
-
getColumnMinWidth
public float getColumnMinWidth(int columnIndex)
Returns the min height of the specified column.
-
getColumnPrefWidth
public float getColumnPrefWidth(int columnIndex)
Returns the pref height of the specified column.
-
layout
public void layout()
Positions and sizes children of the table using the cell associated with each child. The values given are the position within the parent and size of the table.- Specified by:
layoutin interfaceLayout- Overrides:
layoutin classWidgetGroup
-
drawDebug
public void drawDebug(ShapeRenderer shapes)
Description copied from class:GroupDraws this actor's debug lines ifActor.getDebug()is true and, regardless ofActor.getDebug(), callsActor.drawDebug(ShapeRenderer)on each child.
-
drawDebugBounds
protected void drawDebugBounds(ShapeRenderer shapes)
Description copied from class:ActorDraws a rectangle for the bounds of this actor ifActor.getDebug()is true.- Overrides:
drawDebugBoundsin classActor
-
-