Class Button
- 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.Table
-
- com.badlogic.gdx.scenes.scene2d.ui.Button
-
- All Implemented Interfaces:
Cullable
,Disableable
,Layout
- Direct Known Subclasses:
ImageButton
,ImageTextButton
,TextButton
public class Button extends Table implements Disableable
A button is aTable
with a checked state and additionalstyle
fields for pressed, unpressed, and checked. Each time a button is clicked, the checked state is toggled. Being a table, a button can contain any other actors.
The button's padding is set to the background drawable's padding when the background changes, overwriting any padding set manually. Padding can still be set on the button's table cells.ChangeListener.ChangeEvent
is fired when the button is clicked. Cancelling the event will restore the checked button state to what is was previously.The preferred size of the button is determined by the background and the button contents.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Button.ButtonStyle
The style for a button, seeButton
.-
Nested classes/interfaces inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table
Table.Debug, Table.DebugRect
-
-
Field Summary
-
Fields inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table
backgroundBottom, backgroundLeft, backgroundRight, backgroundTop, debugActorColor, debugCellColor, debugTableColor
-
-
Constructor Summary
Constructors Constructor Description Button()
Creates a button without setting the style or size.Button(Actor child, Button.ButtonStyle style)
Button(Actor child, Skin skin)
Button(Actor child, Skin skin, java.lang.String styleName)
Button(Button.ButtonStyle style)
Button(Skin skin)
Button(Skin skin, java.lang.String styleName)
Button(Drawable up)
Button(Drawable up, Drawable down)
Button(Drawable up, Drawable down, Drawable checked)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
draw(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 Drawable
getBackgroundDrawable()
Returns appropriate background drawable from the style based on the current button state.ButtonGroup
getButtonGroup()
ClickListener
getClickListener()
float
getMinHeight()
float
getMinWidth()
float
getPrefHeight()
float
getPrefWidth()
Button.ButtonStyle
getStyle()
Returns the button's style.boolean
isChecked()
boolean
isDisabled()
boolean
isOver()
boolean
isPressed()
void
setChecked(boolean isChecked)
void
setDisabled(boolean isDisabled)
When true, the button will not toggleisChecked()
when clicked and will not fire aChangeListener.ChangeEvent
.void
setProgrammaticChangeEvents(boolean programmaticChangeEvents)
void
setStyle(Button.ButtonStyle style)
void
toggle()
Toggles the checked state.-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table
add, add, add, add, add, add, add, align, background, background, bottom, center, clearChildren, clip, clip, columnDefaults, debug, debug, debugActor, debugAll, debugCell, debugTable, defaults, drawBackground, drawDebug, drawDebugBounds, getAlign, getBackground, getCell, getCells, getClip, getColumnMinWidth, getColumnPrefWidth, getColumns, getColumnWidth, getPadBottom, getPadBottomValue, getPadLeft, getPadLeftValue, getPadRight, getPadRightValue, getPadTop, getPadTopValue, getPadX, getPadY, getRow, getRowHeight, getRowMinHeight, getRowPrefHeight, getRows, getSkin, getTableDebug, hit, invalidate, layout, left, pad, pad, pad, pad, padBottom, padBottom, padLeft, padLeft, padRight, padRight, padTop, padTop, removeActor, removeActor, removeActorAt, reset, right, row, setBackground, setBackground, setClip, setDebug, setRound, setSkin, stack, top
-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
childrenChanged, getMaxHeight, getMaxWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Group
act, addActor, addActorAfter, addActorAt, addActorBefore, applyTransform, applyTransform, clear, clear, clearChildren, computeTransform, drawChildren, drawDebugChildren, findActor, getChild, getChildren, getCullingArea, hasChildren, isTransform, localToDescendantCoordinates, resetTransform, resetTransform, setCullingArea, 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, 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, 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
-
-
-
-
Constructor Detail
-
Button
public Button(Skin skin)
-
Button
public Button(Skin skin, java.lang.String styleName)
-
Button
public Button(Actor child, Button.ButtonStyle style)
-
Button
public Button(Button.ButtonStyle style)
-
Button
public Button()
Creates a button without setting the style or size. At least a style must be set before using this button.
-
-
Method Detail
-
setChecked
public void setChecked(boolean isChecked)
-
toggle
public void toggle()
Toggles the checked state. This method changes the checked state, which fires aChangeListener.ChangeEvent
(if programmatic change events are enabled), so can be used to simulate a button click.
-
isChecked
public boolean isChecked()
-
isPressed
public boolean isPressed()
-
isOver
public boolean isOver()
-
getClickListener
public ClickListener getClickListener()
-
isDisabled
public boolean isDisabled()
- Specified by:
isDisabled
in interfaceDisableable
-
setDisabled
public void setDisabled(boolean isDisabled)
When true, the button will not toggleisChecked()
when clicked and will not fire aChangeListener.ChangeEvent
.- Specified by:
setDisabled
in interfaceDisableable
-
setProgrammaticChangeEvents
public void setProgrammaticChangeEvents(boolean programmaticChangeEvents)
If false,setChecked(boolean)
andtoggle()
will not fireChangeListener.ChangeEvent
. The event will only be fired only when the user clicks the button
-
setStyle
public void setStyle(Button.ButtonStyle style)
-
getStyle
public Button.ButtonStyle getStyle()
Returns the button's style. Modifying the returned style may not have an effect untilsetStyle(ButtonStyle)
is called.
-
getButtonGroup
@Null public ButtonGroup getButtonGroup()
- Returns:
- May be null.
-
getBackgroundDrawable
@Null protected Drawable getBackgroundDrawable()
Returns appropriate background drawable from the style based on the current button state.
-
draw
public void draw(Batch batch, float parentAlpha)
Description copied from class:WidgetGroup
If this method is overridden, the super method orWidgetGroup.validate()
should be called to ensure the widget group is laid out.
-
getPrefWidth
public float getPrefWidth()
- Specified by:
getPrefWidth
in interfaceLayout
- Overrides:
getPrefWidth
in classTable
-
getPrefHeight
public float getPrefHeight()
- Specified by:
getPrefHeight
in interfaceLayout
- Overrides:
getPrefHeight
in classTable
-
getMinWidth
public float getMinWidth()
- Specified by:
getMinWidth
in interfaceLayout
- Overrides:
getMinWidth
in classTable
-
getMinHeight
public float getMinHeight()
- Specified by:
getMinHeight
in interfaceLayout
- Overrides:
getMinHeight
in classTable
-
-