APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d.ui

public Class ProgressBar

extends Widget
implements Disableable, Styleable<ProgressBar.ProgressBarStyle>
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.scenes.scene2d.ui.Styleable, com.badlogic.gdx.scenes.scene2d.utils.Disableable
Known Direct Subclasses
com.badlogic.gdx.scenes.scene2d.ui.Slider
Imports
com.badlogic.gdx.Gdx, com.badlogic.gdx.graphics.Color, com.badlogic.gdx.graphics.g2d.Batch, .NinePatch, .TextureRegion, com.badlogic.gdx.math.Interpolation, .MathUtils, com.badlogic.gdx.scenes.scene2d.Stage, com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent, .Disableable, .Drawable, com.badlogic.gdx.utils.Null

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.

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.

Authors
mzechner, Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ProgressBar.ProgressBarStyle

The style for a progress bar, see ProgressBar.

Field Summary

Modifier and TypeField and Description
private float
private float
private Interpolation
private float
pack-priv boolean
pack-priv float
pack-priv float
pack-priv float
private boolean
private boolean
pack-priv float
private ProgressBar.ProgressBarStyle
private float
pack-priv final boolean
private Interpolation

Constructor Summary

AccessConstructor and Description
public
ProgressBar(float min, float max, float stepSize, boolean vertical, Skin skin)

public
ProgressBar(float min, float max, float stepSize, boolean vertical, Skin skin, String styleName)

public
ProgressBar(float
the minimum value
min
,
float
the maximum value
max
,
float
the step size between values
stepSize
,
boolean vertical, ProgressBar.ProgressBarStyle style)

Creates a new progress bar.

Method Summary

Modifier and TypeMethod and Description
public void
act(float delta)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.act.

Updates the actor based on time.

protected float
clamp(float value)

Clamps the value to the progress bar's min/max range.

public void
draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.

private void
drawRound(Batch batch, Drawable drawable, float x, float y, float w, float h)

protected Drawable
protected Drawable
protected Drawable
protected Drawable
protected float
getKnobPosition()

Returns progress bar visual position within the range (as it was last calculated in draw(Batch, float)).

public float
public float
public float
public float
public float
public boolean
public float
public ProgressBar.ProgressBarStyle
getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the progress bar's style.

public float
public float
public float
getVisualValue()

If animating the progress bar value, this returns the value current displayed.

public boolean
public boolean
public boolean
isVertical()

True if the progress bar is vertical, false if it is horizontal.

protected float
round(float value)

Rouinds the value using the progress bar's step size.

public void
setAnimateDuration(float duration)

If > 0, changes to the progress bar value via setValue(float) will happen over this duration in seconds.

public void
setAnimateInterpolation(Interpolation animateInterpolation)

Sets the interpolation to use for setAnimateDuration(float).

public void
public void
setProgrammaticChangeEvents(boolean programmaticChangeEvents)

If false, setValue(float) will not fire ChangeEvent.

public void
setRange(float min, float max)

Sets the range of this progress bar.

public void
setRound(boolean round)

If true (the default), inner Drawable positions and sizes are rounded to integers.

public void
setStepSize(float stepSize)

public void
public boolean

Returns:

false if the value was not changed because the progress bar already had the value or it was canceled by a listener.
setValue
(float value)

Sets the progress bar position, rounded to the nearest step size and clamped to the minimum and maximum values.

public void
setVisualInterpolation(Interpolation interpolation)

Sets the interpolation to use for display.

public void
updateVisualValue()

Sets the visual value equal to the actual value.

Inherited from com.badlogic.gdx.scenes.scene2d.ui.Widget:
getMaxHeightgetMaxWidthgetMinHeightgetMinWidthinvalidateinvalidateHierarchylayoutneedsLayoutpacksetFillParentsetLayoutEnabledsizeChangedvalidate

Field Detail

animateDurationback to summary
private float animateDuration
animateFromValueback to summary
private float animateFromValue
animateInterpolationback to summary
private Interpolation animateInterpolation
animateTimeback to summary
private float animateTime
disabledback to summary
pack-priv boolean disabled
maxback to summary
pack-priv float max
minback to summary
pack-priv float min
positionback to summary
pack-priv float position
programmaticChangeEventsback to summary
private boolean programmaticChangeEvents
roundback to summary
private boolean round
stepSizeback to summary
pack-priv float stepSize
styleback to summary
private ProgressBar.ProgressBarStyle style
valueback to summary
private float value
verticalback to summary
pack-priv final boolean vertical
visualInterpolationback to summary
private Interpolation visualInterpolation

Constructor Detail

ProgressBarback to summary
public ProgressBar(float min, float max, float stepSize, boolean vertical, Skin skin)
ProgressBarback to summary
public ProgressBar(float min, float max, float stepSize, boolean vertical, Skin skin, String styleName)
ProgressBarback to summary
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:float

the minimum value

max:float

the maximum value

stepSize:float

the step size between values

style:ProgressBar.ProgressBarStyle

the ProgressBarStyle

Method Detail

actback to summary
public void act(float delta)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.act.

Doc from com.badlogic.gdx.scenes.scene2d.Actor.act.

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.

