ProgressBar

November 7, 2023 ยท View on GitHub

from tdw.add_ons.ui_widgets.progress_bar import ProgressBar

Two rectangles used to display a value between 0 and 1, which can be set or incremented/decremented.

This is a subclass of UI but can coincide with any other UI add-on or subclass thereof.

You don't need to set a unique canvas_id: this ProgressBar will automatically use a canvas with that ID if one already exists.


Fields

  • done If True, the progress bar is at its final value (1 if incrementing, 0 if decrementing).

Functions

__init__

ProgressBar()

ProgressBar(value=0, increment=True, left_to_right=True, size=None, underlay_color=None, overlay_color=None, anchor=None, pivot=None, position=None, canvas_id=0)

ParameterTypeDefaultDescription
valuefloat0The initial value as a fraction of the total time (0 to 1).
incrementboolTrueIf True, the progress bar is incrementing. If False, the progress bar is decrementing. This determines whether the progress bar is done when its value is 0 or 1.
left_to_rightboolTrueIf true, the progress bar increments leftwards.
sizeDict[str, int]NoneThe size of the progress bar in pixels.
underlay_colorDict[str, float]NoneThe color of the progress bar underlay.
overlay_colorDict[str, float]NoneThe color of the progress bar overlay.
anchorDict[str, float]NoneThe anchor of the progress bar. If this is (1, 1), then position (0, 0) is the top-right of the screen.
pivotDict[str, float]NoneThe pivot of the progress bar. If this is (1, 1), then the pivot is the bar's top-right corner.
positionDict[str, int]NoneThe anchor position of the UI element in pixels. x is lateral, y is vertical. The anchor position is not the true pixel position. For example, if the anchor is {"x": 0, "y": 0} and the position is {"x": 0, "y": 0}, the UI element will be in the bottom-left of the screen.
canvas_idint0The ID of the canvas.

set_value

self.set_value(value)

Set the internal progress bar value.

ParameterTypeDefaultDescription
valuefloatThe new value. This will be clamped to be between 0 and 1.

increment_value

self.increment_value(delta)

Increment or decrement the progress bar.

ParameterTypeDefaultDescription
deltafloatIncrement or decrement by this delta value (-1 to 1).