|
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.Slider
public class Slider
A value slider.
Slider.ValueChangedListener
with the slider.
NinePatch
and TextureRegion
involved in the display of the slider. Use
#setPrefSize(int, int)
to programmatically change the size to your liking. In case the width and height you set are to
small you will see artifacts.
The slider background will only be stretched in the x-axis. The slider handle will be centered on the background vertically.
Widget
displaying a horizontal background NinePatch
, stretched on the x-axis and
using the total height of the NinePatch on the y-axis, as well as a TextureRegion for the slider handle. The style is defined
via an instance of Slider.SliderStyle
, which can be either done programmatically or via a Skin
.
A Slider's style definition in a skin XML file should look like this:
<slider name="styleName"
slider="sliderPatch"
knob="knobRegion"/>
name
attribute defines the name of the style which you can later use with
Skin#newSlider(String, float, float, float, float, String)
.slider
attribute references a NinePatch
by name, to be used as the slider's backgroundknob
attribute references a TextureRegion
by name, to be used as the slider's handle
Nested Class Summary | |
---|---|
static class |
Slider.SliderStyle
Defines the style of a slider, see Slider . |
static interface |
Slider.ValueChangedListener
Interface to listen for changes of the value of the slider. |
Field Summary |
---|
Fields inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget |
---|
invalidated |
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 | |
---|---|
Slider(float min,
float max,
float steps,
Skin skin)
|
|
Slider(float min,
float max,
float steps,
Slider.SliderStyle style)
|
|
Slider(float min,
float max,
float steps,
Slider.SliderStyle style,
java.lang.String name)
Creates a new slider. |
Method Summary | |
---|---|
void |
draw(SpriteBatch batch,
float parentAlpha)
Draws the Actor. |
float |
getPrefHeight()
|
float |
getPrefWidth()
|
float |
getValue()
|
Actor |
hit(float x,
float y)
|
void |
layout()
Positions and sizes each child of this actor. |
void |
setRange(float min,
float max)
Sets the range of this slider. |
void |
setStyle(Slider.SliderStyle style)
Sets the style of this widget. |
void |
setValue(float value)
Sets the value of this slider |
Slider |
setValueChangedListener(Slider.ValueChangedListener listener)
Sets the Slider.ValueChangedListener of this slider. |
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 |
---|
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy |
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 Slider(float min, float max, float steps, Skin skin)
public Slider(float min, float max, float steps, Slider.SliderStyle style)
public Slider(float min, float max, float steps, Slider.SliderStyle style, java.lang.String name)
NinePatch
or slider handle TextureRegion
. The min and max values determine
the range the values of this slider can take on, the steps parameter specifies the distance between individual values. E.g.
min could be 4, max could be 10 and steps could be 0.2, giving you a total of 30 values, 4.0 4.2, 4.4 and so on.
min
- the minimum valuemax
- the maximum valuesteps
- the step size between valuesstyle
- the Slider.SliderStyle
prefWidth
- the (preferred) widthname
- the nameMethod Detail |
---|
public void setStyle(Slider.SliderStyle style)
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 Slider setValueChangedListener(Slider.ValueChangedListener listener)
Slider.ValueChangedListener
of this slider.
listener
- the listener or null
public float getValue()
public void setValue(float value)
value
- the valuepublic void setRange(float min, float max)
min
- the minimum valuemax
- the maximum valuepublic float getPrefWidth()
public float getPrefHeight()
|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |