Class Slider

All Implemented Interfaces:
Disableable, Layout

public class Slider extends ProgressBar
A slider is a horizontal indicator that allows a user to set a value. The slider has a range (min, max) and a stepping between each value the slider represents.

ChangeListener.ChangeEvent is fired when the slider knob is moved. Canceling the event will move the knob to where it was previously.

For a horizontal progress bar, its preferred height is determined by the larger of the knob and background, and the preferred width is 140, a relatively arbitrary size. These parameters are reversed for a vertical progress bar.

Author:
mzechner, Nathan Sweet
  • Constructor Details

    • Slider

      public Slider(float min, float max, float stepSize, boolean vertical, Slider.SliderStyle style)
      Creates a new slider. If horizontal, its width is determined by the 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 Details

    • getStyle

      public Slider.SliderStyle getStyle()
      Returns the slider's style. Modifying the returned style may not have an effect until ProgressBar.setStyle(ProgressBarStyle) is called.
      Overrides:
      getStyle in class ProgressBar
    • isOver

      public boolean isOver()
    • setSnapToValues

      public void setSnapToValues(float threshold, @Null float... values)
      Makes this slider snap to the specified values when the knob is within the threshold.
      Parameters:
      values - May be null to disable snapping.
    • setSnapToValues

      @Deprecated public void setSnapToValues(@Null float[] values, float threshold)
      Makes this progress bar snap to the specified values, if the knob is within the threshold.
      Parameters:
      values - May be null to disable snapping.
    • getSnapToValues

      @Null public float[] getSnapToValues()
    • getSnapToValuesThreshold

      public float getSnapToValuesThreshold()
    • isDragging

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

      public void setButton(int button)
      Sets the mouse button, which can trigger a change of the slider. Is -1, so every button, by default.
    • setVisualInterpolationInverse

      public void setVisualInterpolationInverse(Interpolation interpolation)
      Sets the inverse interpolation to use for display. This should perform the inverse of the visual interpolation.
    • setVisualPercent

      public void setVisualPercent(float percent)
      Sets the value using the specified visual percent.
      See Also: