# ui/uiprogressview (vanilla-engine 0.4.0)

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

진행률 표시. (원본 ui/uiprogressview.js 의 UIProgressView, ProgressDirection)
- 호스트 content_size 영역을 트랙으로 쓰고, 값 비율만큼 채움을 그린다. 입력은 받지 않는다.
- 트랙 색은 원본처럼 UIView 의 배경색이다. (set_track_color 는 set_background_color 의 다른 이름)
- 반대편 값(secondary_value)을 정하면 진행 방향의 반대쪽 끝에서 차오르는 두 번째 채움을 그린다. (원본 null 은 None)

## UIProgressView (struct) (Default, Component)

진행률 표시.

예제: 체력 바

```rust
use vanilla::{NodeTree, ProgressDirection, UIProgressView, Vector2};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let bar_id = node_tree.create_child(root_id, "HealthBar");
node_tree[bar_id].set_content_size(Vector2::create(200.0, 12.0));
let progress_view = node_tree.add_component(bar_id, UIProgressView::new()).expect("progress");
progress_view.set_range(0.0, 120.0);
progress_view.set_value(90.0);
progress_view.set_corner_radius(6.0);
assert_eq!(progress_view.get_ratio(), 0.75);
assert_eq!(progress_view.get_direction(), ProgressDirection::Horizontal);
```

- `pub fn new() -> UIProgressView` (constructor, since 0.3.2): 생성. (값 0, 범위 0 ~ 1, 트랙 회색, 채움 파랑)
  - returns UIProgressView: 붙기 전의 진행률 표시. (가로 방향, 반대편 값 없음)
- `pub fn get_uiview(&self) -> &UIView` (method, since 0.3.2): 품은 뷰 반환.
  - returns &UIView: 품은 UIView.
- `pub fn get_uiview_mut(&mut self) -> &mut UIView` (method, since 0.3.2): 품은 뷰 반환. (변경용)
  - returns &mut UIView: 품은 UIView.
- `pub fn get_content(&self) -> Option<NodeId>` (method, since 0.3.2): 컨텐트 노드 핸들.
  - returns Option<NodeId>: 컨텐트 노드. (트리에 붙기 전이면 None)
- `pub fn set_background_color(&mut self, background_color: impl Into<Color>)` (method, since 0.3.2): 배경색 설정. (트랙 색)
  - `background_color` impl Into<Color>: 트랙 색. (기본 `Color::create(0.7, 0.7, 0.7, 1.0)`)
- `pub fn get_background_color(&self) -> Color` (method, since 0.3.2): 배경색 반환. (트랙 색)
  - returns Color: 트랙 색.
- `pub fn get_ratio(&self) -> f64` (method, since 0.3.2): 0 ~ 1 비율 반환.
  - returns f64: 범위 안에서 값의 자리. (0 ~ 1, 최대값이 최소값보다 크지 않으면 0)
- `pub fn set_value(&mut self, value: f64)` (method, since 0.3.2): 값 설정. (범위로 자른다)
  - `value` f64: 값. (최소값 ~ 최대값으로 자른다)
- `pub fn get_value(&self) -> f64` (method, since 0.3.2): 값 반환.
  - returns f64: 값. (기본 0)
- `pub fn set_range(&mut self, min_value: f64, max_value: f64)` (method, since 0.3.2): 범위 설정. (지금 값을 새 범위로 다시 자른다)
  - 반대편 값은 다시 자르지 않는다. (원본과 같음, 그릴 때 비율을 0 ~ 1 로 자른다)
  - `min_value` f64: 최소값. (비율 0 자리)
  - `max_value` f64: 최대값. (비율 1 자리)

  예제: 범위를 바꾸면 값이 새 범위로 잘린다

  ```rust
  use vanilla::UIProgressView;
  
  let mut progress_view = UIProgressView::new();
  progress_view.set_value(0.8);
  progress_view.set_range(0.0, 0.5);
  assert_eq!(progress_view.get_value(), 0.5);
  progress_view.set_range(10.0, 20.0);
  assert_eq!(progress_view.get_value(), 10.0);
  assert_eq!(progress_view.get_ratio(), 0.0);
  ```

