# ui/uiprogressring (vanilla-engine 0.4.0)

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

진행 고리. (vanilla.js ui/uiprogressring.js 의 UIProgressRing)
- 노드의 꼴(둥근 네모, 둥근 정도가 크기의 반이면 동그라미)을 따라 도는 가는 선이다.
- 위 가운데에서 시계 방향으로 채운 몫만큼 채운 색, 나머지는 바탕 색으로 그린다.
- 붙인 노드의 내용 크기 전체가 고리의 바깥 꼴이고, 선의 가운데가 그 안쪽으로 굵기의 반만큼 들어온다.
- 둘레의 점은 크기, 둥근 정도, 굵기가 바뀔 때만 다시 셈한다.

## UIProgressRing (struct) (Default, Component)

진행 고리.
- 붙인 노드의 내용 크기를 바깥 꼴로, 위 가운데에서 시계 방향으로 채운 몫을 그린다.

예제: 48 x 48 동그라미 고리

```rust
use vanilla::{NodeTree, UIProgressRing, Vector2};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let ring_id = node_tree.create_child(root_id, "LoadingRing");
node_tree[ring_id].set_content_size(Vector2::create(48.0, 48.0));
let ring = node_tree.add_component(ring_id, UIProgressRing::new()).expect("ring");
ring.set_round_size(24.0);
ring.set_line_width(4.0);
ring.set_ratio(0.25);
assert_eq!(ring.get_ratio(), 0.25);
ring.set_ratio(1.5);
assert_eq!(ring.get_ratio(), 1.0);
```

- `pub fn new() -> UIProgressRing` (constructor, since 0.4.0): 생성.
  - returns UIProgressRing: 붙기 전의 고리. (몫 0, 둥근 정도 0, 굵기 2, 채운 색 흰색)
- `pub fn draw_ring(&mut self, transform: &NodeTransform, graphic: &mut Graphic)` (method, since 0.4.0): 출력. (바탕 고리 한 바퀴, 그 위에 채운 몫)
  - `transform` &NodeTransform: 노드 변환. (내용 크기가 고리의 바깥 꼴, 크기에서 굵기를 뺀 가로나 세로가 1 이하면 그리지 않는다)
  - `graphic` &mut Graphic: 그릴 그래픽.
- `pub fn read_perimeter_points(left: f64, top: f64, width: f64, height: f64, round_size: f64) -> Vec<Vector2>` (static, since 0.4.0): 둥근 네모 둘레의 점. (위 가운데에서 시작해 시계 방향, 닫는 점은 넣지 않는다)
  - `left` f64: 네모의 왼쪽.
  - `top` f64: 네모의 위.
  - `width` f64: 네모의 가로.
  - `height` f64: 네모의 세로.
  - `round_size` f64: 귀퉁이 반지름. (가로와 세로의 반을 넘으면 그 값으로 자른다)
  - returns Vec<Vector2>: 둘레의 점 45 개. (위 가운데 1 개, 귀퉁이마다 11 개)

  예제: 첫 점은 위 가운데

  ```rust
  use vanilla::{UIProgressRing, Vector2};
  
  let points = UIProgressRing::read_perimeter_points(0.0, 0.0, 100.0, 60.0, 0.0);
  assert_eq!(points.len(), 45);
  assert_eq!(points[0], Vector2::create(50.0, 0.0));
  ```

- `pub fn read_partial_points(points: &[Vector2], ratio: f64) -> Vec<Vector2>` (static, since 0.4.0): 둘레의 앞 몫만큼의 점. (길이로 셈하고, 끝점은 마지막 변 위에서 잘라 넣는다)
  - `points` &[Vector2]: 둘레의 점. (닫는 점 없이, read_perimeter_points 의 결과)
  - `ratio` f64: 앞에서부터 그릴 몫. (닫은 둘레 길이의 비율, 0 ~ 1)
  - returns Vec<Vector2>: 첫 점부터 그 몫까지 이은 점. (points 가 비면 빈 목록, 1 이상이면 첫 점으로 돌아와 닫는다)

  예제: 반 바퀴면 아래 가운데에서 끝난다

  ```rust
  use vanilla::UIProgressRing;
  
  let points = UIProgressRing::read_perimeter_points(0.0, 0.0, 100.0, 100.0, 0.0);
  let half_points = UIProgressRing::read_partial_points(&points, 0.5);
  let last_point = half_points[half_points.len() - 1];
  assert!((last_point.x - 50.0).abs() < 0.01);
  assert!((last_point.y - 100.0).abs() < 0.01);
  ```

- `pub fn set_ratio(&mut self, ratio: f64)` (method, since 0.4.0): 채운 몫 설정. (0 ~ 1 로 자른다)
  - `ratio` f64: 채운 몫. (0 ~ 1, 넘으면 자른다)
- `pub fn get_ratio(&self) -> f64` (method, since 0.4.0): 채운 몫 반환.
  - returns f64: 채운 몫. (0 ~ 1, 기본 0)
- `pub fn set_round_size(&mut self, round_size: f64)` (method, since 0.4.0): 귀퉁이 둥근 정도 설정. (크기의 반 이상이면 동그라미)
  - `round_size` f64: 바깥 꼴의 귀퉁이 반지름. (선의 가운데는 굵기의 반을 뺀 반지름으로 돈다)
- `pub fn get_round_size(&self) -> f64` (method, since 0.4.0): 귀퉁이 둥근 정도 반환.
  - returns f64: 바깥 꼴의 귀퉁이 반지름. (기본 0)
- `pub fn set_line_width(&mut self, line_width: f64)` (method, since 0.4.0): 선 굵기 설정.
  - `line_width` f64: 선 굵기. (기본 2)
- `pub fn get_line_width(&self) -> f64` (method, since 0.4.0): 선 굵기 반환.
  - returns f64: 선 굵기. (기본 2)
- `pub fn set_fill_color(&mut self, color: impl Into<Color>)` (method, since 0.4.0): 채운 몫의 색 설정.
  - `color` impl Into<Color>: 채운 몫의 색. (기본 흰색)
- `pub fn get_fill_color(&self) -> Color` (method, since 0.4.0): 채운 몫의 색 반환.
  - returns Color: 채운 몫의 색.
- `pub fn set_track_color(&mut self, color: impl Into<Color>)` (method, since 0.4.0): 나머지의 색 설정.
  - `color` impl Into<Color>: 바탕 고리의 색. (기본 `Color::create(0.2, 0.2, 0.25, 1.0)`)
- `pub fn get_track_color(&self) -> Color` (method, since 0.4.0): 나머지의 색 반환.
  - returns Color: 바탕 고리의 색.
- `pub fn get_perimeter_points(&self) -> &[Vector2]` (method, since 0.4.0): 마지막으로 셈한 둘레의 점. (그린 뒤에 맞는 값, 원본 getPerimeterPoints)
  - returns &[Vector2]: 선의 가운데가 지나는 둘레의 점. (한 번도 그리지 않았으면 빈 목록)
