Class HorizontalGroup

All Implemented Interfaces:
Cullable, Layout

public class HorizontalGroup extends WidgetGroup
A group that lays out its children side by side horizontally, with optional wrapping. This can be easier than using Table when actors need to be inserted into or removed from the middle of the group. Group.getChildren() can be sorted to change the order of the actors (eg Actor.setZIndex(int)). invalidate() must be called after changing the children order.

The preferred width is the sum of the children's preferred widths plus spacing. The preferred height is the largest preferred height of any child. The preferred size is slightly different when wrap is enabled. The min size is the preferred size and the max size is 0.

Widgets are sized using their preferred width, so widgets which return 0 as their preferred width will be given a width of 0 (eg, a label with word wrap enabled).

Author:
Nathan Sweet
  • Constructor Details

    • HorizontalGroup

      public HorizontalGroup()
  • Method Details

    • 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
    • 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
    • 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
    • getRows

      public int getRows()
      When wrapping is enabled, the number of rows may be > 1.
    • setRound

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

      public HorizontalGroup reverse()
      The children will be displayed last to first.
    • reverse

      public HorizontalGroup reverse(boolean reverse)
      If true, the children will be displayed last to first.
    • getReverse

      public boolean getReverse()
    • wrapReverse

      public HorizontalGroup wrapReverse()
      Rows will wrap above the previous rows.
    • wrapReverse

      public HorizontalGroup wrapReverse(boolean wrapReverse)
      If true, rows will wrap above the previous rows.
    • getWrapReverse

      public boolean getWrapReverse()
    • space

      public HorizontalGroup space(float space)
      Sets the horizontal space between children.
    • getSpace

      public float getSpace()
    • wrapSpace

      public HorizontalGroup wrapSpace(float wrapSpace)
      Sets the vertical space between rows when wrap is enabled.
    • getWrapSpace

      public float getWrapSpace()
    • pad

      public HorizontalGroup pad(float pad)
      Sets the padTop, padLeft, padBottom, and padRight to the specified value.
    • pad

      public HorizontalGroup pad(float top, float left, float bottom, float right)
    • padTop

      public HorizontalGroup padTop(float padTop)
    • padLeft

      public HorizontalGroup padLeft(float padLeft)
    • padBottom

      public HorizontalGroup padBottom(float padBottom)
    • padRight

      public HorizontalGroup padRight(float padRight)
    • getPadTop

      public float getPadTop()
    • getPadLeft

      public float getPadLeft()
    • getPadBottom

      public float getPadBottom()
    • getPadRight

      public float getPadRight()
    • align

      public HorizontalGroup align(int align)
      Sets the alignment of all widgets within the horizontal group. Set to Align.center, Align.top, Align.bottom, Align.left, Align.right, or any combination of those.
    • center

      public HorizontalGroup center()
      Sets the alignment of all widgets within the horizontal group to Align.center. This clears any other alignment.
    • top

      public HorizontalGroup top()
      Sets Align.top and clears Align.bottom for the alignment of all widgets within the horizontal group.
    • left

      public HorizontalGroup left()
      Adds Align.left and clears Align.right for the alignment of all widgets within the horizontal group.
    • bottom

      public HorizontalGroup bottom()
      Sets Align.bottom and clears Align.top for the alignment of all widgets within the horizontal group.
    • right

      public HorizontalGroup right()
      Adds Align.right and clears Align.left for the alignment of all widgets within the horizontal group.
    • getAlign

      public int getAlign()
    • fill

      public HorizontalGroup fill()
    • fill

      public HorizontalGroup fill(float fill)
      Parameters:
      fill - 0 will use preferred width.
    • getFill

      public float getFill()
    • expand

      public HorizontalGroup expand()
    • expand

      public HorizontalGroup expand(boolean expand)
      When true and wrap is false, the rows will take up the entire horizontal group height.
    • getExpand

      public boolean getExpand()
    • grow

      public HorizontalGroup grow()
      Sets fill to 1 and expand to true.
    • wrap

      public HorizontalGroup wrap()
      If false, the widgets are arranged in a single row and the preferred width is the widget widths plus spacing.

      If true, the widgets will wrap using the width of the horizontal group. The preferred width of the group will be 0 as it is expected that something external will set the width of the group. Widgets are sized to their preferred width unless it is larger than the group's width, in which case they are sized to the group's width but not less than their minimum width. Default is false.

      When wrap is enabled, the group's preferred height depends on the width of the group. In some cases the parent of the group will need to layout twice: once to set the width of the group and a second time to adjust to the group's new preferred height.

    • wrap

      public HorizontalGroup wrap(boolean wrap)
    • getWrap

      public boolean getWrap()
    • rowAlign

      public HorizontalGroup rowAlign(int rowAlign)
      Sets the horizontal alignment of each row of widgets when wrapping is enabled and sets the vertical alignment of widgets within each row. Set to Align.center, Align.top, Align.bottom, Align.left, Align.right, or any combination of those.
    • rowCenter

      public HorizontalGroup rowCenter()
      Sets the alignment of widgets within each row to Align.center. This clears any other alignment.
    • rowTop

      public HorizontalGroup rowTop()
      Sets Align.top and clears Align.bottom for the alignment of widgets within each row.
    • rowLeft

      public HorizontalGroup rowLeft()
      Adds Align.left and clears Align.right for the alignment of each row of widgets when wrapping is enabled.
    • rowBottom

      public HorizontalGroup rowBottom()
      Sets Align.bottom and clears Align.top for the alignment of widgets within each row.
    • rowRight

      public HorizontalGroup rowRight()
      Adds Align.right and clears Align.left for the alignment of each row of widgets when wrapping is enabled.