# core/node/nodetree (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/node/nodetree/

노드 트리.
- 씬의 노드를 저장소 하나(slotmap)에 담고, 부모와 자식을 핸들(NodeId)로 잇는다.
- 게임 코드는 NodeId 를 들고 다니다가 get_node / get_node_mut (또는 `tree[node_id]`) 로 노드를 꺼낸다.
  지운 노드의 NodeId 는 get_node 가 None 을 돌려준다. (원본 isDestroyed 자리)
- 원본은 부모가 children[] 으로 자식 객체를 들고 자식이 parent 로 거꾸로 가리킨다.
  러스트에서 그 꼴(`Rc<RefCell>`)은 실행 중 빌림 검사 비용과 순환 참조가 생겨서 핸들로 바꿨다.
- tick / 터치를 돌 때는 부르는 컴포넌트 하나만 노드에서 잠깐 꺼내(그 자리에는 빈 자리표를 둔다) ComponentContext(자기 노드 + 트리 전체 + 엔진)를 넘긴다.
  그래서 컴포넌트가 다른 노드를 찾고 바꾸고 만들 수 있고, 같은 노드의 다른 컴포넌트(형제)도 get_node_mut().`get_component_mut::<T>()` 로 찾는다.
- 도는 중에 지운 노드는 그 자리에서 비활성으로 두고, 다 돈 뒤에 실제로 지운다.
- 형제 순서(원본 Node.setSiblingIndex, getSiblingIndex, getSiblings)와 계층 판정(isActiveInHierarchy, TransformNode.isVisibleInHierarchy)은
  부모를 봐야 해서 NodeTree 가 노드 핸들을 받아 한다. 원본의 -1 과 null 은 None 이다.
  원본 isVisible 은 활성이고 불투명도가 0 보다 큰 것이다. 러스트 판은 그리기를 끄는 보이기 플래그(set_visible)가 따로 있어 그것까지 본다.
- 원본 Node 의 계층 함수는 같은 이름으로 둔다. 노드 객체를 주고받는 자리는 NodeId 이고, 이름 끝에 _id(_ids)가 붙은 것은 핸들을 돌려주는 짝이다.
  (getParent → get_parent_id, getChildren → get_child_ids, getSiblings → get_sibling_ids) 부모에서 떼는 것(remove_child)은 노드를 지우지 않는다.
- 원본 WorldNode.getPosition, setPosition, getWorldCorners, getWorldBounds 도 노드 핸들을 받아 한다. 전역 위치는 원본처럼 부모 피벗 기준으로 셈한
  피벗 점의 자리이고, 네 모서리는 그 전역 위치와 전역 크기, 전역 회전으로 셈한다.

## NodeTree (struct) (Default, Index<NodeId>, IndexMut<NodeId>)

노드 트리.
- 씬마다 하나 든다. (SceneBase::get_node_tree_mut) 노드는 NodeId 로 꺼내고, `node_tree[node_id]` 는 지운 노드면 멈춘다.

예제: 층 노드 밑에 노드를 만들고 찾고 지우기

```rust
use vanilla::NodeTree;

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let layer_id = node_tree.create_child(root_id, "layer");
let player_id = node_tree.create_child(layer_id, "player");
assert_eq!(node_tree.find_descendant_by_name(root_id, "player"), Some(player_id));
assert_eq!(node_tree[player_id].get_parent_id(), Some(layer_id));
node_tree.destroy_node(layer_id);
assert!(node_tree.get_node(player_id).is_none());
assert_eq!(node_tree.get_node_count(), 1);
```

- `pub fn new() -> NodeTree` (constructor, since 0.3.2): 생성. (루트 노드 "root" 를 함께 만든다. 루트의 피봇은 왼쪽 위)
  - returns NodeTree: 루트 노드 하나만 든 트리.
- `pub fn get_root_id(&self) -> NodeId` (method, since 0.3.2): 루트 노드 핸들.
  - returns NodeId: 루트 노드 핸들. (루트는 지울 수 없다)
- `pub fn get_node_count(&self) -> usize` (method, since 0.3.2): 노드 수. (루트와 아직 트리에 붙지 않은 노드까지)
  - returns usize: 든 노드 수. (루트와 아직 붙지 않은 노드까지)
- `pub fn contains(&self, node_id: NodeId) -> bool` (method, since 0.3.2): 노드가 살아 있는지.
  - `node_id` NodeId: 볼 노드.
  - returns bool: 지우지 않은 노드면 true.
- `pub fn get_node(&self, node_id: NodeId) -> Option<&WorldNode>` (method, since 0.3.2): 노드 반환.
  - `node_id` NodeId: 꺼낼 노드.
  - returns Option<&WorldNode>: 노드. 지웠거나 모르는 핸들이면 None.
- `pub fn get_node_mut(&mut self, node_id: NodeId) -> Option<&mut WorldNode>` (method, since 0.3.2): 노드 반환. (변경용)
  - `node_id` NodeId: 꺼낼 노드.
  - returns Option<&mut WorldNode>: 노드. (변경용) 지웠거나 모르는 핸들이면 None.
- `pub fn create_node(&mut self, name: &str) -> NodeId` (method, since 0.3.2): 노드 만들기. (아직 어느 부모에도 붙지 않는다. add_child 로 붙여야 그려진다)
  - `name` &str: 노드 이름.
  - returns NodeId: 새 노드 핸들.
- `pub fn create_child(&mut self, parent_id: NodeId, name: &str) -> NodeId` (method, since 0.3.2): 자식 노드 만들기. (만들어서 parent_id 의 맨 뒤 자식으로 붙인다)
  - `parent_id` NodeId: 붙일 부모.
  - `name` &str: 노드 이름.
  - returns NodeId: 새 노드 핸들. (parent_id 가 없는 노드면 붙지 않은 채로 남는다)
- `pub fn add_child(&mut self, parent_id: NodeId, child_id: NodeId) -> bool` (method, since 0.3.2): 자식 붙이기. (맨 뒤. 다른 부모에 붙어 있으면 떼어서 옮긴다)
  - 자기 자신이나 자기 조상 밑으로는 붙이지 않는다. (false)
  - `parent_id` NodeId: 부모가 될 노드.
  - `child_id` NodeId: 붙일 노드.
  - returns bool: 붙였으면 true. 둘 가운데 하나가 없거나, child_id 가 루트거나, child_id 가 parent_id 자신이나 조상이면 false.
- `pub fn insert_child(&mut self, parent_id: NodeId, child_id: NodeId, child_index: usize) -> bool` (method, since 0.3.2): 자식 끼워 넣기. (child_index 자리, 자식 수보다 크면 맨 뒤)
  - `parent_id` NodeId: 부모가 될 노드.
  - `child_id` NodeId: 끼울 노드.
  - `child_index` usize: 끼울 자리. (0 부터, 앞일수록 먼저 그려진다)
  - returns bool: 끼웠으면 true. 막히는 경우는 add_child 와 같다.

  예제: 맨 앞에 끼워 가장 먼저(뒤에 깔리게) 그리기

  ```rust
  use vanilla::NodeTree;
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let player_id = node_tree.create_child(root_id, "player");
  let background_id = node_tree.create_node("background");
  assert!(node_tree.insert_child(root_id, background_id, 0));
  assert_eq!(node_tree.get_child_ids(root_id), &[background_id, player_id]);
  assert!(!node_tree.insert_child(player_id, root_id, 0));
  ```

- `pub fn remove_from_parent(&mut self, child_id: NodeId)` (method, since 0.3.2): 부모에서 떼기. (노드는 지우지 않는다. 다시 add_child 할 수 있다)
  - `child_id` NodeId: 뗄 노드. (부모가 없거나 없는 노드면 아무것도 하지 않는다)
- `pub fn set_parent(&mut self, child_id: NodeId, parent_id: Option<NodeId>) -> bool` (method, since 0.4.0): 부모 설정. (None 이면 부모에서 뗀다, 자기 자신이나 자손 밑으로는 붙이지 않는다, 원본 setParent)
  - `child_id` NodeId: 옮길 노드.
  - `parent_id` Option<NodeId>: 새 부모. None 이면 부모에서 뗀다.
  - returns bool: 붙였거나, 이미 그 부모의 자식이거나(자리는 그대로), 뗐으면 true. add_child 가 막는 경우는 false.
- `pub fn remove_child(&mut self, parent_id: NodeId, child_id: NodeId)` (method, since 0.4.0): 자식 떼기. (그 부모의 자식일 때만, 노드는 지우지 않는다, 원본 removeChild)
  - `parent_id` NodeId: 부모.
  - `child_id` NodeId: 뗄 자식. (parent_id 의 자식이 아니면 아무것도 하지 않는다)
- `pub fn remove_child_at(&mut self, parent_id: NodeId, child_index: usize)` (method, since 0.4.0): 그 자리의 자식 떼기. (원본 removeChildAt)
  - `parent_id` NodeId: 부모.
  - `child_index` usize: 뗄 자식의 자리. (0 부터, 범위 밖이면 아무것도 하지 않는다)
- `pub fn remove_children(&mut self, parent_id: NodeId)` (method, since 0.4.0): 모든 자식 떼기. (바로 아래만 떼고 자식들의 계층은 그대로, 원본 removeChildren)
  - `parent_id` NodeId: 자식을 뗄 부모.
- `pub fn remove_child_by_name(&mut self, parent_id: NodeId, name: &str)` (method, since 0.4.0): 이름으로 자식 떼기. (바로 아래 처음 하나, 원본 removeChildByName)
  - `parent_id` NodeId: 부모.
  - `name` &str: 뗄 자식 이름.
- `pub fn destroy_node(&mut self, node_id: NodeId)` (method, since 0.3.2): 노드 지우기. (자손까지. 루트는 지우지 않는다)
  - tick / 터치를 도는 중이면 비활성으로 두고 다 돈 뒤에 지운다.
  - `node_id` NodeId: 지울 노드. (루트이거나 없는 노드면 아무것도 하지 않는다)
- `pub fn destroy_children(&mut self, parent_id: NodeId)` (method, since 0.3.2): 자식 모두 지우기.
  - 바로 아래 자식마다 destroy_node 를 부른다. (자손까지 지운다)
  - `parent_id` NodeId: 자식을 지울 부모.
- `pub fn destroy_children_where(&mut self, parent_id: NodeId, predicate: impl Fn(&WorldNode) -> bool) -> usize` (method, since 0.3.2): 조건에 맞는 자식 지우기. (지운 수)
  - `parent_id` NodeId: 자식을 지울 부모.
  - `predicate` impl Fn(&WorldNode) -> bool: 바로 아래 자식마다 불러 지울 것이면 true 를 돌려주는 조건.
  - returns usize: 지운 자식 수.

  예제: 이름이 enemy 인 자식만 지우기

  ```rust
  use vanilla::NodeTree;
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  for name in ["enemy", "item", "enemy"] {
  	node_tree.create_child(root_id, name);
  }
  let destroyed_count = node_tree.destroy_children_where(root_id, |node| node.get_name() == "enemy");
  assert_eq!(destroyed_count, 2);
  assert_eq!(node_tree.get_child_count(root_id), 1);
  ```

- `pub fn get_parent_id(&self, node_id: NodeId) -> Option<NodeId>` (method, since 0.3.2): 부모 핸들.
  - `node_id` NodeId: 볼 노드.
  - returns Option<NodeId>: 부모 핸들. 루트, 붙지 않은 노드, 없는 노드면 None.
- `pub fn get_child_ids(&self, node_id: NodeId) -> &[NodeId]` (method, since 0.3.2): 자식 핸들 목록. (그리는 순서)
  - `node_id` NodeId: 볼 노드.
  - returns &[NodeId]: 자식 핸들 목록. (앞이 먼저 그려진다) 없는 노드면 빈 목록.
- `pub fn get_child_count(&self, node_id: NodeId) -> usize` (method, since 0.3.2): 자식 수.
  - `node_id` NodeId: 볼 노드.
  - returns usize: 바로 아래 자식 수. 없는 노드면 0.
- `pub fn get_child_index(&self, parent_id: NodeId, child_id: NodeId) -> Option<usize>` (method, since 0.4.0): 자식의 자리. (그리는 순서의 번호, parent_id 의 자식이 아니면 None)
  - `parent_id` NodeId: 부모.
  - `child_id` NodeId: 찾을 자식.
  - returns Option<usize>: 그리는 순서의 번호. (0 부터) parent_id 의 자식이 아니면 None.
- `pub fn get_sibling_ids(&self, node_id: NodeId) -> Option<&[NodeId]>` (method, since 0.4.0): 형제 목록. (자기 자신을 포함한 부모의 자식 핸들, 부모가 없으면 None)
  - `node_id` NodeId: 볼 노드.
  - returns Option<&[NodeId]>: 자기를 포함한 형제 핸들 목록. (그리는 순서) 부모가 없으면 None.
- `pub fn get_sibling_index(&self, node_id: NodeId) -> Option<usize>` (method, since 0.4.0): 형제 사이의 자리. (부모가 없으면 None)
  - `node_id` NodeId: 볼 노드.
  - returns Option<usize>: 형제 사이의 번호. (0 부터) 부모가 없으면 None.
- `pub fn set_sibling_index(&mut self, node_id: NodeId, child_index: usize)` (method, since 0.4.0): 형제 사이의 자리 설정. (자식 수 - 1 까지로 자르고, 그 자리로 옮긴다. 부모가 없으면 아무것도 하지 않는다)
  - 앞일수록 먼저 그려져 뒤에 깔린다.
  - `node_id` NodeId: 옮길 노드.
  - `child_index` usize: 새 자리. (0 부터, 자식 수 - 1 을 넘으면 맨 뒤)

  예제: 앞으로 옮겼다가 맨 뒤(맨 위에 그려지게)로 보내기

  ```rust
  use vanilla::NodeTree;
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let back_id = node_tree.create_child(root_id, "back");
  let front_id = node_tree.create_child(root_id, "front");
  node_tree.set_sibling_index(front_id, 0);
  assert_eq!(node_tree.get_child_ids(root_id), &[front_id, back_id]);
  node_tree.set_sibling_index(front_id, 100);
  assert_eq!(node_tree.get_sibling_index(front_id), Some(1));
  ```

- `pub fn is_active_in_hierarchy(&self, node_id: NodeId) -> bool` (method, since 0.4.0): 자기부터 루트까지 모두 활성인지. (하나라도 꺼져 있으면 false, 없는 노드도 false)
  - `node_id` NodeId: 볼 노드.
  - returns bool: 자기와 조상이 모두 활성이면 true.
- `pub fn is_visible_in_hierarchy(&self, node_id: NodeId) -> bool` (method, since 0.4.0): 자기부터 루트까지 모두 보이는지. (활성, 보이기 플래그, 불투명도 > 0 가운데 하나라도 아니면 false, 없는 노드도 false)
  - `node_id` NodeId: 볼 노드.
  - returns bool: 자기와 조상이 모두 활성이고 보이기가 켜져 있고 불투명도가 0 보다 크면 true.
- `pub fn is_ancestor_or_self(&self, ancestor_id: NodeId, node_id: NodeId) -> bool` (method, since 0.3.2): ancestor_id 가 node_id 자신이거나 조상인지.
  - `ancestor_id` NodeId: 조상인지 볼 노드.
  - `node_id` NodeId: 기준 노드.
  - returns bool: ancestor_id 가 node_id 자신이거나 그 조상이면 true.
- `pub fn find_child(&self, parent_id: NodeId, predicate: impl Fn(&WorldNode) -> bool) -> Option<NodeId>` (method, since 0.4.0): 조건으로 자식 찾기. (바로 아래만, 처음 하나, 원본 findChild)
  - `parent_id` NodeId: 찾을 부모.
  - `predicate` impl Fn(&WorldNode) -> bool: 찾는 노드면 true 를 돌려주는 조건.
  - returns Option<NodeId>: 처음 맞는 바로 아래 자식. 없으면 None.
- `pub fn find_child_recursive(&self, parent_id: NodeId, predicate: &dyn Fn(&WorldNode) -> bool) -> Option<NodeId>` (method, since 0.4.0): 조건으로 자손 찾기. (깊이 우선, 그리는 순서로 처음 하나, 원본 findChildRecursive)
  - `parent_id` NodeId: 찾을 조상. (자신은 보지 않는다)
  - `predicate` &dyn Fn(&WorldNode) -> bool: 찾는 노드면 true 를 돌려주는 조건. (`&|node| ...` 꼴로 넘긴다)
  - returns Option<NodeId>: 처음 맞는 자손. 없으면 None.

  예제: 터치를 받는 자손 찾기

  ```rust
  use vanilla::NodeTree;
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let panel_id = node_tree.create_child(root_id, "panel");
  let button_id = node_tree.create_child(panel_id, "button");
  node_tree[button_id].set_interactable(true);
  assert_eq!(node_tree.find_child_recursive(root_id, &|node| node.is_interactable()), Some(button_id));
  assert_eq!(node_tree.find_child(root_id, |node| node.is_interactable()), None);
  ```

- `pub fn find_child_recursive_by_name(&self, parent_id: NodeId, name: &str) -> Option<NodeId>` (method, since 0.4.0): 이름으로 자손 찾기. (원본 findChildRecursiveByName, find_descendant_by_name 과 같다)
  - `parent_id` NodeId: 찾을 조상. (자신은 보지 않는다)
  - `name` &str: 찾을 이름.
  - returns Option<NodeId>: 처음 맞는 자손. (깊이 우선, 그리는 순서) 없으면 None.
- `pub fn find_child_by_name(&self, parent_id: NodeId, name: &str) -> Option<NodeId>` (method, since 0.3.2): 이름으로 자식 찾기. (바로 아래만, 처음 하나)
  - `parent_id` NodeId: 찾을 부모.
  - `name` &str: 찾을 이름.
  - returns Option<NodeId>: 처음 맞는 바로 아래 자식. 없으면 None.
- `pub fn find_descendant_by_name(&self, parent_id: NodeId, name: &str) -> Option<NodeId>` (method, since 0.3.2): 이름으로 자손 찾기. (깊이 우선, 그리는 순서로 처음 하나)
  - `parent_id` NodeId: 찾을 조상. (자신은 보지 않는다)
  - `name` &str: 찾을 이름.
  - returns Option<NodeId>: 처음 맞는 자손. (깊이 우선, 그리는 순서) 없으면 None.
- `pub fn get_position(&self, node_id: NodeId) -> Vector2` (method, since 0.4.0): 전역 위치. (피벗 점의 전역 위치, 원본 WorldNode.getPosition)
  - 로컬 위치는 부모 내용 영역의 왼쪽 위에서 본 자리라, 부모 피벗 점(부모 내용 크기 x 부모 피벗) 기준으로 옮긴 뒤 부모의 전역 회전과 크기를 걸고
    부모 피벗 점의 전역 위치에 더한다. (앵커는 넣지 않는다) 그리는 변환(calculate_world_matrix)이 피벗 점을 놓는 자리와 같다.
  - `node_id` NodeId: 볼 노드. (없는 노드면 멈춘다)
  - returns Vector2: 피벗 점의 전역 위치. (루트 아래 노드면 뷰 좌표)

  예제: 전역 위치를 읽고 전역 위치로 옮기기

  ```rust
  use vanilla::{NodeTree, Vector2};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let parent_id = node_tree.create_child(root_id, "parent");
  let child_id = node_tree.create_child(parent_id, "child");
  node_tree[parent_id].set_local_position(Vector2::create(100.0, 50.0));
  node_tree[child_id].set_local_position(Vector2::create(10.0, 20.0));
  assert_eq!(node_tree.get_position(child_id), Vector2::create(110.0, 70.0));
  node_tree.set_position(child_id, Vector2::create(200.0, 100.0));
  assert_eq!(node_tree[child_id].get_local_position(), Vector2::create(100.0, 50.0));
  ```

- `pub fn set_position(&mut self, node_id: NodeId, position: Vector2)` (method, since 0.4.0): 전역 위치 설정. (부모가 없으면 로컬 위치, get_position 의 거꾸로. 원본 WorldNode.setPosition)
  - 부모 피벗 점의 전역 위치에서 본 차이를 부모의 전역 회전과 크기를 풀어 부모 피벗 점 기준으로 되돌리고, 부모 내용 영역의 왼쪽 위 기준(로컬 위치)으로 옮긴다.
  - 부모의 전역 크기가 0 인 축은 부모 피벗 점에 놓는다.
  - `node_id` NodeId: 옮길 노드. (없는 노드면 멈춘다)
  - `position` Vector2: 피벗 점이 갈 전역 위치.
- `pub fn get_scale(&self, node_id: NodeId) -> Vector2` (method, since 0.4.0): 전역 크기. (부모들의 크기를 곱한다, 원본 TransformNode.getScale)
  - `node_id` NodeId: 볼 노드. (없는 노드면 멈춘다)
  - returns Vector2: 전역 배율. (자기와 조상의 로컬 배율을 곱한 것)
- `pub fn read_position(&self, node_id: NodeId, out: &mut Vector2)` (method, since 0.4.0): 전역 위치를 out 에 적는다. (원본 WorldNode.readPosition, TransformNode.readPosition, get_position 과 같은 값)
  - `node_id` NodeId: 볼 노드. (없는 노드면 멈춘다)
  - `out` &mut Vector2: 적을 자리.
- `pub fn read_scale(&self, node_id: NodeId, out: &mut Vector2)` (method, since 0.4.0): 전역 배율을 out 에 적는다. (원본 TransformNode.readScale, get_scale 과 같은 값)
  - `node_id` NodeId: 볼 노드. (없는 노드면 멈춘다)
  - `out` &mut Vector2: 적을 자리.
- `pub fn set_scale(&mut self, node_id: NodeId, scale: Vector2)` (method, since 0.4.0): 전역 크기 설정. (부모의 전역 크기로 나눈다, 0 이면 0, 원본 TransformNode.setScale)
  - `node_id` NodeId: 바꿀 노드. (없는 노드면 멈춘다)
  - `scale` Vector2: 전역 배율.
- `pub fn get_rotation(&self, node_id: NodeId) -> f64` (method, since 0.4.0): 전역 회전. (도, 부모들의 회전을 더한다, 원본 TransformNode.getRotation)
  - `node_id` NodeId: 볼 노드. (없는 노드면 멈춘다)
  - returns f64: 전역 회전. (도, 자기와 조상의 로컬 회전을 더한 것)
- `pub fn set_rotation(&mut self, node_id: NodeId, rotation: f64)` (method, since 0.4.0): 전역 회전 설정. (도, 원본 TransformNode.setRotation)
  - `node_id` NodeId: 바꿀 노드. (없는 노드면 멈춘다)
  - `rotation` f64: 전역 회전. (도)
- `pub fn get_opacity(&self, node_id: NodeId) -> f64` (method, since 0.4.0): 전역 투명도. (부모들의 투명도를 곱한다, 원본 TransformNode.getOpacity)
  - `node_id` NodeId: 볼 노드. (없는 노드면 멈춘다)
  - returns f64: 전역 불투명도. (0 ~ 1, 자기와 조상의 로컬 불투명도를 곱한 것)
- `pub fn get_world_corners(&self, node_id: NodeId) -> [Vector2; 4]` (method, since 0.4.0): 실제 화면에 그려지는 영역의 네 모서리. (원본 WorldNode.getWorldCorners, OBB. 왼쪽 위, 오른쪽 위, 오른쪽 아래, 왼쪽 아래)
  - 크기는 전역 크기의 절댓값을 곱하고, 피벗 점의 전역 위치를 중심으로 전역 회전만큼 돌린다.
  - `node_id` NodeId: 볼 노드. (없는 노드면 멈춘다)
  - returns [Vector2; 4]: 네 모서리. (뷰 좌표, 왼쪽 위, 오른쪽 위, 오른쪽 아래, 왼쪽 아래 차례)

  예제: 가운데 피봇 노드의 모서리와 감싸는 사각형

  ```rust
  use vanilla::{NodeTree, Rect, Vector2};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let node_id = node_tree.create_child(root_id, "box");
  node_tree[node_id].set_local_position(Vector2::create(100.0, 100.0));
  node_tree[node_id].set_content_size(Vector2::create(40.0, 20.0));
  let world_corners = node_tree.get_world_corners(node_id);
  assert_eq!(world_corners[0], Vector2::create(80.0, 90.0));
  assert_eq!(world_corners[2], Vector2::create(120.0, 110.0));
  assert_eq!(node_tree.get_world_bounds(node_id), Rect::create(80.0, 90.0, 40.0, 20.0));
  ```

- `pub fn get_world_bounds(&self, node_id: NodeId) -> Rect` (method, since 0.4.0): 네 모서리를 감싸는 사각형. (원본 WorldNode.getWorldBounds)
  - `node_id` NodeId: 볼 노드. (없는 노드면 멈춘다)
  - returns Rect: 네 모서리를 감싸는 축 정렬 사각형. (뷰 좌표)
- `pub fn calculate_world_matrix(&self, node_id: NodeId) -> TransformMatrix` (method, since 0.3.2): 월드 행렬. (루트부터 이 노드까지 로컬 행렬을 곱한 것. 루트의 부모 좌표계 = 뷰 좌표계)
  - `node_id` NodeId: 볼 노드.
  - returns TransformMatrix: 이 노드 내용 좌표의 점을 뷰 좌표로 옮기는 행렬. 없는 노드면 단위 행렬.
- `pub fn convert_node_position_to_view_position(&self, node_id: NodeId, node_position: Vector2) -> Vector2` (method, since 0.3.2): 노드 영역 안의 점 → 뷰 좌표.
  - `node_id` NodeId: 기준 노드.
  - `node_position` Vector2: 노드 내용 좌표의 점. (내용 영역의 왼쪽 위가 원점)
  - returns Vector2: 뷰 좌표의 점.
