Class WidgetGroup

  • All Implemented Interfaces:
    Cullable, Layout
    Direct Known Subclasses:
    Container, HorizontalGroup, ScrollPane, SplitPane, Stack, Table, Tree, VerticalGroup

    public class WidgetGroup
    extends Group
    implements Layout
    A Group that participates in layout and provides a minimum, preferred, and maximum size.

    The default preferred size of a widget group is 0 and this is almost always overridden by a subclass. The default minimum size returns the preferred size, so a subclass may choose to return 0 for minimum size if it wants to allow itself to be sized smaller than the preferred size. The default maximum size is 0, which means no maximum size.

    See Layout for details on how a widget group should participate in layout. A widget group's mutator methods should call invalidate() or invalidateHierarchy() as needed. By default, invalidateHierarchy is called when child widgets are added and removed.

    • Constructor Detail

      • WidgetGroup

        public WidgetGroup()
      • WidgetGroup

        public WidgetGroup​(Actor... actors)
        Creates a new widget group containing the specified actors.
    • Method Detail

      • getMinWidth

        public float getMinWidth()
        Specified by:
        getMinWidth in interface Layout
      • getMinHeight

        public float getMinHeight()
        Specified by:
        getMinHeight in interface Layout
      • getPrefWidth

        public float getPrefWidth()
        Specified by:
        getPrefWidth in interface Layout
      • getPrefHeight

        public float getPrefHeight()
        Specified by:
        getPrefHeight in interface Layout
      • getMaxWidth

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

        public float getMaxHeight()
        Description copied from interface: Layout
        Zero indicates no max height.
        Specified by:
        getMaxHeight in interface Layout
      • setLayoutEnabled

        public void setLayoutEnabled​(boolean enabled)
        Description copied from interface: Layout
        Enables or disables the layout for this actor and all child actors, recursively. When false, Layout.validate() will not cause a layout to occur. This can be useful when an actor will be manipulated externally, such as with actions. Default is true.
        Specified by:
        setLayoutEnabled in interface Layout
      • needsLayout

        public boolean needsLayout()
        Returns true if the widget's layout has been invalidated.
      • 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
      • invalidateHierarchy

        public void invalidateHierarchy()
        Description copied from interface: Layout
        Invalidates this actor and its ascendants, calling Layout.invalidate() on each. This method should be called when state changes in the actor that affects the minimum, preferred, maximum, or actual size of the actor (meaning it potentially affects the parent actor's layout).
        Specified by:
        invalidateHierarchy in interface Layout
      • childrenChanged

        protected void childrenChanged()
        Description copied from class: Group
        Called when actors are added to or removed from the group.
        Overrides:
        childrenChanged in class Group
      • sizeChanged

        protected void sizeChanged()
        Description copied from class: Actor
        Called when the actor's size has been changed.
        Overrides:
        sizeChanged in class Actor
      • pack

        public void pack()
        Description copied from interface: Layout
        Sizes this actor to its preferred width and height, then calls Layout.validate().

        Generally this method should not be called in an actor's constructor because it calls Layout.layout(), which means a subclass would have layout() called before the subclass' constructor. Instead, in constructors simply set the actor's size to Layout.getPrefWidth() and Layout.getPrefHeight(). This allows the actor to have a size at construction time for more convenient use with groups that do not layout their children.

        Specified by:
        pack in interface Layout
      • setFillParent

        public void setFillParent​(boolean fillParent)
        Description copied from interface: Layout
        If true, this actor will be sized to the parent in Layout.validate(). If the parent is the stage, the actor will be sized to the stage. This method is for convenience only when the widget's parent does not set the size of its children (such as the stage).
        Specified by:
        setFillParent in interface Layout
      • 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
      • hit

        public Actor hit​(float x,
                         float y,
                         boolean touchable)
        If this method is overridden, the super method or validate() should be called to ensure the widget group is laid out.
        Overrides:
        hit in class Group
        touchable - If true, hit detection will respect the touchability.
        See Also:
        Touchable
      • draw

        public void draw​(Batch batch,
                         float parentAlpha)
        If this method is overridden, the super method or validate() should be called to ensure the widget group is laid out.
        Overrides:
        draw in class Group
        parentAlpha - The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.