Class Container<T extends Actor>
- 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.Container<T>
-
public class Container<T extends Actor> extends WidgetGroup
A group with a single child that sizes and positions the child using constraints. This provides layout similar to aTable
with a single cell but is more lightweight.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addActor(Actor actor)
Deprecated.Container may have only a single child.void
addActorAfter(Actor actorAfter, Actor actor)
Deprecated.Container may have only a single child.void
addActorAt(int index, Actor actor)
Deprecated.Container may have only a single child.void
addActorBefore(Actor actorBefore, Actor actor)
Deprecated.Container may have only a single child.Container<T>
align(int align)
Sets the alignment of the actor within the container.Container<T>
background(Drawable background)
Container<T>
bottom()
SetsAlign.bottom
and clearsAlign.top
for the alignment of the actor within the container.Container<T>
center()
Sets the alignment of the actor within the container toAlign.center
.Container<T>
clip()
Sets clip to true.Container<T>
clip(boolean enabled)
void
draw(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 void
drawBackground(Batch batch, float parentAlpha, float x, float y)
Called to draw the background, before clipping is applied (if enabled).void
drawDebug(ShapeRenderer shapes)
Draws this actor's debug lines ifActor.getDebug()
is true and, regardless ofActor.getDebug()
, callsActor.drawDebug(ShapeRenderer)
on each child.Container<T>
fill()
Sets fillX and fillY to 1.Container<T>
fill(boolean fill)
Sets fillX and fillY to 1 if true, 0 if false.Container<T>
fill(boolean x, boolean y)
Sets fillX and fillY to 1 if true, 0 if false.Container<T>
fill(float x, float y)
Container<T>
fillX()
Sets fillX to 1.Container<T>
fillY()
Sets fillY to 1.T
getActor()
int
getAlign()
Drawable
getBackground()
boolean
getClip()
float
getFillX()
float
getFillY()
float
getMaxHeight()
Zero indicates no max height.Value
getMaxHeightValue()
float
getMaxWidth()
Zero indicates no max width.Value
getMaxWidthValue()
float
getMinHeight()
Value
getMinHeightValue()
float
getMinWidth()
float
getPadBottom()
Value
getPadBottomValue()
float
getPadLeft()
Value
getPadLeftValue()
float
getPadRight()
Value
getPadRightValue()
float
getPadTop()
Value
getPadTopValue()
float
getPadX()
ReturnsgetPadLeft()
plusgetPadRight()
.float
getPadY()
ReturnsgetPadTop()
plusgetPadBottom()
.float
getPrefHeight()
Value
getPrefHeightValue()
float
getPrefWidth()
Value
getPrefWidthValue()
Container<T>
height(float height)
Sets the minHeight, prefHeight, and maxHeight to the specified value.Container<T>
height(Value height)
Sets the minHeight, prefHeight, and maxHeight to the specified value.Actor
hit(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.void
layout()
Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsLayout.invalidate()
on any each child whose width or height has changed, and callsLayout.validate()
on each child.Container<T>
left()
SetsAlign.left
and clearsAlign.right
for the alignment of the actor within the container.Container<T>
maxHeight(float maxHeight)
Container<T>
maxHeight(Value maxHeight)
Container<T>
maxSize(float size)
Sets the maxWidth and maxHeight to the specified value.Container<T>
maxSize(float width, float height)
Sets the maxWidth and maxHeight to the specified values.Container<T>
maxSize(Value size)
Sets the maxWidth and maxHeight to the specified value.Container<T>
maxSize(Value width, Value height)
Sets the maxWidth and maxHeight to the specified values.Container<T>
maxWidth(float maxWidth)
Container<T>
maxWidth(Value maxWidth)
Container<T>
minHeight(float minHeight)
Container<T>
minHeight(Value minHeight)
Container<T>
minSize(float size)
Sets the minWidth and minHeight to the specified value.Container<T>
minSize(float width, float height)
Sets the minWidth and minHeight to the specified values.Container<T>
minSize(Value size)
Sets the minWidth and minHeight to the specified value.Container<T>
minSize(Value width, Value height)
Sets the minWidth and minHeight to the specified values.Container<T>
minWidth(float minWidth)
Container<T>
minWidth(Value minWidth)
Container<T>
pad(float pad)
Sets the padTop, padLeft, padBottom, and padRight to the specified value.Container<T>
pad(float top, float left, float bottom, float right)
Container<T>
pad(Value pad)
Sets the padTop, padLeft, padBottom, and padRight to the specified value.Container<T>
pad(Value top, Value left, Value bottom, Value right)
Container<T>
padBottom(float padBottom)
Container<T>
padBottom(Value padBottom)
Container<T>
padLeft(float padLeft)
Container<T>
padLeft(Value padLeft)
Container<T>
padRight(float padRight)
Container<T>
padRight(Value padRight)
Container<T>
padTop(float padTop)
Container<T>
padTop(Value padTop)
Container<T>
prefHeight(float prefHeight)
Container<T>
prefHeight(Value prefHeight)
Container<T>
prefSize(float size)
Sets the prefWidth and prefHeight to the specified values.Container<T>
prefSize(float width, float height)
Sets the prefWidth and prefHeight to the specified value.Container<T>
prefSize(Value size)
Sets the prefWidth and prefHeight to the specified value.Container<T>
prefSize(Value width, Value height)
Sets the prefWidth and prefHeight to the specified values.Container<T>
prefWidth(float prefWidth)
Container<T>
prefWidth(Value prefWidth)
boolean
removeActor(Actor actor)
Removes an actor from this group and unfocuses it.boolean
removeActor(Actor actor, boolean unfocus)
Removes an actor from this group.Actor
removeActorAt(int index, boolean unfocus)
Removes an actor from this group.Container<T>
right()
SetsAlign.right
and clearsAlign.left
for the alignment of the actor within the container.void
setActor(T actor)
void
setBackground(Drawable background)
Sets the background drawable and adjusts the container's padding to match the background.void
setBackground(Drawable background, boolean adjustPadding)
Sets the background drawable and, if adjustPadding is true, sets the container's padding toDrawable.getBottomHeight()
,Drawable.getTopHeight()
,Drawable.getLeftWidth()
, andDrawable.getRightWidth()
.void
setClip(boolean enabled)
Causes the contents to be clipped if they exceed the container bounds.void
setCullingArea(Rectangle cullingArea)
Children completely outside of this rectangle will not be drawn.void
setRound(boolean round)
If true (the default), positions and sizes are rounded to integers.Container<T>
size(float size)
Sets the minWidth, prefWidth, maxWidth, minHeight, prefHeight, and maxHeight to the specified value.Container<T>
size(float width, float height)
Sets the minWidth, prefWidth, maxWidth, minHeight, prefHeight, and maxHeight to the specified values.Container<T>
size(Value size)
Sets the minWidth, prefWidth, maxWidth, minHeight, prefHeight, and maxHeight to the specified value.Container<T>
size(Value width, Value height)
Sets the minWidth, prefWidth, maxWidth, minHeight, prefHeight, and maxHeight to the specified values.Container<T>
top()
SetsAlign.top
and clearsAlign.bottom
for the alignment of the actor within the container.Container<T>
width(float width)
Sets the minWidth, prefWidth, and maxWidth to the specified value.Container<T>
width(Value width)
Sets the minWidth, prefWidth, and maxWidth to the specified value.-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
childrenChanged, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Group
act, applyTransform, applyTransform, clear, clear, clearChildren, clearChildren, computeTransform, debugAll, drawChildren, drawDebugChildren, findActor, getChild, getChildren, getCullingArea, hasChildren, isTransform, localToDescendantCoordinates, resetTransform, resetTransform, 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, debug, drawDebugBounds, 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, setDebug, 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
-
-
-
-
Method Detail
-
draw
public void draw(Batch batch, float parentAlpha)
Description copied from class:WidgetGroup
If this method is overridden, the super method orWidgetGroup.validate()
should be called to ensure the widget group is laid out.- Overrides:
draw
in classWidgetGroup
parentAlpha
- 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(@Null Drawable background)
Sets the background drawable and adjusts the container's padding to match the background.- See Also:
setBackground(Drawable, boolean)
-
setBackground
public void setBackground(@Null Drawable background, boolean adjustPadding)
Sets the background drawable and, if adjustPadding is true, sets the container's padding toDrawable.getBottomHeight()
,Drawable.getTopHeight()
,Drawable.getLeftWidth()
, andDrawable.getRightWidth()
.- Parameters:
background
- If null, the background will be cleared and padding removed.
-
background
public Container<T> background(@Null Drawable background)
- See Also:
setBackground(Drawable)
-
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, callsLayout.invalidate()
on any each child whose width or height has changed, and callsLayout.validate()
on each child. This method should almost never be called directly, insteadLayout.validate()
should be used.- Specified by:
layout
in interfaceLayout
- Overrides:
layout
in classWidgetGroup
-
setCullingArea
public void setCullingArea(Rectangle cullingArea)
Description copied from class:Group
Children completely outside of this rectangle will not be drawn. This is only valid for use with unrotated and unscaled actors.- Specified by:
setCullingArea
in interfaceCullable
- Overrides:
setCullingArea
in classGroup
- Parameters:
cullingArea
- May be null.
-
addActor
@Deprecated public void addActor(Actor actor)
Deprecated.Container may have only a single child.Description copied from class:Group
Adds an actor as a child of this group, removing it from its previous parent. If the actor is already a child of this group, no changes are made.- Overrides:
addActor
in classGroup
- See Also:
setActor(Actor)
-
addActorAt
@Deprecated public void addActorAt(int index, Actor actor)
Deprecated.Container may have only a single child.Description copied from class:Group
Adds an actor as a child of this group at a specific index, removing it from its previous parent. If the actor is already a child of this group, no changes are made.- Overrides:
addActorAt
in classGroup
- Parameters:
index
- May be greater than the number of children.- See Also:
setActor(Actor)
-
addActorBefore
@Deprecated public void addActorBefore(Actor actorBefore, Actor actor)
Deprecated.Container may have only a single child.Description copied from class:Group
Adds an actor as a child of this group immediately before another child actor, removing it from its previous parent. If the actor is already a child of this group, no changes are made.- Overrides:
addActorBefore
in classGroup
- See Also:
setActor(Actor)
-
addActorAfter
@Deprecated public void addActorAfter(Actor actorAfter, Actor actor)
Deprecated.Container may have only a single child.Description copied from class:Group
Adds an actor as a child of this group immediately after another child actor, removing it from its previous parent. If the actor is already a child of this group, no changes are made. IfactorAfter
is not in this group, the actor is added as the last child.- Overrides:
addActorAfter
in classGroup
- See Also:
setActor(Actor)
-
removeActor
public boolean removeActor(Actor actor)
Description copied from class:Group
Removes an actor from this group and unfocuses it. CallsGroup.removeActor(Actor, boolean)
with true.- Overrides:
removeActor
in classGroup
-
removeActor
public boolean removeActor(Actor actor, boolean unfocus)
Description copied from class:Group
Removes an actor from this group. CallsGroup.removeActorAt(int, boolean)
with the actor's child index.- Overrides:
removeActor
in classGroup
-
removeActorAt
public Actor removeActorAt(int index, boolean unfocus)
Description copied from class:Group
Removes an actor from this group. If the actor will not be used again and has actions, they should becleared
so the actions will be returned to theirpool
, if any. This is not done automatically.- Overrides:
removeActorAt
in classGroup
unfocus
- If true,Stage.unfocus(Actor)
is called.- Returns:
- the actor removed from this group.
-
size
public Container<T> size(Value size)
Sets the minWidth, prefWidth, maxWidth, minHeight, prefHeight, and maxHeight to the specified value.
-
size
public Container<T> size(Value width, Value height)
Sets the minWidth, prefWidth, maxWidth, minHeight, prefHeight, and maxHeight to the specified values.
-
size
public Container<T> size(float size)
Sets the minWidth, prefWidth, maxWidth, minHeight, prefHeight, and maxHeight to the specified value.
-
size
public Container<T> size(float width, float height)
Sets the minWidth, prefWidth, maxWidth, minHeight, prefHeight, and maxHeight to the specified values.
-
width
public Container<T> width(Value width)
Sets the minWidth, prefWidth, and maxWidth to the specified value.
-
width
public Container<T> width(float width)
Sets the minWidth, prefWidth, and maxWidth to the specified value.
-
height
public Container<T> height(Value height)
Sets the minHeight, prefHeight, and maxHeight to the specified value.
-
height
public Container<T> height(float height)
Sets the minHeight, prefHeight, and maxHeight to the specified value.
-
minSize
public Container<T> minSize(Value size)
Sets the minWidth and minHeight to the specified value.
-
minSize
public Container<T> minSize(Value width, Value height)
Sets the minWidth and minHeight to the specified values.
-
minSize
public Container<T> minSize(float size)
Sets the minWidth and minHeight to the specified value.
-
minSize
public Container<T> minSize(float width, float height)
Sets the minWidth and minHeight to the specified values.
-
prefSize
public Container<T> prefSize(Value size)
Sets the prefWidth and prefHeight to the specified value.
-
prefSize
public Container<T> prefSize(Value width, Value height)
Sets the prefWidth and prefHeight to the specified values.
-
prefSize
public Container<T> prefSize(float width, float height)
Sets the prefWidth and prefHeight to the specified value.
-
prefSize
public Container<T> prefSize(float size)
Sets the prefWidth and prefHeight to the specified values.
-
maxSize
public Container<T> maxSize(Value size)
Sets the maxWidth and maxHeight to the specified value.
-
maxSize
public Container<T> maxSize(Value width, Value height)
Sets the maxWidth and maxHeight to the specified values.
-
maxSize
public Container<T> maxSize(float size)
Sets the maxWidth and maxHeight to the specified value.
-
maxSize
public Container<T> maxSize(float width, float height)
Sets the maxWidth and maxHeight to the specified values.
-
pad
public Container<T> pad(Value pad)
Sets the padTop, padLeft, padBottom, and padRight to the specified value.
-
pad
public Container<T> pad(float pad)
Sets the padTop, padLeft, padBottom, and padRight to the specified value.
-
align
public Container<T> align(int align)
Sets the alignment of the actor within the container. Set toAlign.center
,Align.top
,Align.bottom
,Align.left
,Align.right
, or any combination of those.
-
center
public Container<T> center()
Sets the alignment of the actor within the container toAlign.center
. This clears any other alignment.
-
top
public Container<T> top()
SetsAlign.top
and clearsAlign.bottom
for the alignment of the actor within the container.
-
left
public Container<T> left()
SetsAlign.left
and clearsAlign.right
for the alignment of the actor within the container.
-
bottom
public Container<T> bottom()
SetsAlign.bottom
and clearsAlign.top
for the alignment of the actor within the container.
-
right
public Container<T> right()
SetsAlign.right
and clearsAlign.left
for the alignment of the actor within the container.
-
getMinWidth
public float getMinWidth()
- Specified by:
getMinWidth
in interfaceLayout
- Overrides:
getMinWidth
in classWidgetGroup
-
getMinHeightValue
public Value getMinHeightValue()
-
getMinHeight
public float getMinHeight()
- Specified by:
getMinHeight
in interfaceLayout
- Overrides:
getMinHeight
in classWidgetGroup
-
getPrefWidthValue
public Value getPrefWidthValue()
-
getPrefWidth
public float getPrefWidth()
- Specified by:
getPrefWidth
in interfaceLayout
- Overrides:
getPrefWidth
in classWidgetGroup
-
getPrefHeightValue
public Value getPrefHeightValue()
-
getPrefHeight
public float getPrefHeight()
- Specified by:
getPrefHeight
in interfaceLayout
- Overrides:
getPrefHeight
in classWidgetGroup
-
getMaxWidthValue
public Value getMaxWidthValue()
-
getMaxWidth
public float getMaxWidth()
Description copied from interface:Layout
Zero indicates no max width.- Specified by:
getMaxWidth
in interfaceLayout
- Overrides:
getMaxWidth
in classWidgetGroup
-
getMaxHeightValue
public Value getMaxHeightValue()
-
getMaxHeight
public float getMaxHeight()
Description copied from interface:Layout
Zero indicates no max height.- Specified by:
getMaxHeight
in interfaceLayout
- Overrides:
getMaxHeight
in classWidgetGroup
-
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()
.
-
getFillX
public float getFillX()
-
getFillY
public float getFillY()
-
getAlign
public int getAlign()
-
setRound
public void setRound(boolean round)
If true (the default), positions and sizes are rounded to integers.
-
setClip
public void setClip(boolean enabled)
Causes the contents to be clipped if they exceed the container bounds. Enabling clipping will setGroup.setTransform(boolean)
to true.
-
getClip
public boolean getClip()
-
hit
@Null public Actor hit(float x, float y, boolean touchable)
Description copied from class:WidgetGroup
If this method is overridden, the super method orWidgetGroup.validate()
should be called to ensure the widget group is laid out.- Overrides:
hit
in classWidgetGroup
touchable
- If true, hit detection will respect thetouchability
.- See Also:
Touchable
-
drawDebug
public void drawDebug(ShapeRenderer shapes)
Description copied from class:Group
Draws this actor's debug lines ifActor.getDebug()
is true and, regardless ofActor.getDebug()
, callsActor.drawDebug(ShapeRenderer)
on each child.
-
-