Skip to content

ProgressBar

Since 2.2.1

ProgressBar displays a value within a configurable [min, max] range as a partially-filled bar. The fill direction, interpolation animation, and inner textures are all configurable. An optional centered Label can overlay the bar.

ProgressBar implements IBindable<Float> and IDataConsumer<Float>, so its value can be driven by a data provider and kept in sync with the server automatically.

INFO

Everything documented on UIElement (layout, styles, events, data bindings, etc.) applies here too.


Usage

java
var bar = new ProgressBar();
bar.setRange(0, 100);
bar.setProgress(75f);
parent.addChild(bar);

// Data-bound (server → client, ticks every tick)
bar.bindDataSource(DataBindingBuilder.floatValS2C(
    () -> machine.getProgress() / (float) machine.getMaxProgress()
).build());

XML

xml
<!-- Basic progress bar at 50 % -->
<progress-bar min-value="0" max-value="100" value="50"/>

<!-- With a centered text label -->
<progress-bar min-value="0" max-value="200" value="100" text="my.progress.key"/>
XML AttributeTypeDescription
min-valuefloatMinimum value. Default: 0.
max-valuefloatMaximum value. Default: 1.
valuefloatCurrent value. Default: 0.
textstringSets the overlay label (translated).

Internal Structure

IndexFieldTypeCSS classDescription
0barContainerUIElement.__progress-bar_bar-container__Outer container with the background texture and padding.

The following elements are nested inside the internal structure:

FieldCSS classDescription
bar.__progress-bar_bar__The filled portion of the bar.
label.__progress-bar_label__The optional overlay Label (absolute-positioned, centred).

Progress Bar Style

INFO

fill-direction

Direction in which the bar fills as the value increases.

Default: LEFT_TO_RIGHT

ValueDescription
LEFT_TO_RIGHTBar grows from the left edge.
RIGHT_TO_LEFTBar grows from the right edge.
UP_TO_DOWNBar grows from the top edge.
DOWN_TO_UPBar grows from the bottom edge.
ALWAYS_FULLBar is always fully visible regardless of value.
java
bar.progressBarStyle(style -> style.fillDirection(FillDirection.DOWN_TO_UP));

INFO

interpolate

When true, the bar visually animates toward the target value each tick instead of jumping.

Default: true

java
bar.progressBarStyle(style -> style.interpolate(false));

INFO

interpolate-step

Fraction of the total range (max - min) moved per tick during interpolation. Negative values use partial-tick lerp for extra smoothness.

Default: 0.1

java
bar.progressBarStyle(style -> style.interpolateStep(0.05f)); // slower animation
bar.progressBarStyle(style -> style.interpolateStep(-1f));    // partial-tick lerp

Customising the Bar Texture

The bar uses Sprites.PROGRESS_CONTAINER for the outer container and Sprites.PROGRESS_BAR for the fill. Override these via style or DSL:

java
bar.barContainer(c -> c.style(s -> s.background(myContainerTexture)));
bar.bar(b -> b.style(s -> s.background(myBarTexture)));

Data Binding

ProgressBar subscribes to IDataProvider&lt;Float&gt; for automatic value updates.

java
var binding = DataBindingBuilder.floatValS2C(
    () -> machine.getProgress() / (float) machine.getMaxProgress()
).build();

bar.bindDataSource(binding);
bar.unbindDataSource(binding); // when done

See Data Bindings for the full binding API.


Fields

NameTypeAccessDescription
barContainerUIElementpublic finalOuter container element.
barUIElementpublic finalThe filled bar element.
labelLabelpublic finalThe overlay label element.
progressBarStyleProgressBarStyleprivate (getter)Current progress bar style.
minValuefloatprivate (getter)Minimum range value.
maxValuefloatprivate (getter)Maximum range value.

Methods

MethodReturnsDescription
setProgress(float)ProgressBarSets the current value (clamped to [min, max]).
setRange(float, float)ProgressBarSets the [min, max] range and re-evaluates the current value.
setMinValue(float)ProgressBarSets the minimum value.
setMaxValue(float)ProgressBarSets the maximum value.
progressBarStyle(Consumer&lt;ProgressBarStyle&gt;)ProgressBarConfigures ProgressBarStyle fluently.
bar(Consumer&lt;UIElement&gt;)ProgressBarConfigures the fill bar element.
barContainer(Consumer&lt;UIElement&gt;)ProgressBarConfigures the outer container element.
label(Consumer&lt;Label&gt;)ProgressBarConfigures the overlay label.
bindDataSource(IDataProvider&lt;Float&gt;)ProgressBarSubscribes to a data provider.
unbindDataSource(IDataProvider&lt;Float&gt;)ProgressBarUnsubscribes from a data provider.
getValue()FloatReturns the current value.
getNormalizedValue()floatReturns the current value normalized to [0, 1].

Released under the MIT License.