com.badlogic.gdx.scenes.scene2d.ui
Class ProgressBar

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

The preferred height of a progress bar is determined by the larger of the knob and background. The preferred width of progress bar is 140, a relatively arbitrary size.

Author:
mzechner, Nathan Sweet

Nested Class Summary
static class ProgressBar.ProgressBarStyle
          The style for a progress bar, see ProgressBar.
 
Constructor Summary
ProgressBar(float min, float max, float stepSize, boolean vertical, ProgressBar.ProgressBarStyle style)
          Creates a new progress bar.
ProgressBar(float min, float max, float stepSize, boolean vertical, Skin skin)
           
ProgressBar(float min, float max, float stepSize, boolean vertical, Skin skin, String styleName)
           
 
Method Summary
 void act(float delta)
          Updates the actor based on time.
 void draw(Batch 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 getMaxValue()
           
 float getMinValue()
           
 float getPrefHeight()
           
 float getPrefWidth()
           
 float getStepSize()
           
 ProgressBar.ProgressBarStyle getStyle()
          Returns the progress bar's style.
 float getValue()
           
 float getVisualValue()
          If animating the progress bar value, this returns the value current displayed.
 boolean isDisabled()
           
 void setAnimateDuration(float duration)
          If > 0, changes to the progress bar value via setValue(float) will happen over this duration in seconds.
 void setAnimateInterpolation(Interpolation animateInterpolation)
          Sets the interpolation to use for setAnimateDuration(float).
 void setDisabled(boolean disabled)
           
 void setRange(float min, float max)
          Sets the range of this progress bar.
 void setSnapToValues(float[] values, float threshold)
          Will make this progress bar snap to the specified values, if the knob is within the threshold.
 void setStepSize(float stepSize)
           
 void setStyle(ProgressBar.ProgressBarStyle style)
           
 boolean setValue(float value)
          Sets the progress bar position, rounded to the nearest step size and clamped to the minimum and maximum values.
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, layout, needsLayout, pack, setFillParent, setLayoutEnabled, validate
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getY, getZIndex, hasParent, hit, isAscendantOf, isDescendantOf, isTouchable, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotateBy, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOriginX, setOriginY, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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,
                   String styleName)

ProgressBar

public ProgressBar(float min,
                   float max,
                   float stepSize,
                   boolean vertical,
                   ProgressBar.ProgressBarStyle style)
Creates a new progress bar. It's width is determined by the given prefWidth parameter, 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

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 - Should be multiplied with the actor's alpha, allowing a 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.


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).


setSnapToValues

public void setSnapToValues(float[] values,
                            float threshold)
Will make this progress bar snap to the specified values, if the knob is within the threshold.


setDisabled

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

isDisabled

public boolean isDisabled()


Copyright © 2014. All Rights Reserved.