Package arc.scene.ui

Class ProgressBar

java.lang.Object
arc.scene.Element
arc.scene.ui.ProgressBar
All Implemented Interfaces:
Disableable
Direct Known Subclasses:
Slider

public class ProgressBar extends Element 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 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

    • 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.
    • setStyle

      public void setStyle(ProgressBar.ProgressBarStyle style)
    • act

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

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

      Overrides:
      act in class Element
      Parameters:
      delta - Time in seconds since the last frame.
    • draw

      public void draw()
      Description copied from class: Element
      Draws the element. Does nothing by default.
      Overrides:
      draw in class Element
    • getValue

      public float getValue()
    • getVisualValue

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

      public float getPercent()
    • getVisualPercent

      public float getVisualPercent()
    • getKnobDrawable

      protected Drawable getKnobDrawable()
    • getKnobPosition

      protected float getKnobPosition()
      Returns progress bar visual position within the range.
    • 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.
    • 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.
    • getPrefWidth

      public float getPrefWidth()
      Overrides:
      getPrefWidth in class Element
    • getPrefHeight

      public float getPrefHeight()
      Overrides:
      getPrefHeight in class Element
    • getMinValue

      public float getMinValue()
    • getMaxValue

      public float getMaxValue()
    • getStepSize

      public float getStepSize()
    • setStepSize

      public void setStepSize(float stepSize)
    • 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(Interp animateInterpolation)
      Sets the interpolation to use for setAnimateDuration(float).
    • setVisualInterpolation

      public void setVisualInterpolation(Interp 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.
    • isDisabled

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

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

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