Package arc.scene.ui
Class Button
java.lang.Object
arc.scene.Element
arc.scene.Group
arc.scene.ui.layout.WidgetGroup
arc.scene.ui.layout.Table
arc.scene.ui.Button
- All Implemented Interfaces:
Cullable
,Disableable
- Direct Known Subclasses:
ImageButton
,MapObjectivesCanvas.ObjectiveTilemap.ObjectiveTile.Connector
,TextButton
A button is a
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.
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class arc.scene.ui.layout.Table
Table.DrawRect
-
Field Summary
Fields inherited from class arc.scene.Group
children, cullingArea, transform
Fields inherited from class arc.scene.Element
color, cullable, fillParent, height, name, originX, originY, parent, parentAlpha, rotation, scaleX, scaleY, touchable, touchablility, translation, userObject, visibility, visible, width, x, y
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
act
(float delta) Updates the actor based on time.boolean
void
draw()
If this method is overridden, the super method orWidgetGroup.validate()
should be called to ensure the widget group is laid out.float
float
float
float
getStyle()
Returns the button's style.boolean
boolean
boolean
isOver()
boolean
void
setChecked
(boolean isChecked) void
setDisabled
(boolean isDisabled) When true, the button will not toggleisChecked()
when clicked and will not fire aChangeListener.ChangeEvent
.void
setDisabled
(Boolp prov) void
setProgrammaticChangeEvents
(boolean programmaticChangeEvents) If false,setChecked(boolean)
andtoggle()
will not fireChangeListener.ChangeEvent
, event will be fired only when user clicked the buttonvoid
setStyle
(Button.ButtonStyle style) void
toggle()
Toggles the checked state.Methods inherited from class arc.scene.ui.layout.Table
add, add, add, add, add, add, add, add, add, align, area, area, background, bottom, button, button, button, button, button, button, button, button, button, button, button, button, buttonCenter, buttonCenter, buttonCenter, buttonRow, center, check, check, check, clearChildren, collapser, collapser, collapser, collapser, defaults, drawBackground, field, field, field, fill, getAlign, getBackground, getCell, getCells, getClip, getColumns, getColumnWidth, getMarginBottom, getMarginLeft, getMarginRight, getMarginTop, getRow, getRowHeight, getRows, hit, image, image, image, image, image, imageDraw, invalidate, label, labelWrap, labelWrap, layout, left, margin, margin, marginBottom, marginLeft, marginRight, marginTop, pane, pane, pane, pane, rect, removeChild, removeChild, reset, right, row, setBackground, setClip, setRound, slider, slider, slider, stack, table, table, table, table, table, top
Methods inherited from class arc.scene.ui.layout.WidgetGroup
childrenChanged, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
Methods inherited from class arc.scene.Group
addChild, addChildAfter, addChildAt, addChildBefore, applyTransform, clear, computeTransform, drawChildren, fill, fill, fill, find, find, findVisible, forEach, getChildren, getCullingArea, hasChildren, isTransform, localToDescendantCoordinates, resetTransform, setCullingArea, setScene, setTransform, swapActor, swapActor, toString
Methods inherited from class arc.scene.Element
actions, addAction, addCaptureListener, addListener, change, changed, clearActions, clearListeners, clicked, clicked, clicked, clicked, clipBegin, clipBegin, clipEnd, dragged, exited, fire, fireClick, getActions, getCaptureListeners, getHeight, getListeners, getMaxHeight, getMaxWidth, getRight, getRotation, getScene, getTop, getWidth, getX, getY, getZIndex, hasActions, hasKeyboard, hasMouse, hasParent, hasScroll, hovered, isAscendantOf, isDescendantOf, isDescendantOf, isTouchable, keepInStage, keyDown, keyDown, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, released, remove, removeAction, removeCaptureListener, removeListener, requestKeyboard, requestScroll, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, scrolled, setBounds, setColor, setColor, setHeight, setOrigin, setOrigin, setPosition, setPosition, setRotation, setRotationOrigin, setScale, setScale, setSize, setSize, setTranslation, setWidth, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, tapped, toBack, toFront, touchable, update, updateVisibility, visible
-
Constructor Details
-
Button
-
Button
public Button()Creates a button without setting the style or size. At least a style must be set before using this button. -
Button
-
Button
-
Button
-
-
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 byScene.act(float)
.The default implementation calls
Action.act(float)
on each action and removes actions that are complete. -
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() -
setChecked
public void setChecked(boolean isChecked) -
isPressed
public boolean isPressed() -
isOver
public boolean isOver() -
getClickListener
-
isDisabled
public boolean isDisabled()- Specified by:
isDisabled
in interfaceDisableable
-
setDisabled
-
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
-
childrenPressed
public boolean childrenPressed() -
setProgrammaticChangeEvents
public void setProgrammaticChangeEvents(boolean programmaticChangeEvents) If false,setChecked(boolean)
andtoggle()
will not fireChangeListener.ChangeEvent
, event will be fired only when user clicked the button -
getStyle
Returns the button's style. Modifying the returned style may not have an effect untilsetStyle(ButtonStyle)
is called. -
setStyle
-
getButtonGroup
- Returns:
- May be null.
-
draw
public void draw()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()- Overrides:
getPrefWidth
in classTable
-
getPrefHeight
public float getPrefHeight()- Overrides:
getPrefHeight
in classTable
-
getMinWidth
public float getMinWidth()- Overrides:
getMinWidth
in classTable
-
getMinHeight
public float getMinHeight()- Overrides:
getMinHeight
in classTable
-