clampback to summary
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.

drawback to summary
public void draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

Doc from com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.

drawRoundback to summary
private void drawRound(Batch batch, Drawable drawable, float x, float y, float w, float h)
getBackgroundDrawableback to summary
protected Drawable getBackgroundDrawable()
Annotations
@Null
getKnobAfterDrawableback to summary
protected Drawable getKnobAfterDrawable()
getKnobBeforeDrawableback to summary
protected Drawable getKnobBeforeDrawable()
getKnobDrawableback to summary
protected Drawable getKnobDrawable()
Annotations
@Null
getKnobPositionback to summary
protected float getKnobPosition()

Returns progress bar visual position within the range (as it was last calculated in draw(Batch, float)).

getMaxValueback to summary
public float getMaxValue()
getMinValueback to summary
public float getMinValue()
getPercentback to summary
public float getPercent()
getPrefHeightback to summary
public float getPrefHeight()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.getPrefHeight.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefHeight.

getPrefWidthback to summary
public float getPrefWidth()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.getPrefWidth.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefWidth.

getProgrammaticChangeEventsback to summary
public boolean getProgrammaticChangeEvents()
getStepSizeback to summary
public float getStepSize()
getStyleback to summary
public ProgressBar.ProgressBarStyle getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the progress bar's style. Modifying the returned style may not have an effect until setStyle(ProgressBarStyle) is called.

getValueback to summary
public float getValue()
getVisualPercentback to summary
public float getVisualPercent()
getVisualValueback to summary
public float getVisualValue()

If animating the progress bar value, this returns the value current displayed.

isAnimatingback to summary
public boolean isAnimating()
isDisabledback to summary
public boolean isDisabled()

Implements com.badlogic.gdx.scenes.scene2d.utils.Disableable.isDisabled.

isVerticalback to summary
public boolean isVertical()

True if the progress bar is vertical, false if it is horizontal.

roundback to summary
protected float round(float value)

Rouinds the value using the progress bar's step size. This can be overridden to customize or disable rounding.

setAnimateDurationback to summary
public void setAnimateDuration(float duration)

If > 0, changes to the progress bar value via setValue(float) will happen over this duration in seconds.

setAnimateInterpolationback to summary
public void setAnimateInterpolation(Interpolation animateInterpolation)

Sets the interpolation to use for setAnimateDuration(float).

setDisabledback to summary
public void setDisabled(boolean disabled)

Implements com.badlogic.gdx.scenes.scene2d.utils.Disableable.setDisabled.

setProgrammaticChangeEventsback to summary
public void setProgrammaticChangeEvents(boolean programmaticChangeEvents)

If false, setValue(float) will not fire ChangeEvent. The event will only be fired when the user changes the slider.

setRangeback to summary
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.

setRoundback to summary
public void setRound(boolean round)

If true (the default), inner Drawable positions and sizes are rounded to integers.

setStepSizeback to summary
public void setStepSize(float stepSize)
setStyleback to summary
public void setStyle(ProgressBar.ProgressBarStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Doc from com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

setValueback to summary
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:boolean

false if the value was not changed because the progress bar already had the value or it was canceled by a listener.

setVisualInterpolationback to summary
public void setVisualInterpolation(Interpolation interpolation)

Sets the interpolation to use for display.

updateVisualValueback to summary
public void updateVisualValue()

Sets the visual value equal to the actual value. This can be used to set the value without animating.

com.badlogic.gdx.scenes.scene2d.ui back to summary

public Class ProgressBar.ProgressBarStyle

extends Object
Class Inheritance
  • java.lang.Object
  • com.badlogic.gdx.scenes.scene2d.ui.ProgressBar.ProgressBarStyle
Known Direct Subclasses
com.badlogic.gdx.scenes.scene2d.ui.Slider.SliderStyle

The style for a progress bar, see ProgressBar.
Authors
mzechner, Nathan Sweet

Field Summary

Modifier and TypeField and Description
public Drawable
background

The progress bar background, stretched only in one direction.

public Drawable
disabledBackground

The progress bar background, stretched only in one direction.

public Drawable
public Drawable
public Drawable
public Drawable
public Drawable
public Drawable

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backgroundback to summary
public Drawable background

The progress bar background, stretched only in one direction.

Annotations
@Null
disabledBackgroundback to summary
public Drawable disabledBackground

The progress bar background, stretched only in one direction.

Annotations
@Null
disabledKnobback to summary
public Drawable disabledKnob
Annotations
@Null
disabledKnobAfterback to summary
public Drawable disabledKnobAfter
Annotations
@Null
disabledKnobBeforeback to summary
public Drawable disabledKnobBefore
Annotations
@Null
knobback to summary
public Drawable knob
Annotations
@Null
knobAfterback to summary
public Drawable knobAfter
Annotations
@Null
knobBeforeback to summary
public Drawable knobBefore
Annotations
@Null

Constructor Detail

ProgressBarStyleback to summary
public ProgressBarStyle()
ProgressBarStyleback to summary
public ProgressBarStyle(Drawable background, Drawable knob)
ProgressBarStyleback to summary
public ProgressBarStyle(ProgressBar.ProgressBarStyle style)