- `pub fn convert_view_position_to_node_position(&self, node_id: NodeId, view_position: Vector2) -> Option<Vector2>` (method, since 0.3.2): 뷰 좌표 → 노드 영역 안의 점. (행렬이 뒤집히지 않으면 None)
  - `node_id` NodeId: 기준 노드.
  - `view_position` Vector2: 뷰 좌표의 점.
  - returns Option<Vector2>: 노드 내용 좌표의 점. 행렬을 뒤집을 수 없으면(배율 0) None.
- `pub fn convert_view_to_local(&self, node_id: NodeId, view_position: Vector2) -> Option<Vector2>` (method, since 0.4.0): 뷰 좌표 → 노드의 로컬 좌표. (내용 영역의 왼쪽 위가 원점, 부모들의 변환을 모두 거친다, 원본 WorldNode.convertViewToLocal)
  - convert_view_position_to_node_position 과 같다. 행렬이 뒤집히지 않으면(배율 0) None.
  - `node_id` NodeId: 기준 노드.
  - `view_position` Vector2: 뷰 좌표의 점.
  - returns Option<Vector2>: 노드 내용 좌표의 점. 행렬을 뒤집을 수 없으면(배율 0) None.

  예제: 터치 자리를 패널 안의 자리로 바꾸기

  ```rust
  use vanilla::{NodeTree, Pivot, Vector2};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let panel_id = node_tree.create_child(root_id, "panel");
  node_tree[panel_id].set_pivot(Pivot::TOP_LEFT);
  node_tree[panel_id].set_rect(100.0, 50.0, 200.0, 100.0);
  assert_eq!(node_tree.convert_view_to_local(panel_id, Vector2::create(110.0, 60.0)), Some(Vector2::create(10.0, 10.0)));
  node_tree[panel_id].set_local_scale(Vector2::zero());
  assert_eq!(node_tree.convert_view_to_local(panel_id, Vector2::create(110.0, 60.0)), None);
  ```

- `pub fn tick(&mut self, engine: &Engine, time_delta: f64)` (method, since 0.3.2): 주기적 갱신. (루트부터 깊이 우선: 컴포넌트 → 자식 순, 원본 ComponentNode.tick)
  - 도는 중에 지운 노드는 다 돈 뒤에 지운다.
  - `engine` &Engine: 컴포넌트 문맥에 넘길 엔진.
  - `time_delta` f64: 지난 tick 뒤로 흐른 시간. (초)
- `pub fn add_component<T: Component + 'static>(&mut self, node_id: NodeId, component: T) -> Option<&mut T>` (method, since 0.3.2): 컴포넌트 붙이기. (attach 다음 attach_to_tree 를 불러, 컴포넌트가 자식 노드를 만들 수 있게 한다)
  - UIView 처럼 자식 노드를 만드는 컴포넌트는 이것으로 붙인다. 붙인 컴포넌트를 돌려준다.
  - 원본 addComponent 처럼 자기 자리를 먼저 잡고, 의존 컴포넌트(require)가 노드에 없으면 같은 길로 붙인 다음 붙는다.
  - 의존 컴포넌트와 붙는 동안 함께 붙인 컴포넌트(UIScrollView 의 Mask 같은 것)는 그 뒤에 온다.
  - `node_id` NodeId: 붙일 노드.
  - `component` T: 붙일 컴포넌트.
  - returns Option<&mut T>: 붙인 컴포넌트. (변경용) 노드가 없으면 None.

  예제: 붙인 컴포넌트를 돌려받고, 지운 노드에는 붙지 않는다

  ```rust
  use vanilla::{NodeTree, Paint};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let node_id = node_tree.create_child(root_id, "panel");
  let paint = node_tree.add_component(node_id, Paint::new()).expect("node");
  paint.set_round_size(12.0);
  assert_eq!(node_tree[node_id].get_component::<Paint>().expect("paint").get_round_size(), 12.0);
  node_tree.destroy_node(node_id);
  assert!(node_tree.add_component(node_id, Paint::new()).is_none());
  ```

- `pub fn with_component_mut<T: Component + 'static, R>(&mut self, node_id: NodeId, action: impl FnOnce(&mut T, &mut NodeTree) -> R) -> Option<R>` (method, since 0.3.2): 컴포넌트 하나를 트리와 함께 쥐고 부르기. (씬 코드에서 위젯처럼 다른 노드도 만지는 컴포넌트를 바로 바꿀 때)
  - node_id 노드의 첫 번째 T 컴포넌트만 잠깐 빼고, 그 컴포넌트와 트리를 action 에 넘긴다. 없으면 None.
  - 예: node_tree.`with_component_mut::<UIScrollView, _>`(scroll_id, |scroll_view, tree| scroll_view.set_scroll_offset_in_tree(tree, scroll_id, offset))
  - action 안에서 지운 노드는 action 이 끝난 뒤에 지운다.
  - `node_id` NodeId: 컴포넌트가 붙은 노드.
  - `action` impl FnOnce(&mut T, &mut NodeTree) -> R: 꺼낸 컴포넌트와 트리를 받아 부를 함수. (그동안 그 컴포넌트는 노드에서 빠져 있다)
  - returns Option<R>: action 이 돌려준 값. 노드가 없거나 T 컴포넌트가 없으면 None.

  예제: 컴포넌트를 바꾸면서 트리에 노드 만들기

  ```rust
  use vanilla::{NodeTree, Paint};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let node_id = node_tree.create_child(root_id, "panel");
  node_tree[node_id].add_component(Paint::new());
  let shadow_id = node_tree.with_component_mut::<Paint, _>(node_id, |paint, tree| {
  	paint.set_round_size(4.0);
  	tree.create_child(node_id, "shadow")
  }).expect("paint");
  assert_eq!(node_tree.get_parent_id(shadow_id), Some(node_id));
  assert_eq!(node_tree[node_id].get_component::<Paint>().expect("paint").get_round_size(), 4.0);
  ```

