Package arc.scene.ui

Class Button

All Implemented Interfaces:
Cullable, Disableable
Direct Known Subclasses:
ImageButton, MapObjectivesCanvas.ObjectiveTilemap.ObjectiveTile.Connector, 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.

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.

  • Constructor Details

    • 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)
  • Method Details

    • act

      public void act(float delta)
      Description copied from class: Element
      Updates the actor based on time. Typically this is called each frame by Scene.act(float).

      The default implementation calls Action.act(float) on each action and removes actions that are complete.

      Overrides:
      act in class Group
      Parameters:
      delta - Time in seconds since the last frame.
    • toggle

      public void toggle()
      Toggles the checked state. This method changes the checked state, which fires a ChangeListener.ChangeEvent (if programmatic change events are enabled), so can be used to simulate a button click.
    • isChecked

      public boolean isChecked()
    • setChecked

      public void setChecked(boolean isChecked)
    • isPressed

      public boolean isPressed()
    • isOver

      public boolean isOver()
    • getClickListener

      public ClickListener getClickListener()
    • isDisabled

      public boolean isDisabled()
      Specified by:
      isDisabled in interface Disableable
    • setDisabled

      public void setDisabled(Boolp prov)
    • 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
    • childrenPressed

      public boolean childrenPressed()
    • setProgrammaticChangeEvents

      public void setProgrammaticChangeEvents(boolean programmaticChangeEvents)
      If false, setChecked(boolean) and toggle() will not fire ChangeListener.ChangeEvent, event will be fired only when user clicked the button
    • getStyle

      public Button.ButtonStyle getStyle()
      Returns the button's style. Modifying the returned style may not have an effect until setStyle(ButtonStyle) is called.
    • setStyle

      public void setStyle(Button.ButtonStyle style)
    • getButtonGroup

      public ButtonGroup getButtonGroup()
      Returns:
      May be null.
    • draw

      public void draw()
      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
    • getPrefWidth

      public float getPrefWidth()
      Overrides:
      getPrefWidth in class Table
    • getPrefHeight

      public float getPrefHeight()
      Overrides:
      getPrefHeight in class Table
    • getMinWidth

      public float getMinWidth()
      Overrides:
      getMinWidth in class Table
    • getMinHeight

      public float getMinHeight()
      Overrides:
      getMinHeight in class Table