com.badlogic.gdx.scenes.scene2d.ui
Class Button

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
      extended by com.badlogic.gdx.scenes.scene2d.Group
          extended by com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
              extended by com.badlogic.gdx.scenes.scene2d.ui.Table
                  extended by 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 a Table with a checked state and additional style 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.

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.

Author:
Nathan Sweet

Nested Class Summary
static class Button.ButtonStyle
          The style for a button, see Button.
 
Constructor Summary
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, String styleName)
           
Button(Button.ButtonStyle style)
           
Button(Drawable up)
           
Button(Drawable up, Drawable down)
           
Button(Drawable up, Drawable down, Drawable checked)
           
Button(Skin skin)
           
Button(Skin skin, String styleName)
           
 
Method Summary
 void draw(Batch batch, float parentAlpha)
          If this method is overridden, the super method or WidgetGroup.validate() should be called to ensure the widget group is laid out.
 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 toggle isChecked() when clicked and will not fire a ChangeListener.ChangeEvent.
 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, columnDefaults, debug, debug, debugCell, debugTable, debugWidget, defaults, drawDebug, getAlign, getBackground, getCell, getCells, getClip, getDebug, getPadBottom, getPadBottomValue, getPadLeft, getPadLeftValue, getPadRight, getPadRightValue, getPadTop, getPadTopValue, getPadX, getPadY, getRow, hit, invalidate, layout, left, pad, pad, pad, pad, padBottom, padBottom, padLeft, padLeft, padRight, padRight, padTop, padTop, removeActor, reset, right, row, setBackground, setBackground, setBackground, setClip, setRound, setSkin, stack, top
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
getMaxHeight, getMaxWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, validate
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Group
act, addActor, addActorAfter, addActorAt, addActorBefore, clear, findActor, getChildren, hasChildren, isTransform, localToDescendantCoordinates, print, setCullingArea, setTransform, swapActor, swapActor
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getY, getZIndex, hasParent, isAscendantOf, isDescendantOf, isTouchable, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotateBy, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOriginX, setOriginY, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Button

public Button(Skin skin)

Button

public Button(Skin skin,
              String styleName)

Button

public Button(Actor child,
              Skin skin,
              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.


Button

public Button(Drawable up)

Button

public Button(Drawable up,
              Drawable down)

Button

public Button(Drawable up,
              Drawable down,
              Drawable checked)

Button

public Button(Actor child,
              Skin skin)
Method Detail

setChecked

public void setChecked(boolean isChecked)

toggle

public void toggle()
Toggles the checked state. This method changes the checked state, which fires a ChangeListener.ChangeEvent, 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()

setDisabled

public void setDisabled(boolean isDisabled)
When true, the button will not toggle isChecked() when clicked and will not fire a ChangeListener.ChangeEvent.

Specified by:
setDisabled in interface Disableable

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 until setStyle(ButtonStyle) is called.


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 Table
parentAlpha - Should be multiplied with the actor's alpha, allowing a parent's alpha to affect all children.

getPrefWidth

public float getPrefWidth()
Specified by:
getPrefWidth in interface Layout
Overrides:
getPrefWidth in class Table

getPrefHeight

public float getPrefHeight()
Specified by:
getPrefHeight in interface Layout
Overrides:
getPrefHeight in class Table

getMinWidth

public float getMinWidth()
Specified by:
getMinWidth in interface Layout
Overrides:
getMinWidth in class Table

getMinHeight

public float getMinHeight()
Specified by:
getMinHeight in interface Layout
Overrides:
getMinHeight in class Table


Copyright © 2014. All Rights Reserved.