- `pub fn get_min_value(&self) -> f64` (method, since 0.3.2): 최소값 반환.
  - returns f64: 최소값. (기본 0)
- `pub fn get_max_value(&self) -> f64` (method, since 0.3.2): 최대값 반환.
  - returns f64: 최대값. (기본 1)
- `pub fn set_secondary_value(&mut self, secondary_value: Option<f64>)` (method, since 0.3.2): 반대편 값 설정. (None 이면 끔. 범위로 자른다)
  - `secondary_value` Option<f64>: 진행 방향의 반대쪽 끝에서 차오르는 두 번째 채움의 값. (None 이면 그리지 않는다)

  예제: 대전 게이지의 반대편

  ```rust
  use vanilla::UIProgressView;
  
  let mut progress_view = UIProgressView::new();
  progress_view.set_range(0.0, 100.0);
  progress_view.set_value(40.0);
  progress_view.set_secondary_value(Some(35.0));
  assert_eq!(progress_view.get_secondary_value(), Some(35.0));
  progress_view.set_secondary_value(Some(150.0));
  assert_eq!(progress_view.get_secondary_value(), Some(100.0));
  progress_view.set_secondary_value(None);
  assert_eq!(progress_view.get_secondary_value(), None);
  ```

- `pub fn get_secondary_value(&self) -> Option<f64>` (method, since 0.3.2): 반대편 값 반환.
  - returns Option<f64>: 반대편 값. (끈 상태면 None, 기본 None)
- `pub fn set_secondary_fill_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 반대편 채움 색 설정.
  - `color` impl Into<Color>: 반대편 채움 색. (기본 `Color::create(0.94, 0.33, 0.31, 1.0)`)
- `pub fn get_secondary_fill_color(&self) -> Color` (method, since 0.3.2): 반대편 채움 색 반환.
  - returns Color: 반대편 채움 색.
- `pub fn set_track_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 트랙 색 설정. (배경색)
  - `color` impl Into<Color>: 트랙 색. (set_background_color 와 같다)
- `pub fn get_track_color(&self) -> Color` (method, since 0.3.2): 트랙 색 반환. (배경색)
  - returns Color: 트랙 색.
- `pub fn set_fill_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 채움 색 설정.
  - `color` impl Into<Color>: 채움 색. (기본 `Color::create(0.23, 0.51, 0.96, 1.0)`)
- `pub fn get_fill_color(&self) -> Color` (method, since 0.3.2): 채움 색 반환.
  - returns Color: 채움 색.
- `pub fn set_corner_radius(&mut self, corner_radius: f64)` (method, since 0.3.2): 둥근 모서리 반지름 설정.
  - `corner_radius` f64: 트랙과 채움의 모서리 반지름. (0 이하면 각진 사각형, 기본 0)
- `pub fn get_corner_radius(&self) -> f64` (method, since 0.3.2): 둥근 모서리 반지름 반환.
  - returns f64: 모서리 반지름. (기본 0)
- `pub fn set_direction(&mut self, direction: ProgressDirection)` (method, since 0.3.2): 방향 설정.
  - `direction` ProgressDirection: 진행 방향. (Horizontal 은 왼쪽에서, Vertical 은 아래에서 채운다. 반대편 값은 그 반대쪽 끝에서)
- `pub fn get_direction(&self) -> ProgressDirection` (method, since 0.3.2): 방향 반환.
  - returns ProgressDirection: 진행 방향. (기본 Horizontal)

## ProgressDirection (enum) (Clone, Copy, Debug, PartialEq, Eq)

진행 방향.

- `Horizontal`: 왼쪽에서 오른쪽으로 채움.
- `Vertical`: 아래에서 위로 채움.
