public class Slider extends Widget implements Disableable
ChangeListener.ChangeEvent
is fired when the slider knob is moved. Cancelling the event will move the knob to where it was previously.
The preferred height of a slider is determined by the larger of the knob and background. The preferred width of a slider is 140, a relatively arbitrary size.
Modifier and Type | Class and Description |
---|---|
static class |
Slider.SliderStyle
The style for a slider, see
Slider . |
Constructor and Description |
---|
Slider(float min,
float max,
float stepSize,
boolean vertical,
Skin skin) |
Slider(float min,
float max,
float stepSize,
boolean vertical,
Skin skin,
java.lang.String styleName) |
Slider(float min,
float max,
float stepSize,
boolean vertical,
Slider.SliderStyle style)
Creates a new slider.
|
Modifier and Type | Method and Description |
---|---|
void |
act(float delta)
Updates the actor based on time.
|
protected float |
clamp(float value)
Clamps the value to the sliders min/max range.
|
void |
draw(SpriteBatch batch,
float parentAlpha)
If this method is overridden, the super method or
Widget.validate() should be called to ensure the widget is laid out. |
float |
getMaxValue() |
float |
getMinValue() |
float |
getPrefHeight() |
float |
getPrefWidth() |
float |
getStepSize() |
Slider.SliderStyle |
getStyle()
Returns the slider's style.
|
float |
getValue() |
float |
getVisualValue()
If
animating the slider value, this returns the value current displayed. |
boolean |
isDisabled() |
boolean |
isDragging()
Returns true if the slider is being dragged.
|
void |
setAnimateDuration(float duration)
If > 0, changes to the slider value via
setValue(float) will happen over this duration in seconds. |
void |
setAnimateInterpolation(Interpolation animateInterpolation)
Sets the interpolation to use for
setAnimateDuration(float) . |
void |
setDisabled(boolean disabled) |
void |
setRange(float min,
float max)
Sets the range of this slider.
|
void |
setSnapToValues(float[] values,
float threshold)
Will make this slider snap to the specified values, if the knob is within the threshold
|
void |
setStepSize(float stepSize)
Sets the step size of the slider
|
void |
setStyle(Slider.SliderStyle style) |
boolean |
setValue(float value)
Sets the slider position, rounded to the nearest step size and clamped to the minumum and maximim values.
|
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, layout, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
addAction, addCaptureListener, addListener, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getWidth, getX, getY, getZIndex, hasParent, hit, isAscendantOf, isDescendantOf, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotate, scale, scale, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOriginX, setOriginY, setParent, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setVisible, setWidth, setX, setY, setZIndex, size, size, stageToLocalCoordinates, toBack, toFront, toString, translate
public Slider(float min, float max, float stepSize, boolean vertical, Skin skin)
public Slider(float min, float max, float stepSize, boolean vertical, Skin skin, java.lang.String styleName)
public Slider(float min, float max, float stepSize, boolean vertical, Slider.SliderStyle style)
NinePatch
or slider handle TextureRegion
. The min and max values determine
the range the values of this slider can take on, the stepSize parameter specifies the distance between individual values.
E.g. min could be 4, max could be 10 and stepSize 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 valuestepSize
- the step size between valuesstyle
- the Slider.SliderStyle
public void setStyle(Slider.SliderStyle style)
public Slider.SliderStyle getStyle()
setStyle(SliderStyle)
is
called.public void act(float delta)
Actor
Stage.act(float)
.
The default implementation calls Action.act(float)
on each action and removes actions that are complete.
public void draw(SpriteBatch batch, float parentAlpha)
Widget
Widget.validate()
should be called to ensure the widget is laid out.public boolean isDragging()
public float getValue()
public float getVisualValue()
animating
the slider value, this returns the value current displayed.public boolean setValue(float value)
clamp(float)
can be overidden to allow values outside of the sliders min/max range.protected float clamp(float value)
public void setRange(float min, float max)
public void setStepSize(float stepSize)
public float getPrefWidth()
getPrefWidth
in interface Layout
getPrefWidth
in class Widget
public float getPrefHeight()
getPrefHeight
in interface Layout
getPrefHeight
in class Widget
public float getMinValue()
public float getMaxValue()
public float getStepSize()
public void setAnimateDuration(float duration)
setValue(float)
will happen over this duration in seconds.public void setAnimateInterpolation(Interpolation animateInterpolation)
setAnimateDuration(float)
.public void setSnapToValues(float[] values, float threshold)
public void setDisabled(boolean disabled)
setDisabled
in interface Disableable
public boolean isDisabled()