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.

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

Nested Class Summary
static class Slider.SliderStyle
          The style for a slider, see Slider.
static interface Slider.ValueChangedListener
          Interface to listen for changes to the value of the slider.
 
Field Summary
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
actions, color, height, name, originX, originY, parent, rotation, scaleX, scaleY, stage, 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.
Slider(Skin skin)
           
 
Method Summary
 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 getPrefHeight()
           
 float getPrefWidth()
           
 Slider.SliderStyle getStyle()
          Returns the slider's style.
 float getValue()
           
 boolean isDragging()
          Returns true if the slider is being dragged.
 void setRange(float min, float max)
          Sets the range of this slider.
 void setStyle(Slider.SliderStyle style)
           
 void setValue(float value)
           
 void setValueChangedListener(Slider.ValueChangedListener listener)
           
 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, hit, invalidate, invalidateHierarchy, layout, needsLayout, pack, setFillParent, toScreenCoordinates, validate
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, action, clearActions, getStage, 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

Slider

public Slider(Skin skin)

Slider

public Slider(float min,
              float max,
              float steps,
              Skin skin)

Slider

public Slider(float min,
              float max,
              float steps,
              Slider.SliderStyle style)

Slider

public Slider(float min,
              float max,
              float steps,
              Slider.SliderStyle style,
              java.lang.String name)
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 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.

Parameters:
min - the minimum value
max - the maximum value
steps - the step size between values
style - the Slider.SliderStyle
name - the name
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.


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
Parameters:
batch - the spritebatch to render with
parentAlpha - the parent's alpha value.

touchDown

public boolean touchDown(float x,
                         float y,
                         int pointer)
Overrides:
touchDown in class Widget

touchUp

public void touchUp(float x,
                    float y,
                    int pointer)
Overrides:
touchUp in class Widget

touchDragged

public void touchDragged(float x,
                         float y,
                         int pointer)
Overrides:
touchDragged in class Widget

isDragging

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


setValueChangedListener

public void setValueChangedListener(Slider.ValueChangedListener listener)
Parameters:
listener - May be null.

getValue

public float getValue()

setValue

public void setValue(float value)

setRange

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


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

libgdx API

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