- `pub fn with_component_at_mut<R>(&mut self, node_id: NodeId, component_index: usize, action: impl FnOnce(&mut dyn Component, &mut NodeTree) -> R) -> Option<R>` (method, since 0.4.0): 차례 번호로 컴포넌트 하나를 트리와 함께 쥐고 부르기. (종류를 모르는 자리, UIDocument 가 트리를 받는 반사 세터를 부를 때)
  - node_id 노드의 component_index 번째 컴포넌트를 잠깐 빼고, 그 컴포넌트와 트리를 action 에 넘긴다. 없으면 None.
  - `node_id` NodeId: 컴포넌트가 붙은 노드.
  - `component_index` usize: 컴포넌트 자리. (붙인 차례, 0 부터)
  - `action` impl FnOnce(&mut dyn Component, &mut NodeTree) -> R: 꺼낸 컴포넌트와 트리를 받아 부를 함수.
  - returns Option<R>: action 이 돌려준 값. 노드가 없거나 자리가 범위 밖이면 None.

  예제: 종류를 모르는 첫 컴포넌트의 이름 읽기

  ```rust
  use vanilla::{NodeTree, Paint};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let node_id = node_tree.create_child(root_id, "panel");
  node_tree[node_id].add_component(Paint::new());
  let component_type = node_tree.with_component_at_mut(node_id, 0, |component, _tree| component.get_component_type());
  assert_eq!(component_type, Some("Paint"));
  assert!(node_tree.with_component_at_mut(node_id, 1, |_component, _tree| ()).is_none());
  ```

- `pub fn draw(&mut self, graphic: &mut Graphic)` (method, since 0.3.2): 출력. (루트부터 재귀, 원본 Graphic.drawNode)
  - `graphic` &mut Graphic: 그릴 Graphic. (화면 밖이라 건너뛴 노드 수를 더해 둔다)
- `pub fn draw_node(&mut self, node_id: NodeId, graphic: &mut Graphic)` (method, since 0.3.2): 노드 하나와 그 자손 출력.
  - push_transform → 컴포넌트의 push_transform → (투명도 층 시작) → 컴포넌트 → (Mask 면 클립 시작) → 자식 → (클립 끝) → (투명도 층 끝) → 기즈모 → 컴포넌트의 pop_transform → pop_transform
  - `node_id` NodeId: 그릴 노드. (없거나 비활성이면 그리지 않는다)
  - `graphic` &mut Graphic: 그릴 Graphic. (부모의 트랜스폼이 걸린 상태)
- `pub fn draw_children(&mut self, node_id: NodeId, graphic: &mut Graphic)` (method, since 0.4.0): 자식 목록 출력. (자식 차례대로 draw_node, draw_node 가 부른다, 원본 TransformNode.drawChildren)
  - 하위 트리 거르기가 켜졌으면 부모 좌표의 보이는 사각형(Graphic::read_local_visible_bounds)으로 보이는 자식 범위를 이분 찾기로 좁혀 그 앞뒤 자식은 부르지 않는다.
    범위 밖 자식 가운데 하나씩 거를 때 셀 것은 Graphic::add_culled_subtree_count 로 더한다. (건너뛴 하위 트리 수가 하나씩 거를 때와 같다)
  - 지금 변환은 이 노드의 내용 좌표여야 한다. (push_transform 을 건 뒤)
  - `node_id` NodeId: 자식을 그릴 노드.
  - `graphic` &mut Graphic: 그릴 Graphic.

  예제: 화면 밖 자식은 부르지 않는다

  ```rust
  use vanilla::{NodeTree, Paint, Pivot};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let list_id = node_tree.create_child(root_id, "list");
  node_tree[list_id].set_pivot(Pivot::TOP_LEFT);
  for row_index in 0..100 {
  	let row_id = node_tree.create_child(list_id, "row");
  	node_tree[row_id].set_pivot(Pivot::TOP_LEFT);
  	node_tree[row_id].set_rect(0.0, row_index as f64 * 40.0, 200.0, 36.0);
  	node_tree.add_component(row_id, Paint::new());
  }
  assert_eq!(node_tree.get_child_count(list_id), 100);
  ```

- `pub fn read_subtree_draw_bounds(&mut self, node_id: NodeId, graphic: &mut Graphic) -> Option<Rect>` (method, since 0.4.0): 하위 트리 그리기 경계 읽기. (이 노드의 내용 좌표, push_transform 을 건 뒤의 좌표, 원본 TransformNode.readSubtreeDrawBounds)
  - 이 노드와 켜지고 보이는 자손이 그리는 곳을 모두 품는 사각형이다. 크기가 0 이면 아무것도 그리지 않는다.
  - 바뀐 때만 다시 셈하고 그 밖에는 셈해 둔 것을 준다. 그리기 순회가 이 사각형이 화면과 자르기 밖이면 하위 트리를 통째로 건너뛴다.
  - 자기 그림: 켜지고 그리는 컴포넌트(Component::is_draw_overridden)의 calculate_drawn_rect. 내용 영역 안에서만 그리는 컴포넌트는 내용 영역을 한 단위씩 넓혀 본다.
  - 자식: 자식의 경계를 자식의 변환(위치, 회전, 배율, 피봇)으로 옮긴 이 노드의 내용 좌표 경계 상자. 마스크로 잘라도 줄이지 않는다. (넉넉하게 본다)
  - `node_id` NodeId: 읽을 노드.
  - `graphic` &mut Graphic: 컴포넌트가 그리는 사각형을 셀 때 쓰는 Graphic. (글 크기 재기)
  - returns Option<Rect>: 경계. 어디에 그리는지 모르는 것(경계를 알리지 않는 컴포넌트, 기즈모를 그리는 노드)이 들거나 없는 노드면 None.

  예제: 자식 경계가 부모 좌표로 모인다

  ```rust
  use vanilla::{Graphic, NodeTree, Paint, Pivot, Rect};
  
  fn read_bounds(graphic: &mut Graphic) {
  	let mut node_tree = NodeTree::new();
  	let root_id = node_tree.get_root_id();
  	let list_id = node_tree.create_child(root_id, "list");
  	node_tree[list_id].set_pivot(Pivot::TOP_LEFT);
  	let row_id = node_tree.create_child(list_id, "row");
  	node_tree[row_id].set_pivot(Pivot::TOP_LEFT);
  	node_tree[row_id].set_rect(10.0, 20.0, 100.0, 30.0);
  	node_tree.add_component(row_id, Paint::new());
  	let bounds = node_tree.read_subtree_draw_bounds(list_id, graphic).expect("known");
  	assert_eq!(bounds, Rect::create(9.0, 19.0, 102.0, 32.0));
  	assert_eq!(node_tree.read_parent_draw_bounds(row_id), Some(Rect::create(9.0, 19.0, 102.0, 32.0)));
  }
  ```

