# ui/uicontrol (vanilla-engine 0.4.0)

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

UI 컨트롤. (원본 ui/uicontrol.js 의 UIControl)
- 사용자 입력(터치)을 받는 위젯의 바탕. UIKit 의 UIControl 처럼 UIView 위에 선다.
- 원본은 UIView 를 상속하고 이름만 바꾼다. 러스트 판은 UIView 를 품고 content, 배경색을 넘겨준다.
  UIButton, UISlider 가 이것을 품는다.

## UIControl (struct) (Default, Component)

UI 컨트롤.
- UIView 를 품고 content 노드와 배경색을 넘겨준다. 터치를 받는 위젯(UIButton, UISlider)이 이것을 품는다.

예제: 노드에 붙여 content 노드와 배경색 쓰기

```rust
use vanilla::{Color, NodeTree, UIControl};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let control_id = node_tree.create_child(root_id, "control");
let control = node_tree.add_component(control_id, UIControl::new()).unwrap();
control.set_background_color("#334455");
assert!(control.get_content().is_some());
assert_eq!(control.get_background_color(), Color::from("#334455"));
assert_eq!(control.get_uiview().get_background_color(), control.get_background_color());
```

- `pub fn new() -> UIControl` (constructor, since 0.3.2): 생성.
  - returns UIControl: 새 컨트롤. (content 노드는 트리에 붙일 때 만든다)
- `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>: content 노드. 트리에 붙기 전이면 None.
- `pub fn set_background_color(&mut self, background_color: impl Into<Color>)` (method, since 0.3.2): 배경색 설정.
  - `background_color` impl Into<Color>: 배경색. (알파가 0 이면 칠하지 않는다)
- `pub fn get_background_color(&self) -> Color` (method, since 0.3.2): 배경색 반환.
  - returns Color: 배경색. (기본은 알파 0 인 흰색)
