|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.ui.Widget
com.badlogic.gdx.scenes.scene2d.ui.ToggleButton
public class ToggleButton
A toggle button.
ToggleButton.ClickListener
can be registered
with the ToggleButton which will be called in case the button changed its state.
NinePatch
as well as the bounding box of the multi-line label displayed inside the ToggleButton. Use
Widget.setPrefSize(int, int)
to programmatically change the size to your liking. In case the width and height you set are to
small for the contained label you will see artifacts.
Widget
displaying a background NinePatch
as well as multi-line text with a
specific font and color. The style is defined via an instance of ToggleButton.ToggleButtonStyle
, which can be either done
programmatically or via a Skin
.
A Button's style definition in a skin XML file should look like this:
<togglebutton name="styleName"
down="downNinePatch"
up="upNinePatch"
font="fontName"
fontColor="colorName"/>/>
name
attribute defines the name of the style which you can later use with
Skin#newToggleButton(String, String, String)
.down
attribute references a NinePatch
by name, to be used as the toggle button's background when
it is pressedup
attribute references a NinePatch
by name, to be used as the toggle button's background when it
is not pressedfont
attribute references a BitmapFont
by name, to be used to render the text on the toggle button
fontColor
attribute references a Color
by name, to be used to render the text on the toggle button
Nested Class Summary | |
---|---|
static interface |
ToggleButton.ClickListener
Interface to listen for button state changes. |
static class |
ToggleButton.ToggleButtonStyle
Defines the style of a toggle button, see ToggleButton |
Field Summary |
---|
Fields inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget |
---|
invalidated, prefHeight, prefWidth |
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor |
---|
actions, color, height, name, originX, originY, parent, rotation, scaleX, scaleY, touchable, visible, width, x, y |
Constructor Summary | |
---|---|
ToggleButton(java.lang.String label,
Skin skin)
|
|
ToggleButton(java.lang.String name,
java.lang.String label,
ToggleButton.ToggleButtonStyle style)
Creates a new ToggleButton. |
|
ToggleButton(java.lang.String label,
ToggleButton.ToggleButtonStyle style)
|
Method Summary | |
---|---|
void |
draw(SpriteBatch batch,
float parentAlpha)
Draws the Actor. |
java.lang.String |
getText()
|
Actor |
hit(float x,
float y)
|
boolean |
isPressed()
|
void |
layout()
Positions and sizes each child of this actor. |
ToggleButton |
setClickListener(ToggleButton.ClickListener listener)
Sets the ToggleButton.ClickListener of this button. |
void |
setPressed(boolean isPressed)
Sets whether this button is pressed or not. |
void |
setStyle(ToggleButton.ToggleButtonStyle style)
Sets the style of this widget. |
void |
setText(java.lang.String text)
Sets the text label of this button. |
boolean |
touchDown(float x,
float y,
int pointer)
|
void |
touchDragged(float x,
float y,
int pointer)
|
void |
touchUp(float x,
float y,
int pointer)
|
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget |
---|
getPrefHeight, getPrefWidth, invalidate, invalidateHierarchy, setPrefSize |
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor |
---|
act, action, clearActions, isMarkedToRemove, keyDown, keyTyped, keyUp, markToRemove, remove, scrolled, toLocalCoordinates, toString, touchMoved |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ToggleButton(java.lang.String label, Skin skin)
public ToggleButton(java.lang.String label, ToggleButton.ToggleButtonStyle style)
public ToggleButton(java.lang.String name, java.lang.String label, ToggleButton.ToggleButtonStyle style)
NinePatch
border patches as well
as the bounding box around the contained text label.
name
- the namelabel
- the multi-line labelstyle
- the ToggleButton.ToggleButtonStyle
Method Detail |
---|
public void setStyle(ToggleButton.ToggleButtonStyle style)
Widget.invalidateHierarchy()
internally.
style
- public void layout()
Layout
Layout.invalidate()
is
called.
public void draw(SpriteBatch batch, float parentAlpha)
Actor
FadeIn
and
other Actions to have an effect even if they are only set on the parent of the Actor.
draw
in class Actor
batch
- the spritebatch to render withparentAlpha
- the parent's alpha value.public boolean touchDown(float x, float y, int pointer)
touchDown
in class Actor
public void touchUp(float x, float y, int pointer)
touchUp
in class Actor
public void touchDragged(float x, float y, int pointer)
touchDragged
in class Actor
public Actor hit(float x, float y)
hit
in class Widget
public void setText(java.lang.String text)
text
- the textpublic java.lang.String getText()
public ToggleButton setClickListener(ToggleButton.ClickListener listener)
ToggleButton.ClickListener
of this button.
listener
- the listener or null
ToggleButton
for chainingpublic boolean isPressed()
public void setPressed(boolean isPressed)
isPressed
- whether the button is pressed or not
|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |