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 aTablewith a single cell but is more lightweight.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddActor(Actor actor)Deprecated.Container may have only a single child.voidaddActorAfter(Actor actorAfter, Actor actor)Deprecated.Container may have only a single child.voidaddActorAt(int index, Actor actor)Deprecated.Container may have only a single child.voidaddActorBefore(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.bottomand clearsAlign.topfor 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)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.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.TgetActor()intgetAlign()DrawablegetBackground()booleangetClip()floatgetFillX()floatgetFillY()floatgetMaxHeight()Zero indicates no max height.ValuegetMaxHeightValue()floatgetMaxWidth()Zero indicates no max width.ValuegetMaxWidthValue()floatgetMinHeight()ValuegetMinHeightValue()floatgetMinWidth()floatgetPadBottom()ValuegetPadBottomValue()floatgetPadLeft()ValuegetPadLeftValue()floatgetPadRight()ValuegetPadRightValue()floatgetPadTop()ValuegetPadTopValue()floatgetPadX()ReturnsgetPadLeft()plusgetPadRight().floatgetPadY()ReturnsgetPadTop()plusgetPadBottom().floatgetPrefHeight()ValuegetPrefHeightValue()floatgetPrefWidth()ValuegetPrefWidthValue()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.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.voidlayout()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.leftand clearsAlign.rightfor 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)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.Container<T>right()SetsAlign.rightand clearsAlign.leftfor the alignment of the actor within the container.voidsetActor(T actor)voidsetBackground(Drawable background)Sets the background drawable and adjusts the container's padding to match the background.voidsetBackground(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().voidsetClip(boolean enabled)Causes the contents to be clipped if they exceed the container bounds.voidsetCullingArea(Rectangle cullingArea)Children completely outside of this rectangle will not be drawn.voidsetRound(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.topand clearsAlign.bottomfor 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: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(@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:LayoutComputes 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:
layoutin interfaceLayout- Overrides:
layoutin classWidgetGroup
-
setCullingArea
public void setCullingArea(Rectangle cullingArea)
Description copied from class:GroupChildren completely outside of this rectangle will not be drawn. This is only valid for use with unrotated and unscaled actors.- Specified by:
setCullingAreain interfaceCullable- Overrides:
setCullingAreain 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:GroupAdds 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:
addActorin 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:GroupAdds 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:
addActorAtin 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:GroupAdds 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:
addActorBeforein 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:GroupAdds 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. IfactorAfteris not in this group, the actor is added as the last child.- Overrides:
addActorAfterin classGroup- See Also:
setActor(Actor)
-
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.
-
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.topand clearsAlign.bottomfor the alignment of the actor within the container.
-
left
public Container<T> left()
SetsAlign.leftand clearsAlign.rightfor the alignment of the actor within the container.
-
bottom
public Container<T> bottom()
SetsAlign.bottomand clearsAlign.topfor the alignment of the actor within the container.
-
right
public Container<T> right()
SetsAlign.rightand clearsAlign.leftfor the alignment of the actor within the container.
-
getMinWidth
public float getMinWidth()
- Specified by:
getMinWidthin interfaceLayout- Overrides:
getMinWidthin classWidgetGroup
-
getMinHeightValue
public Value getMinHeightValue()
-
getMinHeight
public float getMinHeight()
- Specified by:
getMinHeightin interfaceLayout- Overrides:
getMinHeightin classWidgetGroup
-
getPrefWidthValue
public Value getPrefWidthValue()
-
getPrefWidth
public float getPrefWidth()
- Specified by:
getPrefWidthin interfaceLayout- Overrides:
getPrefWidthin classWidgetGroup
-
getPrefHeightValue
public Value getPrefHeightValue()
-
getPrefHeight
public float getPrefHeight()
- Specified by:
getPrefHeightin interfaceLayout- Overrides:
getPrefHeightin classWidgetGroup
-
getMaxWidthValue
public Value getMaxWidthValue()
-
getMaxWidth
public float getMaxWidth()
Description copied from interface:LayoutZero indicates no max width.- Specified by:
getMaxWidthin interfaceLayout- Overrides:
getMaxWidthin classWidgetGroup
-
getMaxHeightValue
public Value getMaxHeightValue()
-
getMaxHeight
public float getMaxHeight()
Description copied from interface:LayoutZero indicates no max height.- Specified by:
getMaxHeightin interfaceLayout- Overrides:
getMaxHeightin 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: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
-
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.
-
-