- `pub fn read_parent_draw_bounds(&self, node_id: NodeId) -> Option<Rect>` (method, since 0.4.0): 부모가 셈해 둔 이 노드의 하위 트리 그리기 경계 읽기. (부모의 내용 좌표, 이 노드의 변환을 건 경계 상자, 원본 TransformNode.readParentDrawBounds)
  - 부모가 하위 트리 경계를 셈할 때 자식마다 옮겨 적어 둔 것이다. 이 노드의 변환이나 경계가 바뀌면 부모가 다시 셈하므로 그때까지 그대로 쓴다.
  - 그리기 순회가 부모의 변환 아래에서 이 사각형을 먼저 보아, 부모 좌표의 보이는 사각형 밖이면 이 노드에 변환을 걸지 않고 건너뛴다.
  - `node_id` NodeId: 읽을 노드.
  - returns Option<Rect>: 부모 좌표 경계. 부모가 아직 셈하지 않았거나 셈한 뒤 바뀌었거나, 이 노드가 어디에 그리는지 모르면 None. (아무것도 그리지 않으면 크기 0)
- `pub fn find_topmost_interactable_node(&self, view_position: Vector2) -> Option<NodeId>` (method, since 0.3.2): 그리는 순서로 돌며 점 아래 맨 위의 interactable 노드 찾기. (원본 TouchRecognizer 의 대상 고르기)
  - 비활성이거나 안 보이는 노드와 그 자손, 자르는(Mask) 노드 밖의 자손은 맞지 않는다.
  - `view_position` Vector2: 볼 점. (뷰 좌표)
  - returns Option<NodeId>: 점 아래에서 가장 나중에 그리는 터치 받는 노드. 없으면 None.

  예제: 겹친 두 노드 가운데 뒤에 그리는 것이 맞는다

  ```rust
  use vanilla::{NodeTree, Pivot, Vector2};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  for name in ["back", "front"] {
  	let node_id = node_tree.create_child(root_id, name);
  	node_tree[node_id].set_pivot(Pivot::TOP_LEFT);
  	node_tree[node_id].set_rect(0.0, 0.0, 100.0, 100.0);
  	node_tree[node_id].set_interactable(true);
  }
  let found_id = node_tree.find_topmost_interactable_node(Vector2::create(50.0, 50.0)).expect("node");
  assert_eq!(node_tree[found_id].get_name(), "front");
  assert_eq!(node_tree.find_topmost_interactable_node(Vector2::create(150.0, 50.0)), None);
  ```

- `pub fn dispatch_touch(&mut self, node_id: NodeId, engine: &Engine, touch_kind: TouchKind, view_input_position: Vector2)` (method, since 0.3.2): 터치 전달. (노드의 컴포넌트들에게)
  - 켜진 컴포넌트에게 붙인 차례로 부르고, 도는 중에 지운 노드는 다 돈 뒤에 지운다.
  - `node_id` NodeId: 터치를 받을 노드.
  - `engine` &Engine: 컴포넌트 문맥에 넘길 엔진.
  - `touch_kind` TouchKind: 부를 터치 함수의 종류.
  - `view_input_position` Vector2: 터치 자리. (뷰 좌표)
- `pub fn find_wheel_target_node(&self, view_position: Vector2) -> Option<NodeId>` (method, since 0.4.0): 그 자리에서 휠을 받을 노드 찾기. (find_topmost_interactable_node 와 같은 그리는 순서, 없으면 None)
  - 그 자리를 품은 노드 가운데 누를 수 있는 노드와 휠을 받는 칸(Component::is_wheel_receiver)의 노드를 보고 가장 앞(나중에 그리는 것)을 고른다.
    스크롤 칸이 가장 앞이면 그 칸의 노드다. (칸 안의 글이나 그림처럼 누를 수 없는 것 위에서 굴려도 칸이 받는다)
  - 누를 수 있는 노드가 가장 앞이면 그 노드다. (dispatch_wheel 이 부모 쪽으로 올라가며 묻는다, 스크롤 칸을 덮은 막이나 창이 휠을 가린다)
  - `view_position` Vector2: 볼 점. (뷰 좌표)
  - returns Option<NodeId>: 휠을 받을 노드. 없으면 None.
- `pub fn dispatch_wheel_at(&mut self, view_position: Vector2, engine: &Engine, wheel_delta: Vector2) -> bool` (method, since 0.4.0): 그 자리에 휠 전달. (find_wheel_target_node 로 찾은 노드부터 부모 쪽으로, 받아 쓴 컴포넌트가 있으면 true)
  - `view_position` Vector2: 휠을 굴린 자리. (뷰 좌표)
  - `engine` &Engine: 컴포넌트 문맥에 넘길 엔진.
  - `wheel_delta` Vector2: 휠 이동량. (픽셀, 내용을 아래로 넘기면 y 가 양수)
  - returns bool: 받아 쓴 컴포넌트가 있으면 true. 받을 노드가 없으면 false.
- `pub fn dispatch_wheel(&mut self, node_id: NodeId, engine: &Engine, wheel_delta: Vector2) -> bool` (method, since 0.3.2): 휠 전달. (node_id 자신부터 부모 쪽으로 올라가며 처음 받아 쓴 컴포넌트에서 멈춘다. 원본 touchWheel)
  - `node_id` NodeId: 처음 물을 노드.
  - `engine` &Engine: 컴포넌트 문맥에 넘길 엔진.
  - `wheel_delta` Vector2: 휠 이동량. (픽셀, 내용을 아래로 넘기면 y 가 양수)
  - returns bool: 받아 쓴 컴포넌트가 있으면 true.

  예제: 항목 위에서 굴린 휠을 목록 노드의 컴포넌트가 받는다

  ```rust
  use vanilla::{Component, ComponentBase, ComponentContext, Engine, EngineConfiguration, NodeTree, Vector2};
  
  struct Scroller {
  	component_base: ComponentBase,
  	scroll_offset: f64,
  }
  
  #[vanilla::reflect]
  impl Scroller {}
  
  #[vanilla::reflect]
  impl Component for Scroller {
  	fn wheel(&mut self, _context: &mut ComponentContext, wheel_delta: Vector2) -> bool {
  		self.scroll_offset += wheel_delta.y;
  		true
  	}
  }
  
  let engine = Engine::new(EngineConfiguration::new());
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let list_id = node_tree.create_child(root_id, "list");
  node_tree[list_id].add_component(Scroller {
  	component_base: ComponentBase::new(),
  	scroll_offset: 0.0,
  });
  let item_id = node_tree.create_child(list_id, "item");
  assert!(node_tree.dispatch_wheel(item_id, &engine, Vector2::create(0.0, 40.0)));
  assert_eq!(node_tree[list_id].get_component::<Scroller>().expect("scroller").scroll_offset, 40.0);
  assert!(!node_tree.dispatch_wheel(root_id, &engine, Vector2::create(0.0, 40.0)));
  ```

