Class ProgressBar

All Implemented Interfaces:
Disableable, Layout
Direct Known Subclasses:
Slider

public class ProgressBar extends Widget implements Disableable
A progress bar is a widget that visually displays the progress of some activity or a value within given range. The progress bar has a range (min, max) and a stepping between each value it represents. The percentage of completeness typically starts out as an empty progress bar and gradually becomes filled in as the task or variable value progresses.

ChangeListener.ChangeEvent is fired when the progress bar knob is moved. Cancelling 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

    • ProgressBar

      public ProgressBar(float min, float max, float stepSize, boolean vertical, ProgressBar.ProgressBarStyle style)
      Creates a new progress bar. If horizontal, its width is determined by the prefWidth parameter, and its height is determined by the maximum of the height of either the progress bar NinePatch or progress bar handle TextureRegion. The min and max values determine the range the values of this progress bar 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 ProgressBar.ProgressBarStyle
  • Method Details

    • setStyle

      public void setStyle(ProgressBar.ProgressBarStyle style)
    • getStyle

      public ProgressBar.ProgressBarStyle getStyle()
      Returns the progress bar's style. Modifying the returned style may not have an effect until setStyle(ProgressBarStyle) 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(Batch 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 - The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.
    • getValue

      public float getValue()
    • getVisualValue

      public float getVisualValue()
      If animating the progress bar value, this returns the value current displayed.
    • updateVisualValue

      public void updateVisualValue()
      Sets the visual value equal to the actual value. This can be used to set the value without animating.
    • getPercent

      public float getPercent()
    • getVisualPercent

      public float getVisualPercent()
    • setValue

      public boolean setValue(float value)
      Sets the progress bar position, rounded to the nearest step size and clamped to the minimum and maximum values. clamp(float) can be overridden to allow values outside of the progress bar's min/max range.
      Returns:
      false if the value was not changed because the progress bar already had the value or it was canceled by a listener.
    • setRange

      public void setRange(float min, float max)
      Sets the range of this progress bar. The progress bar's current value is clamped to the range.
    • setStepSize

      public void setStepSize(float stepSize)
    • 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 progress bar 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).
    • setVisualInterpolation

      public void setVisualInterpolation(Interpolation interpolation)
      Sets the interpolation to use for display.
    • setRound

      public void setRound(boolean round)
      If true (the default), inner Drawable positions and sizes are rounded to integers.
    • setDisabled

      public void setDisabled(boolean disabled)
      Specified by:
      setDisabled in interface Disableable
    • isAnimating

      public boolean isAnimating()
    • isDisabled

      public boolean isDisabled()
      Specified by:
      isDisabled in interface Disableable
    • isVertical

      public boolean isVertical()
      True if the progress bar is vertical, false if it is horizontal.
    • setProgrammaticChangeEvents

      public void setProgrammaticChangeEvents(boolean programmaticChangeEvents)
      If false, setValue(float) will not fire ChangeListener.ChangeEvent. The event will only be fired when the user changes the slider.