# ui/uiprogressview (vanilla.js 0.4.0)

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

진행률 표시.

## UIProgressView extends UIView

진행률 표시.
- 노드의 contentSize 영역을 트랙으로 사용.
- value 비율만큼 fill 영역을 그린다.
- 입력은 없음. 값은 외부에서 setValue 로만 변경.
- UIView 를 상속하여 컨테이너 표시 객체로서의 일관성을 유지하고,
  WorldNode 에 부착될 때 자동 마스크/콘텐츠 노드 처리를 받는다.

예제: 둥근 진행 막대 그리기

```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): 생성.
- `isDrawnInsideContent()` (method, since 0.4.0): 내용 영역 안에서만 그리는지 반환. (트랙과 채움은 내용 크기의 사각형 안만 칠한다, 화면 밖과 자르기 밖 거르기가 쓴다)
  - draw 를 덮어쓴 하위 클래스는 어디에 그리는지 모르므로 false. (그 클래스가 이 함수도 덮어써 알린다)
  - returns boolean: 내용 영역 안에서만 그리면 참.
- `draw(graphic)` (method, since 0.2.1): 출력. (트랙 + 채움. 트랙은 UIView.backgroundColor 사용)
  - cornerRadius 처리를 위해 super.draw 를 호출하지 않고 직접 그린다.
  - `graphic` Graphic: 그릴 그래픽. (노드 로컬 좌표, 내용 영역 왼쪽 위가 원점)
- `getRatio()` (method, since 0.2.1): 0~1 비율 반환.
  - returns number: 범위 안에서 값의 비율. (0 ~ 1, 범위가 0 이하면 0)
- `setValue(value)` (method, since 0.2.1): 값 설정.
  - `value` number: 값. (최소 ~ 최대로 자른다)
- `getValue()` (method, since 0.2.1): 값 반환.
  - returns number: 범위로 자른 값.
- `setRange(minValue, maxValue)` (method, since 0.2.1): 최소~최대 값 범위 설정.
  - `minValue` number: 최소 값. (비율 0)
  - `maxValue` number: 최대 값. (비율 1, 최소 이하면 비율이 늘 0)
- `getMinValue()` (method, since 0.2.1): 최소 값 반환.
  - returns number: 범위의 최소 값.
- `getMaxValue()` (method, since 0.2.1): 최대 값 반환.
  - returns number: 범위의 최대 값.
- `setSecondaryValue(secondaryValue)` (method, since 0.3.0): 반대편 값 설정. (null 이면 끔, 진행 방향의 반대쪽 끝에서 차오른다)
  - `secondaryValue` number | null: 반대편 값. (최소 ~ 최대로 자른다, null 이면 끈다)

  예제: 한 막대에 양쪽 점유율 보이기

  ```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 number | null: 반대편 값. (끈 상태면 null)
- `setSecondaryFillColor(color)` (method, since 0.3.0): 반대편 채움 색 설정.
  - `color` Color | string: 반대편 채움 색. (복제하지 않고 그대로 쥔다)
- `getSecondaryFillColor()` (method, since 0.3.0): 반대편 채움 색 반환.
  - returns Color: 반대편 채움 색.
- `setTrackColor(color)` (method, since 0.2.1): 트랙 색 설정.
  - `color` Color | string: 트랙 색. (UIView 의 배경 색으로 넣는다)
- `getTrackColor()` (method, since 0.2.1): 트랙 색 반환.
  - returns Color: 트랙 색. (UIView 의 배경 색)
- `setFillColor(color)` (method, since 0.2.1): 채움 색.
  - `color` Color | string: 채움 색. (복제하지 않고 그대로 쥔다)
- `getFillColor()` (method, since 0.2.1): 채움 색 반환.
  - returns Color: 채움 색.
- `setCornerRadius(radius)` (method, since 0.2.1): 라운드 코너 반지름.
  - `radius` number: 반지름. (픽셀, 0 이하면 네모로 그린다)
- `getCornerRadius()` (method, since 0.2.1): 라운드 코너 반지름 반환.
  - returns number: 반지름. (픽셀)
- `setDirection(direction)` (method, since 0.2.1): 방향. (ProgressDirection.horizontal / vertical)
  - `direction` string: "horizontal" 이면 왼쪽에서 오른쪽, "vertical" 이면 아래에서 위로 채운다.
- `getDirection()` (method, since 0.2.1): 방향 반환.
  - returns string: "horizontal" 이나 "vertical".

## ProgressDirection (enum)

진행률 방향.

- `horizontal` = `horizontal`: 좌→우 채움
- `vertical` = `vertical`: 하→상 채움
