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.

    • Constructor Detail

      • ProgressBar

        public ProgressBar​(float min,
                           float max,
                           float stepSize,
                           boolean vertical,
                           Skin skin)
      • ProgressBar

        public ProgressBar​(float min,
                           float max,
                           float stepSize,
                           boolean vertical,
                           Skin skin,
                           java.lang.String styleName)
      • 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 Detail

      • 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()
      • getBackgroundDrawable

        @Null
        protected Drawable getBackgroundDrawable()
      • getKnobBeforeDrawable

        protected Drawable getKnobBeforeDrawable()
      • getKnobAfterDrawable

        protected Drawable getKnobAfterDrawable()
      • getKnobPosition

        protected float getKnobPosition()
        Returns progress bar visual position within the range (as it was last calculated in draw(Batch, float)).
      • 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.
      • round

        protected float round​(float value)
        Rouinds the value using the progress bar's step size. This can be overridden to customize or disable rounding.
      • clamp

        protected float clamp​(float value)
        Clamps the value to the progress bar's min/max range. This can be overridden to allow a range different from the progress bar knob's range.
      • 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)
      • 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.
      • 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()
      • 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.