# ui/uiprogressring (vanilla.js 0.4.0)

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

Progress ring.

## UIProgressRing extends Component

Progress ring.
- A thin line running along the node's shape (rounded rectangle, a circle if the roundness is half the size).
- From the top center, clockwise, the filled fraction is drawn in the fill color and the rest in the background color.
- The whole content size of the attached node is the ring's outer shape, and the line's center is inset by half the thickness.
- Perimeter points are recomputed only when the size, roundness or thickness changes.

Example: Drawing a round progress ring

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

class RingScene extends UIScene {
	create() {
		super.create();
		const ringNode = new WorldNode();
		ringNode.setPivot(Pivot.middleCenter.clone());
		ringNode.setAnchor(Pivot.topLeft.clone());
		ringNode.setContentSize(Vector2.create(96, 96));
		ringNode.setLocalPosition(Vector2.create(320, 180));
		const progressRing = ringNode.addComponent(UIProgressRing);
		progressRing.setRoundSize(48);
		progressRing.setLineWidth(6);
		progressRing.setFillColor("#4ade80");
		progressRing.setTrackColor("rgba(255, 255, 255, 0.15)");
		progressRing.setRatio(0.7);
		const root = this.getRoot();
		root.addChild(ringNode);
	}
}

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

- `constructor()` (constructor, since 0.4.0): Constructor.
- `draw(graphic)` (method, since 0.4.0): Draw. (one full background ring, with the filled fraction on top)
  - `graphic` Graphic: Graphic to draw with. (node local coordinates, origin at the top-left of the content area)
- `isDrawnInsideContent()` (method, since 0.4.0): Returns whether it draws only inside the content area. (the ring is drawn inset inside the content size by half the thickness)
  - false for subclasses that override draw, since where they draw is unknown.
  - returns boolean: True if draw is not overridden.
- `readPerimeterPoints(left, top, width, height, roundSize)` (method, since 0.4.0): Points on the rounded rectangle perimeter. (starting from the top center, clockwise, without the closing point)
  - `left` number: Left. (pixels)
  - `top` number: Top. (pixels)
  - `width` number: Width. (pixels)
  - `height` number: Height. (pixels)
  - `roundSize` number: Corner radius. (clamped to half the width and height)
  - returns Array<Vector2>: Perimeter points. (one top-center point and 11 per corner, 45 in total)
- `readPartialPoints(points, ratio)` (method, since 0.4.0): Points for the leading fraction of the perimeter. (computed by length; the end point is cut on the last edge and added)
  - `points` Array<Vector2>: Result of readPerimeterPoints. (closed shape)
  - `ratio` number: Share of the perimeter length to cut from the start. (0 ~ 1)
  - returns Array<Vector2>: Open point list starting at the first point and ending at the cut end point.
- `setRatio(ratio)` (method, since 0.4.0): Sets the filled fraction. (clamped to 0 ~ 1)
  - `ratio` number: Filled share. (0 ~ 1)
- `getRatio()` (method, since 0.4.0): Returns the filled fraction.
  - returns number: Filled share. (0 ~ 1)
- `setRoundSize(roundSize)` (method, since 0.4.0): Sets the corner roundness. (a circle if half the size or more)
  - `roundSize` number: Corner radius of the outer shape. (pixels, a rectangle if 0)
- `getRoundSize()` (method, since 0.4.0): Returns the corner roundness.
  - returns number: Corner radius of the outer shape. (pixels)
- `setLineWidth(lineWidth)` (method, since 0.4.0): Sets the line thickness.
  - `lineWidth` number: Line width. (pixels)
- `getLineWidth()` (method, since 0.4.0): Returns the line thickness.
  - returns number: Line width. (pixels)
- `setFillColor(color)` (method, since 0.4.0): Sets the color of the filled fraction.
  - `color` Color | string: Color of the filled share. (Color, "#rrggbb", "rgba(...)")
- `getFillColor()` (method, since 0.4.0): Returns the color of the filled fraction.
  - returns Color: Color of the filled share.
- `setTrackColor(color)` (method, since 0.4.0): Sets the color of the rest.
  - `color` Color | string: Color of the rest. (Color, "#rrggbb", "rgba(...)")
- `getTrackColor()` (method, since 0.4.0): Returns the color of the rest.
  - returns Color: Color of the rest.
- `getPerimeterPoints()` (method, since 0.4.0): Returns the perimeter points. (for the last drawn size)
  - returns Array<Vector2>: Perimeter points. (empty array if never drawn)
- `static parseColor(color)` (static, since 0.4.0): Reads a color value. ("#rrggbb", "rgba(...)" or Color)
  - `color` Color | string: Color value. (text starting with "rgb" is read as rgba, other text as a hex color)
  - returns Color: The parsed color. (a Color is returned as is)
