Class Container<T extends Actor>

All Implemented Interfaces:
Cullable, Layout

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 a Table with a single cell but is more lightweight.
Author:
Nathan Sweet
  • Constructor Details

    • Container

      public Container()
      Creates a container with no actor.
    • Container

      public Container(@Null T actor)
  • Method Details

    • 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 - The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.
    • setBackground

      public void setBackground(@Null Drawable background)
      Sets the background drawable and adjusts the container's padding to match the background.
      See Also:
    • setBackground

      public void setBackground(@Null Drawable background, boolean adjustPadding)
      Sets the background drawable and, if adjustPadding is true, sets the container'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 Container<T> background(@Null Drawable background)
      See Also:
    • getBackground

      @Null public Drawable getBackground()
    • 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() on 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
    • 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 interface Cullable
      Overrides:
      setCullingArea in class Group
      Parameters:
      cullingArea - May be null.
    • setActor

      public void setActor(@Null T actor)
      Parameters:
      actor - May be null.
    • getActor

      @Null public T getActor()
      Returns:
      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 class Group
      See Also:
    • 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 class Group
      Parameters:
      index - May be greater than the number of children.
      See Also:
    • 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 class Group
      See Also:
    • 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. If actorAfter is not in this group, the actor is added as the last child.
      Overrides:
      addActorAfter in class Group
      See Also:
    • removeActor

      public boolean removeActor(Actor actor)
      Description copied from class: Group
      Removes an actor from this group and unfocuses it. Calls Group.removeActor(Actor, boolean) with true.
      Overrides:
      removeActor in class Group
    • removeActor

      public boolean removeActor(Actor actor, boolean unfocus)
      Description copied from class: Group
      Removes an actor from this group. Calls Group.removeActorAt(int, boolean) with the actor's child index.
      Overrides:
      removeActor in class Group
    • 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 be cleared so the actions will be returned to their pool, if any. This is not done automatically.
      Overrides:
      removeActorAt in class Group
      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.
    • minWidth

      public Container<T> minWidth(Value minWidth)
    • minHeight

      public Container<T> minHeight(Value minHeight)
    • 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.
    • minWidth

      public Container<T> minWidth(float minWidth)
    • minHeight

      public Container<T> minHeight(float minHeight)
    • 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.
    • prefWidth

      public Container<T> prefWidth(Value prefWidth)
    • prefHeight

      public Container<T> prefHeight(Value prefHeight)
    • 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.
    • prefWidth

      public Container<T> prefWidth(float prefWidth)
    • prefHeight

      public Container<T> prefHeight(float prefHeight)
    • 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.
    • maxWidth

      public Container<T> maxWidth(Value maxWidth)
    • maxHeight

      public Container<T> maxHeight(Value maxHeight)
    • 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.
    • maxWidth

      public Container<T> maxWidth(float maxWidth)
    • maxHeight

      public Container<T> maxHeight(float maxHeight)
    • pad

      public Container<T> pad(Value pad)
      Sets the padTop, padLeft, padBottom, and padRight to the specified value.
    • pad

      public Container<T> pad(Value top, Value left, Value bottom, Value right)
    • padTop

      public Container<T> padTop(Value padTop)
    • padLeft

      public Container<T> padLeft(Value padLeft)
    • padBottom

      public Container<T> padBottom(Value padBottom)
    • padRight

      public Container<T> padRight(Value padRight)
    • pad

      public Container<T> pad(float pad)
      Sets the padTop, padLeft, padBottom, and padRight to the specified value.
    • pad

      public Container<T> pad(float top, float left, float bottom, float right)
    • padTop

      public Container<T> padTop(float padTop)
    • padLeft

      public Container<T> padLeft(float padLeft)
    • padBottom

      public Container<T> padBottom(float padBottom)
    • padRight

      public Container<T> padRight(float padRight)
    • fill

      public Container<T> fill()
      Sets fillX and fillY to 1.
    • fillX

      public Container<T> fillX()
      Sets fillX to 1.
    • fillY

      public Container<T> fillY()
      Sets fillY to 1.
    • fill

      public Container<T> fill(float x, float y)
    • fill

      public Container<T> fill(boolean x, boolean y)
      Sets fillX and fillY to 1 if true, 0 if false.
    • fill

      public Container<T> fill(boolean fill)
      Sets fillX and fillY to 1 if true, 0 if false.
    • align

      public Container<T> align(int align)
      Sets the alignment of the actor within the container. Set to Align.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 to Align.center. This clears any other alignment.
    • top

      public Container<T> top()
      Sets Align.top and clears Align.bottom for the alignment of the actor within the container.
    • left

      public Container<T> left()
      Sets Align.left and clears Align.right for the alignment of the actor within the container.
    • bottom

      public Container<T> bottom()
      Sets Align.bottom and clears Align.top for the alignment of the actor within the container.
    • right

      public Container<T> right()
      Sets Align.right and clears Align.left for the alignment of the actor within the container.
    • getMinWidth

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

      public Value getMinHeightValue()
      Overrides:
      getMinHeightValue in class WidgetGroup
    • getMinHeight

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

      public Value getPrefWidthValue()
      Overrides:
      getPrefWidthValue in class WidgetGroup
    • getPrefWidth

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

      public Value getPrefHeightValue()
      Overrides:
      getPrefHeightValue in class WidgetGroup
    • getPrefHeight

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

      public Value getMaxWidthValue()
      Overrides:
      getMaxWidthValue in class WidgetGroup
    • getMaxWidth

      public float getMaxWidth()
      Description copied from interface: Layout
      Zero indicates no max width.
      Specified by:
      getMaxWidth in interface Layout
      Overrides:
      getMaxWidth in class WidgetGroup
    • getMaxHeightValue

      public Value getMaxHeightValue()
      Overrides:
      getMaxHeightValue in class WidgetGroup
    • getMaxHeight

      public float getMaxHeight()
      Description copied from interface: Layout
      Zero indicates no max height.
      Specified by:
      getMaxHeight in interface Layout
      Overrides:
      getMaxHeight in class WidgetGroup
    • 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()
    • getPadY

      public float getPadY()
    • 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.
    • clip

      public Container<T> clip()
      Sets clip to true.
    • clip

      public Container<T> clip(boolean enabled)
    • setClip

      public void setClip(boolean enabled)
      Causes the contents to be clipped if they exceed the container bounds. Enabling clipping will set Group.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 or WidgetGroup.validate() should be called to ensure the widget group is laid out.
      Overrides:
      hit in class WidgetGroup
      touchable - If true, hit detection will respect the touchability.
      See Also:
    • drawDebug

      public void drawDebug(ShapeRenderer shapes)
      Description copied from class: Group
      Draws this actor's debug lines if Actor.getDebug() is true and, regardless of Actor.getDebug(), calls Actor.drawDebug(ShapeRenderer) on each child.
      Overrides:
      drawDebug in class Group