libgdx API

com.badlogic.gdx.scenes.scene2d.ui
Class Slider

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
      extended by com.badlogic.gdx.scenes.scene2d.ui.Widget
          extended by com.badlogic.gdx.scenes.scene2d.ui.Slider
All Implemented Interfaces:
Layout

public class Slider
extends Widget

A slider is a horizontal indicator that allows a user to set a value. The slider his a range (min, max) and a stepping between each value the slider represents.

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.

Author:
mzechner, Nathan Sweet

Nested Class Summary
static class Slider.SliderStyle
          The style for a slider, see Slider.
 
Constructor Summary
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.
 
Method Summary
 void act(float delta)
          Updates the actor based on time.
 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 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 setRange(float min, float max)
          Sets the range of this slider.
 void setStepSize(float stepSize)
          Sets the step size of the slider
 void setStyle(Slider.SliderStyle style)
           
 void setValue(float value)
          Sets the slider position, rounded to the nearest step size and clamped to the minumum and maximim values.
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, layout, needsLayout, pack, setFillParent, setLayoutEnabled, validate
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, clearActions, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Slider

public Slider(float min,
              float max,
              float stepSize,
              boolean vertical,
              Skin skin)

Slider

public Slider(float min,
              float max,
              float stepSize,
              boolean vertical,
              Skin skin,
              java.lang.String styleName)

Slider

public Slider(float min,
              float max,
              float stepSize,
              boolean vertical,
              Slider.SliderStyle style)
Creates a new slider. It's width is determined by the given prefWidth parameter, its height is determined by the maximum of the height of either the slider 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.

Parameters:
min - the minimum value
max - the maximum value
stepSize - the step size between values
style - the Slider.SliderStyle
Method Detail

setStyle

public void setStyle(Slider.SliderStyle style)

getStyle

public Slider.SliderStyle getStyle()
Returns the slider's style. Modifying the returned style may not have an effect until setStyle(SliderStyle) is called.


act

public void act(float delta)
Description copied from class: Actor
Updates the actor based on time. Typically this is called each frame by Stage.act(float).

The default implementation calls Action.act(float) on each action and removes actions that are complete.

Overrides:
act in class Actor
Parameters:
delta - Time in seconds since the last frame.

draw

public void draw(SpriteBatch batch,
                 float parentAlpha)
Description copied from class: Widget
If this method is overridden, the super method or Widget.validate() should be called to ensure the widget is laid out.

Overrides:
draw in class Widget
parentAlpha - Should be multipied with the actor's alpha, allowing a parent's alpha to affect all children.

isDragging

public boolean isDragging()
Returns true if the slider is being dragged.


getValue

public float getValue()

getVisualValue

public float getVisualValue()
If animating the slider value, this returns the value current displayed.


setValue

public void setValue(float value)
Sets the slider position, rounded to the nearest step size and clamped to the minumum and maximim values.


setRange

public void setRange(float min,
                     float max)
Sets the range of this slider. The slider's current value is reset to min.


setStepSize

public void setStepSize(float stepSize)
Sets the step size of the slider


getPrefWidth

public float getPrefWidth()
Specified by:
getPrefWidth in interface Layout
Overrides:
getPrefWidth in class Widget

getPrefHeight

public float getPrefHeight()
Specified by:
getPrefHeight in interface Layout
Overrides:
getPrefHeight in class Widget

getMinValue

public float getMinValue()

getMaxValue

public float getMaxValue()

getStepSize

public float getStepSize()

setAnimateDuration

public void setAnimateDuration(float duration)
If > 0, changes to the slider value via setValue(float) will happen over this duration in seconds.


setAnimateInterpolation

public void setAnimateInterpolation(Interpolation animateInterpolation)
Sets the interpolation to use for setAnimateDuration(float).


libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)