|
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.ImageToggleButton
public class ImageToggleButton
A toggle button with an image on it.
ImageToggleButton.ClickListener
can be registered
with the ImageToggleButton which will be called in case the button changed its state.
NinePatch
as well as the width and height of the TextureRegion of the image displayed inside the ImageToggleButton. 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 image you will see artifacts.
Widget
displaying a background NinePatch
as well as image in form of a
TextureRegion
. The style is defined via an instance of ImageToggleButton.ImageToggleButtonStyle
, which can be either done
programmatically or via a Skin
.
A Button's style definition in a skin XML file should look like this:
<imagetogglebutton name="styleName"
down="downNinePatch"
up="upNinePatch"
/>
name
attribute defines the name of the style which you can later use with
Skin#newImageToggleButton(String, TextureRegion, String)
.down
attribute references a NinePatch
by name, to be used as the button's background when it is
pressedup
attribute references a NinePatch
by name, to be used as the button's background when it is not
pressedsetImageSize(float, float)
Nested Class Summary | |
---|---|
static interface |
ImageToggleButton.ClickListener
Interface for listening to click events. |
static class |
ImageToggleButton.ImageToggleButtonStyle
Defines an image toggle button style, see ImageToggleButton |
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 | |
---|---|
ImageToggleButton(java.lang.String name,
TextureRegion image,
float imageWidth,
float imageHeight,
ImageToggleButton.ImageToggleButtonStyle style)
Creates a new image toggle button. |
|
ImageToggleButton(java.lang.String name,
TextureRegion image,
ImageToggleButton.ImageToggleButtonStyle style)
Creates a new image toggle button. |
|
ImageToggleButton(TextureRegion image,
ImageToggleButton.ImageToggleButtonStyle style)
|
|
ImageToggleButton(TextureRegion image,
Skin skin)
|
Method Summary | |
---|---|
void |
draw(SpriteBatch batch,
float parentAlpha)
Draws the Actor. |
TextureRegion |
getImage()
|
boolean |
isPressed()
|
void |
layout()
Positions and sizes each child of this actor. |
ImageToggleButton |
setClickListener(ImageToggleButton.ClickListener listener)
Sets the ImageToggleButton.ClickListener |
void |
setImage(TextureRegion image)
Sets the image's TextureRegion. |
void |
setImageSize(float width,
float height)
Sets the image's size. |
void |
setPressed(boolean isPressed)
Sets whether this ImageToggleButton is down. |
void |
setStyle(ImageToggleButton.ImageToggleButtonStyle style)
Sets the style of this widget. |
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, hit, 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 ImageToggleButton(TextureRegion image, Skin skin)
public ImageToggleButton(TextureRegion image, ImageToggleButton.ImageToggleButtonStyle style)
public ImageToggleButton(java.lang.String name, TextureRegion image, ImageToggleButton.ImageToggleButtonStyle style)
name
- the nameimage
- the image' TextureRegion
style
- the ImageToggleButton.ImageToggleButtonStyle
public ImageToggleButton(java.lang.String name, TextureRegion image, float imageWidth, float imageHeight, ImageToggleButton.ImageToggleButtonStyle style)
name
- the nameimage
- the image' TextureRegion
imageWidth
- the image's widthimageHeight
- the image's heightstyle
- the ImageToggleButton.ImageToggleButtonStyle
Method Detail |
---|
public void setStyle(ImageToggleButton.ImageToggleButtonStyle 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 TextureRegion getImage()
TextureRegion
public void setImage(TextureRegion image)
image
- the image's TextureRegion
public void setImageSize(float width, float height)
width
- the image's widthheight
- the image's heightpublic ImageToggleButton setClickListener(ImageToggleButton.ClickListener listener)
ImageToggleButton.ClickListener
listener
- the listener or null
ImageToggleButton
for chainingpublic boolean isPressed()
ImageToggleButton
is down or notpublic void setPressed(boolean isPressed)
ImageToggleButton
is down.
isPressed
- whether this button is down
|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |