Package arc.scene.ui
Class ProgressBar
java.lang.Object
arc.scene.Element
arc.scene.ui.ProgressBar
- All Implemented Interfaces:
Disableable
- Direct Known Subclasses:
Slider
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.
-
Nested Class Summary
-
Field Summary
Fields inherited from class arc.scene.Element
color, cullable, fillParent, height, name, originX, originY, parent, parentAlpha, rotation, scaleX, scaleY, touchable, touchablility, translation, userObject, visibility, visible, width, x, y
-
Constructor Summary
ConstructorDescriptionProgressBar
(float min, float max, float stepSize, boolean vertical, ProgressBar.ProgressBarStyle style) Creates a new progress bar. -
Method Summary
Modifier and TypeMethodDescriptionvoid
act
(float delta) Updates the actor based on time.protected float
clamp
(float value) Clamps the value to the progress bar's min/max range.void
draw()
Draws the element.protected Drawable
protected float
Returns progress bar visual position within the range.float
float
float
float
float
float
getStyle()
Returns the progress bar's style.float
getValue()
float
float
Ifanimating
the progress bar value, this returns the value current displayed.boolean
boolean
True if the progress bar is vertical, false if it is horizontal.void
setAnimateDuration
(float duration) If > 0, changes to the progress bar value viasetValue(float)
will happen over this duration in seconds.void
setAnimateInterpolation
(Interp animateInterpolation) Sets the interpolation to use forsetAnimateDuration(float)
.void
setDisabled
(boolean disabled) void
setRange
(float min, float max) Sets the range of this progress bar.void
setRound
(boolean round) If true (the default), inner Drawable positions and sizes are rounded to integers.void
setStepSize
(float stepSize) void
boolean
setValue
(float value) Sets the progress bar position, rounded to the nearest step size and clamped to the minimum and maximum values.void
setVisualInterpolation
(Interp interpolation) Sets the interpolation to use for display.Methods inherited from class arc.scene.Element
actions, addAction, addCaptureListener, addListener, change, changed, clear, clearActions, clearListeners, clicked, clicked, clicked, clicked, clipBegin, clipBegin, clipEnd, dragged, exited, fire, fireClick, getActions, getCaptureListeners, getHeight, getListeners, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getRight, getRotation, getScene, getTop, getWidth, getX, getY, getZIndex, hasActions, hasKeyboard, hasMouse, hasParent, hasScroll, hit, hovered, invalidate, invalidateHierarchy, isAscendantOf, isDescendantOf, isDescendantOf, isTouchable, keepInStage, keyDown, keyDown, layout, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, needsLayout, notify, pack, parentToLocalCoordinates, released, remove, removeAction, removeCaptureListener, removeListener, requestKeyboard, requestScroll, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, scrolled, setBounds, setColor, setColor, setFillParent, setHeight, setLayoutEnabled, setOrigin, setOrigin, setPosition, setPosition, setRotation, setRotationOrigin, setScale, setScale, setScene, setSize, setSize, setTranslation, setWidth, setZIndex, sizeBy, sizeBy, sizeChanged, stageToLocalCoordinates, tapped, toBack, toFront, toString, touchable, update, updateVisibility, validate, visible
-
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 barNinePatch
or progress bar handleTextureRegion
. 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 valuemax
- the maximum valuestepSize
- the step size between valuesstyle
- theProgressBar.ProgressBarStyle
-
-
Method Details
-
getStyle
Returns the progress bar's style. Modifying the returned style may not have an effect untilsetStyle(ProgressBarStyle)
is called. -
setStyle
-
act
public void act(float delta) Description copied from class:Element
Updates the actor based on time. Typically this is called each frame byScene.act(float)
.The default implementation calls
Action.act(float)
on each action and removes actions that are complete. -
draw
public void draw()Description copied from class:Element
Draws the element. Does nothing by default. -
getValue
public float getValue() -
getVisualValue
public float getVisualValue()Ifanimating
the progress bar value, this returns the value current displayed. -
getPercent
public float getPercent() -
getVisualPercent
public float getVisualPercent() -
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 classElement
-
getPrefHeight
public float getPrefHeight()- Overrides:
getPrefHeight
in classElement
-
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 viasetValue(float)
will happen over this duration in seconds. -
setAnimateInterpolation
Sets the interpolation to use forsetAnimateDuration(float)
. -
setVisualInterpolation
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 interfaceDisableable
-
setDisabled
public void setDisabled(boolean disabled) - Specified by:
setDisabled
in interfaceDisableable
-
isVertical
public boolean isVertical()True if the progress bar is vertical, false if it is horizontal.
-