# ui/uiprogressview (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/ui/uiprogressview/

Progress display.

## UIProgressView extends UIView

Progress display.
- Uses the node's contentSize area as the track.
- Draws the fill area by the value ratio.
- No input. The value is changed only externally via setValue.
- Inherits UIView to stay consistent as a container display object,
  and gets automatic mask/content node handling when attached to a WorldNode.

Example: Drawing a rounded progress bar

```js
import { Engine, EngineConfiguration, UIScene, UIProgressView, WorldNode, Color, Pivot, Vector2 } from "./build/vanilla.js";

class ProgressScene extends UIScene {
	create() {
		super.create();
		const progressNode = new WorldNode();
		progressNode.setPivot(Pivot.topLeft.clone());
		progressNode.setAnchor(Pivot.topLeft.clone());
		progressNode.setContentSize(Vector2.create(400, 24));
		progressNode.setLocalPosition(Vector2.create(120, 168));
		const progressView = progressNode.addComponent(UIProgressView);
		progressView.setRange(0, 100);
		progressView.setValue(65);
		progressView.setTrackColor(new Color(0.2, 0.2, 0.25, 1));
		progressView.setFillColor(new Color(0.3, 0.8, 0.5, 1));
		progressView.setCornerRadius(12);
		const ratio = progressView.getRatio();
		console.log(ratio);
		const root = this.getRoot();
		root.addChild(progressNode);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new ProgressScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);
```

- `constructor()` (constructor, since 0.2.1): Constructor.
- `isDrawnInsideContent()` (method, since 0.4.0): Returns whether it draws only inside the content area. (the track and fill paint only inside the content-size rectangle; used by off-screen and outside-clip culling)
  - Subclasses that override draw return false because where they draw is unknown. (such a class overrides this function too to report it)
  - returns boolean: True if drawing only inside the content area.
- `draw(graphic)` (method, since 0.2.1): Draw. (track + fill. The track uses UIView.backgroundColor)
  - Draws directly without calling super.draw, to handle cornerRadius.
  - `graphic` Graphic: Graphic to draw with. (node local coordinates, origin at the top-left of the content area)
- `getRatio()` (method, since 0.2.1): Returns the 0~1 ratio.
  - returns number: Ratio of the value within the range. (0 ~ 1, 0 if the range is 0 or less)
- `setValue(value)` (method, since 0.2.1): Sets the value.
  - `value` number: Value. (clamped to minimum ~ maximum)
- `getValue()` (method, since 0.2.1): Returns the value.
  - returns number: Value clamped to the range.
- `setRange(minValue, maxValue)` (method, since 0.2.1): Sets the minimum~maximum value range.
  - `minValue` number: Minimum value. (ratio 0)
  - `maxValue` number: Maximum value. (ratio 1, the ratio is always 0 if it is not above the minimum)
- `getMinValue()` (method, since 0.2.1): Returns the minimum value.
  - returns number: Minimum value of the range.
- `getMaxValue()` (method, since 0.2.1): Returns the maximum value.
  - returns number: Maximum value of the range.
- `setSecondaryValue(secondaryValue)` (method, since 0.3.0): Sets the opposite value. (off if null, fills from the end opposite the progress direction)
  - `secondaryValue` number | null: Opposite value. (clamped to minimum ~ maximum, null turns it off)

  Example: Showing both sides' share in one bar

  ```js
  import { UIProgressView, Color } from "./build/vanilla.js";
  
  const progressView = new UIProgressView();
  progressView.setRange(0, 100);
  progressView.setValue(40);
  progressView.setSecondaryValue(35);
  progressView.setSecondaryFillColor(new Color(0.94, 0.33, 0.31, 1));
  const secondaryValue = progressView.getSecondaryValue();
  console.log(secondaryValue);
  progressView.setSecondaryValue(null);
  ```

- `getSecondaryValue()` (method, since 0.3.0): Returns the opposite value.
  - returns number | null: Opposite value. (null when off)
- `setSecondaryFillColor(color)` (method, since 0.3.0): Sets the opposite fill color.
  - `color` Color | string: Opposite fill color. (kept as is, not cloned)
- `getSecondaryFillColor()` (method, since 0.3.0): Returns the opposite fill color.
  - returns Color: Opposite fill color.
- `setTrackColor(color)` (method, since 0.2.1): Sets the track color.
  - `color` Color | string: Track color. (set as the UIView background color)
- `getTrackColor()` (method, since 0.2.1): Returns the track color.
  - returns Color: Track color. (the UIView background color)
- `setFillColor(color)` (method, since 0.2.1): Fill color.
  - `color` Color | string: Fill color. (kept as is, not cloned)
- `getFillColor()` (method, since 0.2.1): Returns the fill color.
  - returns Color: Fill color.
- `setCornerRadius(radius)` (method, since 0.2.1): Rounded corner radius.
  - `radius` number: Radius. (pixels, drawn as a plain rectangle if 0 or less)
- `getCornerRadius()` (method, since 0.2.1): Returns the rounded corner radius.
  - returns number: Radius. (pixels)
- `setDirection(direction)` (method, since 0.2.1): Direction. (ProgressDirection.horizontal / vertical)
  - `direction` string: "horizontal" fills from left to right, "vertical" fills from bottom to top.
- `getDirection()` (method, since 0.2.1): Returns the direction.
  - returns string: "horizontal" or "vertical".

## ProgressDirection (enum)

Progress direction.

- `horizontal` = `horizontal`: Fills left to right
- `vertical` = `vertical`: Fills bottom to top