- `pub fn get_local_bounds(&self, node_id: NodeId) -> Option<Rect>` (method, since 0.3.2): 노드 경계 사각형을 부모 영역 기준으로. (회전 없을 때 정확, 충돌 검사 등)
  - `node_id` NodeId: 볼 노드.
  - returns Option<Rect>: 부모 내용 좌표의 경계 사각형. (NodeTransform::get_local_bounds) 없는 노드면 None.

## ComponentContext (struct)

컴포넌트 문맥. (tick / 터치 때 컴포넌트가 받는 것: 자기 노드, 트리 전체, 엔진)
- 원본 컴포넌트의 get_node(), get_node().getParent(), Engine.get_engine() 자리.

예제: tick 에서 트리의 다른 노드를 찾아 그 자리로 따라가기

```rust
use vanilla::{Component, ComponentBase, ComponentContext, Engine, EngineConfiguration, NodeTree, Vector2};

struct Follower {
	component_base: ComponentBase,
}

#[vanilla::reflect]
impl Follower {}

#[vanilla::reflect]
impl Component for Follower {
	fn tick(&mut self, context: &mut ComponentContext, _time_delta: f64) {
		let node_tree = context.get_node_tree();
		let root_id = node_tree.get_root_id();
		if let Some(target_id) = node_tree.find_descendant_by_name(root_id, "target") {
			let target_position = node_tree[target_id].get_local_position();
			context.get_transform_mut().set_local_position(target_position);
		}
	}
}

let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let target_id = node_tree.create_child(root_id, "target");
node_tree[target_id].set_local_position(Vector2::create(30.0, 40.0));
let follower_id = node_tree.create_child(root_id, "follower");
node_tree[follower_id].add_component(Follower {
	component_base: ComponentBase::new(),
});
node_tree.tick(&engine, 0.016);
assert_eq!(node_tree[follower_id].get_local_position(), Vector2::create(30.0, 40.0));
```

- `pub fn get_node_id(&self) -> NodeId` (method, since 0.3.2): 자기 노드 핸들.
  - returns NodeId: 자기 노드 핸들.
- `pub fn get_node(&self) -> &WorldNode` (method, since 0.3.2): 자기 노드. (지금 불리는 컴포넌트만 빠져 있고, 같은 노드의 다른 컴포넌트는 get_component 로 찾는다)
  - returns &WorldNode: 자기 노드. (지금 불리는 컴포넌트는 빠져 있다)
- `pub fn get_node_mut(&mut self) -> &mut WorldNode` (method, since 0.3.2): 자기 노드. (변경용)
  - returns &mut WorldNode: 자기 노드. (변경용, 지금 불리는 컴포넌트는 빠져 있다)
- `pub fn get_transform(&self) -> &NodeTransform` (method, since 0.3.2): 자기 노드 트랜스폼.
  - returns &NodeTransform: 자기 노드의 트랜스폼.
- `pub fn get_transform_mut(&mut self) -> &mut NodeTransform` (method, since 0.3.2): 자기 노드 트랜스폼. (변경용)
  - returns &mut NodeTransform: 자기 노드의 트랜스폼. (변경용)
- `pub fn get_node_tree(&self) -> &NodeTree` (method, since 0.3.2): 트리 전체.
  - returns &NodeTree: 트리 전체.
- `pub fn get_node_tree_mut(&mut self) -> &mut NodeTree` (method, since 0.3.2): 트리 전체. (변경용. 다른 노드를 바꾸거나 만들고 지울 때)
  - returns &mut NodeTree: 트리 전체. (변경용, 도는 중에 지운 노드는 다 돈 뒤에 지워진다)
- `pub fn get_engine(&self) -> &'a Engine` (method, since 0.3.2): 엔진. (입력, 시간, 뷰)
  - returns &'a Engine: 엔진.
- `pub fn with_component_mut<T: Component + 'static, R>(&mut self, node_id: NodeId, action: impl FnOnce(&mut T, &mut ComponentContext) -> R) -> Option<R>` (method, since 0.3.2): 다른 노드(또는 자기 노드)의 T 컴포넌트를 그 노드의 문맥과 함께 부르기. (없거나 지금 꺼내져 있으면 None)
  - 위젯 안의 행 버튼이 위젯 본체를 부를 때 쓴다: context.`with_component_mut::<UIDropdown, _>`(dropdown_id, |dropdown, dropdown_context| ...)
  - `node_id` NodeId: T 컴포넌트가 붙은 노드.
  - `action` impl FnOnce(&mut T, &mut ComponentContext) -> R: 꺼낸 컴포넌트와 그 노드의 문맥을 받아 부를 함수.
  - returns Option<R>: action 이 돌려준 값. 노드가 없거나, T 컴포넌트가 없거나, 지금 꺼내져 있으면 None.

  예제: 버튼 노드의 컴포넌트가 다른 노드의 셈 컴포넌트를 부르기

  ```rust
  use vanilla::{Component, ComponentBase, ComponentContext, Engine, EngineConfiguration, NodeId, NodeTree};
  
  struct Counter {
  	component_base: ComponentBase,
  	count: u32,
  }
  
  #[vanilla::reflect]
  impl Counter {}
  
  #[vanilla::reflect]
  impl Component for Counter {
  }
  
  struct Clicker {
  	component_base: ComponentBase,
  	counter_id: NodeId,
  }
  
  #[vanilla::reflect]
  impl Clicker {}
  
  #[vanilla::reflect]
  impl Component for Clicker {
  	fn tick(&mut self, context: &mut ComponentContext, _time_delta: f64) {
  		context.with_component_mut::<Counter, _>(self.counter_id, |counter, _counter_context| {
  			counter.count += 1;
  		});
  	}
  }
  
  let engine = Engine::new(EngineConfiguration::new());
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let counter_id = node_tree.create_child(root_id, "counter");
  node_tree[counter_id].add_component(Counter {
  	component_base: ComponentBase::new(),
  	count: 0,
  });
  let clicker_id = node_tree.create_child(root_id, "clicker");
  node_tree[clicker_id].add_component(Clicker {
  	component_base: ComponentBase::new(),
  	counter_id,
  });
  node_tree.tick(&engine, 0.016);
  assert_eq!(node_tree[counter_id].get_component::<Counter>().expect("counter").count, 1);
  ```

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

터치 종류. (NodeTree::dispatch_touch 가 컴포넌트의 어느 함수를 부를지)

- `Press`: 눌림. (Component::touch_press)
- `Moved`: 이동. (Component::touch_move)
- `Release`: 뗌. (Component::touch_release)
- `Cancel`: 취소. (Component::touch_cancel)
