Class Widget
- java.lang.Object
-
- com.badlogic.gdx.scenes.scene2d.Actor
-
- com.badlogic.gdx.scenes.scene2d.ui.Widget
-
- All Implemented Interfaces:
Layout
public class Widget extends Actor implements Layout
AnActorthat participates in layout and provides a minimum, preferred, and maximum size.The default preferred size of a widget 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 if it wants to allow itself to be sized smaller. The default maximum size is 0, which means no maximum size.
See
Layoutfor details on how a widget should participate in layout. A widget's mutator methods should callinvalidate()orinvalidateHierarchy()as needed.
-
-
Constructor Summary
Constructors Constructor Description Widget()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddraw(Batch batch, float parentAlpha)If this method is overridden, the super method orvalidate()should be called to ensure the widget is laid out.floatgetMaxHeight()Zero indicates no max height.floatgetMaxWidth()Zero indicates no max width.floatgetMinHeight()floatgetMinWidth()floatgetPrefHeight()floatgetPrefWidth()voidinvalidate()Invalidates this actor's layout, causingLayout.layout()to happen the next timeLayout.validate()is called.voidinvalidateHierarchy()Invalidates this actor and its ascendants, callingLayout.invalidate()on each.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.booleanneedsLayout()Returns true if the widget's layout has beeninvalidated.voidpack()Sizes this actor to its preferred width and height, then callsLayout.validate().voidsetFillParent(boolean fillParent)If true, this actor will be sized to the parent inLayout.validate().voidsetLayoutEnabled(boolean enabled)Enables or disables the layout for this actor and all child actors, recursively.protected voidsizeChanged()Called when the actor's size has been changed.voidvalidate()Ensures the actor has been laid out.-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebug, 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, hit, 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, setStage, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront, toString
-
-
-
-
Method Detail
-
getMinWidth
public float getMinWidth()
- Specified by:
getMinWidthin interfaceLayout
-
getMinHeight
public float getMinHeight()
- Specified by:
getMinHeightin interfaceLayout
-
getPrefWidth
public float getPrefWidth()
- Specified by:
getPrefWidthin interfaceLayout
-
getPrefHeight
public float getPrefHeight()
- Specified by:
getPrefHeightin interfaceLayout
-
getMaxWidth
public float getMaxWidth()
Description copied from interface:LayoutZero indicates no max width.- Specified by:
getMaxWidthin interfaceLayout
-
getMaxHeight
public float getMaxHeight()
Description copied from interface:LayoutZero indicates no max height.- Specified by:
getMaxHeightin interfaceLayout
-
setLayoutEnabled
public void setLayoutEnabled(boolean enabled)
Description copied from interface:LayoutEnables 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:
setLayoutEnabledin interfaceLayout
-
validate
public void validate()
Description copied from interface:LayoutEnsures the actor has been laid out. CallsLayout.layout()ifLayout.invalidate()has been called since the last timeLayout.validate()was called, or if the actor otherwise needs to be laid out. This method is usually called inActor.draw(Batch, float)by the actor itself before drawing is performed.
-
needsLayout
public boolean needsLayout()
Returns true if the widget's layout has beeninvalidated.
-
invalidate
public void invalidate()
Description copied from interface:LayoutInvalidates this actor's layout, causingLayout.layout()to happen the next timeLayout.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:
invalidatein interfaceLayout
-
invalidateHierarchy
public void invalidateHierarchy()
Description copied from interface:LayoutInvalidates this actor and its ascendants, callingLayout.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:
invalidateHierarchyin interfaceLayout
-
sizeChanged
protected void sizeChanged()
Description copied from class:ActorCalled when the actor's size has been changed.- Overrides:
sizeChangedin classActor
-
pack
public void pack()
Description copied from interface:LayoutSizes this actor to its preferred width and height, then callsLayout.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 toLayout.getPrefWidth()andLayout.getPrefHeight(). This allows the actor to have a size at construction time for more convenient use with groups that do not layout their children.
-
setFillParent
public void setFillParent(boolean fillParent)
Description copied from interface:LayoutIf true, this actor will be sized to the parent inLayout.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:
setFillParentin interfaceLayout
-
draw
public void draw(Batch batch, float parentAlpha)
If this method is overridden, the super method orvalidate()should be called to ensure the widget is laid out.
-
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.
-
-