# ui/uiinputfield (vanilla-engine 0.4.0)

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

입력 필드. (원본 ui/uiinputfield.js 의 UIInputField, BackgroundLayerRenderer, OverlayLayerRenderer)
- 글, 커서, 선택 영역, IME 조합 글과 밑줄, 포커스 테두리를 캔버스에 직접 그리고, 누르기와 끌기로 커서와 선택을 정한다.
- 원본은 WorldNode 를 상속한 노드이고, 글은 UILabel 자식 노드 두 개(값, 안내 글), 커서와 테두리는 오버레이 자식 노드가 그린다.
  러스트 판은 다른 위젯처럼 컴포넌트다. node_tree.add_component(node_id, UIInputField::new()) 로 붙인다.
  UIControl 을 품어 attach_to_tree 에서 content 노드를 만들고 호스트를 interactable 로 켠다. 피봇과 앵커는 원본처럼 왼쪽 위로 맞춘다.
  글은 Text 두 개(값, 안내 글)를 품어 그리고, 바탕(원본 Paint 컴포넌트)도 품은 Paint 로 그린다.
  층 순서는 원본과 같다: 바탕 → 선택 영역 → 글 → 조합 밑줄 → 커서 → 포커스 테두리. 한 컴포넌트가 한 번에 그려서
  씬 코드가 tick 밖에서 set_text 를 불러도 그 프레임에 바로 보인다. (자식 노드로 나누면 상태를 옮기느라 한 프레임 늦는다)
- 입력은 엔진의 글 입력 줄(core/textinput.rs)에서 받는다. 포커스를 가진, attach() 한 필드가 tick 에서 꺼내 쓴다.
  - 데스크탑: winit 의 KeyboardInput 과 Ime 이벤트. use_dom_input(원본 setUseDOMInput)이 켜진 필드가 포커스를 가질 때만 IME 가 켜진다.
  - 웹: 원본처럼 필드마다 숨긴 DOM <input> 을 필드 위에 둔다. (platform/web/textinput.rs) 값과 선택은 DOM 이 주인이고 필드가 따라간다.
    use_dom_input 이 꺼진 필드는 원본 캔버스 모드처럼 window keydown 으로 받는다.
- 원본과 다른 것:
  - 이벤트는 Box<dyn FnMut(&mut UIInputField, &mut ComponentContext)> 다. 원본 콜백은 값만 받는다. (값은 field.get_text())
  - setFont(FontFace) 는 set_font_family(등록한 폰트 이름) 로 바꿨다. setEngine 은 옮기지 않았다. (엔진은 문맥으로 받는다)
  - 공개 함수의 글자 자리(get_cursor_index, get_selection_start, get_selection_range, move_cursor, measure_index_at_local_x)와 max_length 는
    원본처럼 UTF-16 단위로 센다. 안에서는 문자(char) 단위로 들어 서로게이트 쌍(이모지 같은 글자)을 쪼개지 않는다.
    그래서 UTF-16 자리가 서로게이트 쌍 가운데면 그 글자 뒤로 본다. (원본도 같다) max_length 가 있으면 블링크 입력 칸처럼 넣는 글을 남은 길이까지만 넣는다.
  - 누른 자리 → 글자 자리는 draw 때 재 둔 글자 경계로 찾는다. (원본은 오프스크린 2D 캔버스로 그때그때 잰다)
  - 데스크탑에서는 use_dom_input 이 켜진 필드도 원본 DOM 모드처럼 필드 밖을 누르면 포커스를 잃는다. 포커스는 엔진에 하나뿐이다.
    (원본 캔버스 모드는 다른 필드를 눌러도 앞 필드가 포커스를 쥐고 있다. 러스트 판은 나중에 포커스를 얻은 필드만 남긴다)
  - 포커스를 잃을 때 조합 중이던 글은 확정해 값에 넣는다. (브라우저가 DOM 입력에 하는 일과 같다)
  - 문맥 메뉴(오른쪽 단추)는 원본처럼 엔진이 그린다. (UIInputFieldContextMenu, 웹과 데스크탑 같다) 루트의 마지막 자식 노드로 만들어 위에 그린다.
    항목은 원본처럼 잘라내기, 복사, 붙여넣기, 모두 선택이다. DOM 입력을 직접 누르게 한 필드(use_direct_touch)도 원본처럼 브라우저 편집 칸 메뉴 대신 같은 메뉴다.
    그 필드는 크롬 데스크탑 터치처럼 손가락 길게 누르기(650ms, 15 DIP 안)로 낱말을 고르고 터치 손잡이와 빠른 메뉴를 띄운다. (윈도우는 뗄 때 메뉴를 정한다)
  - 데스크탑 DOM 입력 필드는 원본 DOM 입력 칸처럼 되돌리기와 다시 하기를 한다. (Ctrl+Z, Ctrl+Shift+Z, Ctrl+Y, 맥은 Cmd, 블링크의 묶음 규칙, TextEditBuffer)
  - 데스크탑 한 줄 DOM 입력 필드는 블링크 입력 칸처럼 넣는 글의 끝 줄바꿈을 지우고 가운데 줄바꿈을 공백으로 바꾸고, 위와 page 위는 글 앞, 아래와 page 아래는 글 끝으로 옮긴다.
  - set_multiline(true) 면 크롬 textarea 같은 여러 줄 입력이다. (원본 엔진에는 없고, 원본은 Pane 의 textarea 프리셋으로 DOM textarea 를 쓴다)
    글은 white-space: pre-wrap, overflow-wrap: break-word 처럼 줄바꿈 문자와 폭으로 나눈다. (ui/textarealayout.rs, 줄 나눔 자리는 크롬처럼 유니코드 줄 나누기)
    Enter 는 줄을 넣고(글자 넣기 되돌리기 묶음), 위아래는 첫 위아래 이동 때의 가로 자리를 지키며(첫 줄 위는 글 앞, 마지막 줄 아래는 글 끝),
    Home 과 End 는 보이는 줄의 앞과 끝(맥은 Cmd + 왼쪽, 오른쪽도), Ctrl + Home, End(맥은 Cmd + 위, 아래)는 글 앞과 끝,
    PageUp, PageDown(맥은 Option 과 함께)은 보이는 높이의 87.5%(맥은 높이 - 40 과 견줘 큰 쪽) 안의 가장 먼 줄로 옮겨 그 줄을 맨 위로 올린다.
    넣는 글의 CR, CRLF 는 LF 로 바꾼다. 커서는 편집과 이동 뒤 보이게 스크롤하고(맥이 아니면 가장자리, 맥은 가운데), 휠과 썸 끌기로 넘긴다.
    줄 높이의 normal 은 크롬처럼 첫째 글꼴의 위아래 길이와 줄 사이로 셈한다. 스크롤 막대는 크롬처럼 클래식 막대(윈도우, 리눅스, 맥 클래식 설정)면 넘칠 때 글 폭을 던다.
    맥 Home, End 는 크롬 맥처럼 커서를 두고 처음과 끝으로 넘기고(넘길 것이 없으면 줄 앞과 끝), PageUp, PageDown 은 커서를 두고 한 화면만큼 넘긴다.
  - DOM 입력을 흉내 내는 필드(use_dom_input, 여러 줄)는 크롬처럼 마우스로 두 번 누르면 낱말(윈도우는 뒤 공백까지), 세 번 누르면 문단을 고르고 끌면 그 단위로 넓힌다.
    이어 누르기는 크롬 aura 처럼 500ms(맥은 시스템의 두 번 클릭 시간) 안, 가로 세로 2 DIP 안이다. 웹은 브라우저가 센 mousedown 의 detail 을 쓴다.
  - 커서 이동과 Delete 는 크롬처럼 글자 묶음(확장 자소 묶음) 단위, 뒤로 지우기는 블링크 BackspaceStateMachine(코드 포인트 하나, 이모지 묶음은 통째로)이다.
    웹 DOM 입력은 숨긴 `<textarea>` 가 글, 조합, 되돌리기를 맡고, 보이는 줄로 옮기는 키(위아래, page, Home, End)는 필드가 엔진 배치로 옮긴다.
  - 낱말 이동과 지우기(윈도우와 리눅스 Ctrl, 맥 Option 과 왼쪽, 오른쪽, Backspace, Delete)는 크롬 textarea 처럼 블링크 NextWordPosition, PreviousWordPosition 대로다.
    (오른쪽은 윈도우만 다음 낱말 앞, 맥과 리눅스는 지금 낱말 끝. 맥은 넓히던 고르기가 고정 끝을 넘지 않는다) 웹 DOM 입력은 브라우저가 한다.
  - 노드를 끄거나(set_active(false)) 지우면 tick 이 돌지 않아 포커스와 IME, 웹의 숨긴 <input> 이 함께 사라진다. (원본은 detach 해야 사라진다)
  - getRenderState 는 옮기지 않았다. (그리는 컴포넌트가 하나라 넘길 일이 없다)
  - UI 문서(UIDocument)는 register_node_type 으로 등록하면 원본 노드 꼴로 쓰고 읽는다. (노드 type "UIInputField", 바탕 Paint, 그리기 층, 안내 글과 값 UILabel 자식,
    오버레이 자식. uidocument.rs 의 UIDocumentNode) 러스트 판이 만드는 content 노드는 문서에 적지 않는다.
    글 라벨과 오버레이의 자리와 크기는 원본 refreshTextPositions 처럼 tick 이 마지막으로 놓은 노드 크기(text_layout_size)로 적는다.

예제: 이어 친 글자는 한 번에 되돌리고 다시 하기

```rust
use vanilla::{TextEditBuffer, TextEditKind};

let mut buffer = TextEditBuffer::new();
buffer.set_text("abc");
buffer.begin_edit(TextEditKind::InsertText);
buffer.replace_selection("d");
buffer.begin_edit(TextEditKind::InsertText);
buffer.replace_selection("e");
assert_eq!(buffer.get_text(), "abcde");

assert!(buffer.undo());
assert_eq!(buffer.get_text(), "abc");
assert!(buffer.redo());
assert_eq!(buffer.get_text(), "abcde");
assert!(!buffer.can_redo());
```

## UIInputFieldEvent (type)

입력 필드 이벤트. (필드와 문맥을 받는다. 값은 field.get_text())

```rust
pub type UIInputFieldEvent = Box<dyn FnMut(&mut UIInputField, &mut ComponentContext)>
```

## TextEditBuffer (struct) (Clone, Debug, Default)

편집 버퍼. (값, 조합 글, 커서, 선택 시작. 원본 UIInputField 의 #value / #composition / #cursor_index / #selection_start 와 편집 함수)
- 자리는 문자 단위다. 커서와 선택 시작이 다르면 그 사이가 선택 영역이다. (커서가 앞일 수도 있다)
- max_length 는 원본 maxLength 처럼 UTF-16 단위다. (웹 DOM <input> 의 maxlength 와 같은 셈)
- 되돌리기와 다시 하기: 원본 DOM 입력 칸은 브라우저가 해 준다. 묶음은 블링크와 같다. (이어 친 글자는 한 번에, 커서를 옮기거나 선택을 바꾸면 끊긴다,
  새 편집은 다시 하기 목록을 지운다, 값을 코드로 넣으면 목록을 비운다) 편집하는 쪽이 고치기 전에 begin_edit 를 부른다.

예제: 최대 길이로 자르고 고른 글을 바꾼 뒤 뒤로 지우기

```rust
use vanilla::TextEditBuffer;

let mut buffer = TextEditBuffer::new();
buffer.set_max_length(5);
buffer.set_text("hello world");
assert_eq!(buffer.get_text(), "hello");

buffer.set_selection(0, 5);
assert_eq!(buffer.get_selection_text(), "hello");
buffer.replace_selection("hi");
assert_eq!(buffer.get_text(), "hi");
assert_eq!(buffer.get_cursor_index(), 2);
assert!(buffer.delete_backward());
assert_eq!(buffer.get_text(), "h");
```

- `pub fn new() -> TextEditBuffer` (constructor, since 0.3.2): 생성.
  - returns TextEditBuffer: 빈 버퍼. (값과 조합 글이 비었고 최대 길이는 0)
- `pub fn set_text(&mut self, text: &str)` (method, since 0.3.2): 값 설정. (max_length 로 자르고 커서는 끝에. 원본 setText)
  - `text` &str: 넣을 글. (되돌리기와 다시 하기 목록과 조합 중인 글도 비운다)
- `pub fn begin_edit(&mut self, edit_kind: TextEditKind)` (method, since 0.4.0): 편집 시작 알리기. (고치기 전에 부른다. 새 묶음이면 지금 값을 되돌리기 목록에 쌓고 다시 하기 목록을 지운다)
  - `edit_kind` TextEditKind: 할 편집의 되돌리기 묶음 종류.
- `pub fn close_edit_group(&mut self)` (method, since 0.4.0): 열린 묶음 닫기. (다음 편집은 새 묶음)
- `pub fn can_undo(&self) -> bool` (method, since 0.4.0): 되돌릴 것이 있는지.
  - returns bool: 되돌릴 묶음이 있으면 true.
- `pub fn can_redo(&self) -> bool` (method, since 0.4.0): 다시 할 것이 있는지.
  - returns bool: 다시 할 묶음이 있으면 true.
- `pub fn undo(&mut self) -> bool` (method, since 0.4.0): 되돌리기. (했으면 true)
  - returns bool: 되돌렸으면 true. 되돌릴 것이 없으면 false.
- `pub fn redo(&mut self) -> bool` (method, since 0.4.0): 다시 하기. (했으면 true)
  - returns bool: 다시 했으면 true. 다시 할 것이 없으면 false.
- `pub fn get_text(&self) -> &str` (method, since 0.3.2): 값 반환.
  - returns &str: 입력한 글. (조합 중인 글은 빠진다)
- `pub fn set_value_from_platform(&mut self, value: &str, cursor_index: usize)` (method, since 0.3.2): 플랫폼이 준 값으로 바꾸기. (자르지 않는다. 커서를 정하고 선택은 접는다. 원본 handleDOMInputEvent)
  - `value` &str: 플랫폼 입력 칸의 값.
  - `cursor_index` usize: 커서 자리. (문자 단위, 값 끝을 넘으면 끝으로)
- `pub fn set_max_length(&mut self, max_length: usize)` (method, since 0.3.2): 최대 길이 설정. (UTF-16 단위, 0 이면 제한 없음. 원본처럼 지금 값은 자르지 않는다)
  - `max_length` usize: 최대 글자 수. (UTF-16 단위, 0 이면 제한하지 않는다, 지금 값은 자르지 않는다)
- `pub fn get_max_length(&self) -> usize` (method, since 0.3.2): 최대 길이 반환.
  - returns usize: 최대 글자 수. (0 이면 제한하지 않는다)
- `pub fn set_composition(&mut self, composition: &str)` (method, since 0.3.2): 조합 글 설정.
  - `composition` &str: IME 가 조합 중인 글. (빈 글이면 없음)
- `pub fn get_composition(&self) -> &str` (method, since 0.3.2): 조합 글 반환.
  - returns &str: IME 가 조합 중인 글. (없으면 빈 글)
- `pub fn get_cursor_index(&self) -> usize` (method, since 0.3.2): 커서 자리.
  - returns usize: 커서 자리. (문자 단위, 0 ~ 값의 문자 수)
- `pub fn get_selection_start(&self) -> usize` (method, since 0.3.2): 선택 시작 자리. (선택을 늘릴 때 고정되는 쪽)
  - returns usize: 선택의 고정 끝. (문자 단위, 커서 자리와 같으면 선택이 없다)
- `pub fn set_selection(&mut self, selection_start: usize, cursor_index: usize)` (method, since 0.3.2): 선택 정하기. (끝을 넘으면 자른다)
  - `selection_start` usize: 선택의 고정 끝. (문자 단위, 값 끝을 넘으면 끝으로)
  - `cursor_index` usize: 커서 자리. (문자 단위, 값 끝을 넘으면 끝으로)
- `pub fn has_selection(&self) -> bool` (method, since 0.3.2): 선택이 있는지.
  - returns bool: 선택한 글이 있으면 참.
- `pub fn get_selection_range(&self) -> Option<(usize, usize)>` (method, since 0.3.2): 선택 범위. (앞, 뒤. 없으면 None)
  - returns Option<(usize, usize)>: 선택 범위 (앞, 뒤). (문자 단위, 앞이 작은 쪽, 선택이 없으면 None)
- `pub fn get_selection_text(&self) -> String` (method, since 0.3.2): 선택된 글.
  - returns String: 선택한 글. (없으면 빈 글)
- `pub fn replace_selection(&mut self, text: &str)` (method, since 0.3.2): 선택을 글로 바꾸기. (선택이 없으면 커서 자리에 끼운다. 원본 replaceSelection)
  - max_length 가 있으면 블링크 입력 칸(text_field_input_type.cc 의 FilterBeforeTextInserted)처럼 넣는 글을 남은 UTF-16 길이까지만 넣는다. (글자는 쪼개지 않는다)
  - `text` &str: 넣을 글. (빈 글이면 선택을 지운다)
- `pub fn delete_character_at(&mut self, character_index: usize)` (method, since 0.3.2): 글자 하나 지우기. (그 자리부터 글자 묶음 하나, 크롬 Delete 키처럼 이모지나 결합 부호를 쪼개지 않는다. 원본 deleteCharAt)
  - `character_index` usize: 지울 글자의 자리. (문자 단위)
- `pub fn delete_range(&mut self, start_index: usize, end_index: usize)` (method, since 0.4.0): 글 범위 지우기. (문자 자리, 커서는 지운 자리로 당기고 선택은 접는다. 원본 deleteRange)
  - `start_index` usize: 지울 범위의 앞. (문자 단위)
  - `end_index` usize: 지울 범위의 뒤. (문자 단위, 앞보다 크지 않으면 아무것도 하지 않는다)
- `pub fn delete_backward(&mut self) -> bool` (method, since 0.3.2): 뒤로 지우기. (선택이 있으면 선택을, 없으면 블링크 BackspaceStateMachine 이 정한 커서 앞 범위. 바뀌었으면 true)
  - returns bool: 지웠으면 true. 선택이 없고 커서가 글 앞이면 false.
- `pub fn delete_forward(&mut self) -> bool` (method, since 0.3.2): 앞으로 지우기. (선택이 있으면 선택을, 없으면 커서 뒤 글자 묶음. 바뀌었으면 true)
  - returns bool: 지웠으면 true. 선택이 없고 커서가 글 끝이면 false.
- `pub fn move_cursor(&mut self, new_index: usize, is_selection_extended: bool)` (method, since 0.3.2): 커서 옮기기. (글 안으로 자른다. 선택을 늘리지 않으면 선택을 접는다. 원본 moveCursor)
  - `new_index` usize: 옮길 자리. (문자 단위, 0 ~ 값의 문자 수로 자른다)
  - `is_selection_extended` bool: 참이면 선택의 고정 끝을 두고 선택을 늘린다.
- `pub fn select_all(&mut self)` (method, since 0.3.2): 모두 선택. (원본 selectAll)
- `pub fn get_text_before_cursor(&self) -> &str` (method, since 0.3.2): 커서 앞 글.
  - returns &str: 값에서 커서 앞까지의 글.
- `pub fn get_composition_start(&self) -> usize` (method, since 0.4.0): 조합 글이 들어갈 값의 자리. (조합 중이면 고른 글의 앞, 아니면 커서. 원본 #getCompositionStart)
  - 고른 채 조합하면 확정이 고른 글을 갈음한다. 보이는 글은 [고른 글 앞, 조합 글, 고른 글 뒤] 다.
  - returns usize: 글자 자리.
- `pub fn get_composition_end(&self) -> usize` (method, since 0.4.0): 조합 글이 갈음할 값의 끝. (조합 중이면 고른 글의 뒤, 아니면 커서. 원본 #getCompositionEnd)
  - returns usize: 글자 자리.
- `pub fn get_display_text_before_cursor(&self) -> String` (method, since 0.4.0): 보이는 글의 커서 앞까지. (조합 중이면 조합 글이 들어갈 자리 앞의 값과 조합 글, 아니면 값의 커서 앞)
  - returns String: 보이는 글에서 커서 앞까지의 글.
- `pub fn build_display_text(&self) -> String` (method, since 0.3.2): 보이는 글. (커서 자리에 조합 글을 끼운 것, 고른 채 조합하면 고른 글 자리를 조합 글로 갈음한 것. 원본 getDisplayText)
  - returns String: 보이는 글. (조합 중이 아니면 값 그대로)

## UIInputField (struct) (Default, Component, UIDocumentNode)

입력 필드.

예제: 이름 입력 필드를 붙이고 눌러 포커스 주기

```rust
use vanilla::{Engine, EngineConfiguration, NodeTree, TouchKind, UIInputField, Vector2};

let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let field_id = node_tree.create_child(root_id, "NameField");
node_tree[field_id].set_local_position(Vector2::create(100.0, 50.0));
node_tree[field_id].set_content_size(Vector2::create(300.0, 56.0));
let input_field = node_tree.add_component(field_id, UIInputField::new()).expect("input field");
input_field.set_use_dom_input(true);
input_field.set_placeholder("Name");
input_field.set_max_length(8);
input_field.set_text("Vanilla Engine");
assert_eq!(input_field.get_text(), "Vanilla ");
input_field.move_cursor(0, true);
assert_eq!(input_field.get_selection_range(), Some((0, 8)));
input_field.attach();

node_tree.dispatch_touch(field_id, &engine, TouchKind::Press, Vector2::create(150.0, 70.0));
assert!(node_tree[field_id].get_component::<UIInputField>().expect("input field").is_focused());
```

- `pub fn new() -> UIInputField` (constructor, since 0.3.2): 생성. (기본값은 원본과 같다: 28px, 여백 16, 흰 바탕 둥글기 8, 글 #222222, 안내 글 #999999, 커서 #5b8def, 테두리 #f97316 3px)
  - returns UIInputField: 새 입력 필드. (값과 안내 글이 비었고 포커스가 없다)
- `pub fn get_uicontrol(&self) -> &UIControl` (method, since 0.3.2): 품은 컨트롤 반환.
  - returns &UIControl: 품은 UIControl.
- `pub fn get_uicontrol_mut(&mut self) -> &mut UIControl` (method, since 0.3.2): 품은 컨트롤 반환. (변경용)
  - returns &mut UIControl: 품은 UIControl.
- `pub fn get_content(&self) -> Option<NodeId>` (method, since 0.3.2): 컨텐트 노드 핸들.
  - returns Option<NodeId>: 호스트 노드 밑에 만든 컨텐트 노드. 트리에 붙기 전이면 None.
- `pub fn get_field_id(&self) -> u64` (method, since 0.3.2): 필드 id. (엔진 글 입력 줄에서 이 필드를 가리키는 값)
  - returns u64: 필드 id. (1 부터)
- `pub fn set_use_dom_input(&mut self, use_dom_input: bool)` (method, since 0.3.2): 플랫폼 글 입력 사용 설정. (원본 setUseDOMInput. 켜야 한글 IME, 모바일 키보드, 웹 시스템 붙여넣기가 된다. 기본 꺼짐)
  - `use_dom_input` bool: true 면 플랫폼 글 입력으로 받는다. (웹은 숨은 DOM 입력, 데스크탑은 IME)
- `pub fn is_using_dom_input(&self) -> bool` (method, since 0.3.2): 플랫폼 글 입력 사용 여부.
  - returns bool: DOM 입력을 쓰면 참.
- `pub fn set_use_touch_end_focus(&mut self, use_touch_end_focus: bool)` (method, since 0.3.2): 손을 뗄 때도 포커스를 줄지 설정. (웹 DOM 입력 전용. 첫 터치에 키보드를 띄우지 않는 브라우저용, 기본 꺼짐)
  - `use_touch_end_focus` bool: 참이면 touchend 에서도 포커스를 준다. (기본 거짓)
- `pub fn is_using_touch_end_focus(&self) -> bool` (method, since 0.3.2): 손을 뗄 때도 포커스를 주는지.
  - returns bool: touchend 에서도 포커스를 주면 참.
- `pub fn set_use_direct_touch(&mut self, use_direct_touch: bool)` (method, since 0.3.2): DOM 입력을 필드 위에서 직접 누르게 할지 설정. (use_dom_input 을 켠 필드에서 뜻이 있다, 기본 꺼짐)
  - 웹: 원본처럼 투명한 DOM 입력이 필드 자리에서 누름을 받아, 브라우저 기본 동작으로 포커스와 키보드를 연다. (코드로 준 포커스를 받지 않는 웹뷰용)
    그 필드의 오른쪽 단추는 원본처럼 브라우저 편집 칸 메뉴 대신 다른 필드와 같은 엔진 문맥 메뉴(잘라내기, 복사, 붙여넣기, 모두 선택)다.
    손가락 길게 누르기는 크롬이 그 DOM 입력에 띄우는 것이다.
  - 데스크탑: 원본에서 크롬이 그 DOM 입력에 하는 일을 엔진이 한다. 오른쪽 단추는 같은 엔진 문맥 메뉴이고,
    손가락으로 650ms 길게 누르면(15 DIP 안) 낱말을 고르고 터치 손잡이와 빠른 메뉴를 띄운다. (크롬 데스크탑 터치, 윈도우는 뗄 때 메뉴를 정한다)
  - `use_direct_touch` bool: 참이면 필드 자리의 누름을 DOM 입력이 직접 받는다. (데스크탑은 그 DOM 입력처럼 길게 누르기를 한다, 기본 거짓)
- `pub fn is_using_direct_touch(&self) -> bool` (method, since 0.3.2): DOM 입력을 직접 누르게 하는지.
  - returns bool: DOM 입력이 누름을 직접 받으면 참.
- `pub fn set_multiline(&mut self, is_multiline: bool)` (method, since 0.4.0): 여러 줄 설정. (크롬 textarea 처럼. 웹 DOM 입력은 숨긴 `<textarea>` 를 쓴다. 원본 필드의 속성이 아니라 반사에서 뺀다)
  - `is_multiline` bool: true 면 여러 줄, false 면 한 줄. (처음 false, 바꾸면 스크롤을 처음으로)
- `pub fn is_multiline(&self) -> bool` (method, since 0.4.0): 여러 줄인지.
  - returns bool: 여러 줄이면 true.
- `pub fn set_line_height(&mut self, line_height: Option<f64>)` (method, since 0.4.0): 줄 높이 설정. (여러 줄 필드, None 이면 CSS normal 이다. 크롬 SimpleFontData 처럼 첫째 글꼴의 위아래 길이와 줄 사이를 반올림해 더한다)
  - `line_height` Option<f64>: 줄 높이. (내용 크기 단위, None 이면 CSS normal)
- `pub fn get_line_height(&self) -> f64` (method, since 0.4.0): 줄 높이. (여러 줄 필드)
  - returns f64: 줄 높이. (정하지 않았으면 CSS normal 로 잰 값, 글꼴을 하나도 읽지 못했으면 글꼴 크기의 1.2 배를 반올림한 값)
- `pub fn set_tab_size(&mut self, tab_size: f64)` (method, since 0.4.0): 탭 크기 설정. (여러 줄 필드, 공백 몇 개 폭. CSS tab-size, 기본 8)
  - `tab_size` f64: 탭 크기. (공백 몇 개 폭, 음수는 0, 기본 8)
- `pub fn get_tab_size(&self) -> f64` (method, since 0.4.0): 탭 크기.
  - returns f64: 탭 크기. (공백 몇 개 폭)
- `pub fn get_scroll_top(&self) -> f64` (method, since 0.4.0): 위로 굴려 넘긴 만큼. (여러 줄 필드, 원본 textarea scrollTop)
  - returns f64: 위로 넘긴 만큼. (내용 크기 단위)
- `pub fn set_scroll_top(&mut self, scroll_top: f64)` (method, since 0.4.0): 위로 굴려 넘기기. (여러 줄 필드, 다음 그리기에서 글 끝 안으로 줄인다)
  - `scroll_top` f64: 위로 넘길 만큼. (내용 크기 단위, 음수는 0)
- `pub fn can_undo(&self) -> bool` (method, since 0.4.0): 되돌릴 것이 있는지.
  - returns bool: 되돌릴 묶음이 있으면 true.
- `pub fn can_redo(&self) -> bool` (method, since 0.4.0): 다시 할 것이 있는지.
  - returns bool: 다시 할 묶음이 있으면 true.
- `pub fn set_text(&mut self, text: &str)` (method, since 0.3.2): 값 설정. (max_length 로 자르고 커서는 끝에. 바뀜 이벤트는 부르지 않는다. 원본 setText)
  - 조합 중이었으면 조합을 버린다. (조합 글은 바꾸기 전 값에 끼운 것이다. 남겨 두면 확정이 오지 않을 때 조합 상태에 갇힌다)
  - `text` &str: 넣을 글. (되돌리기와 다시 하기 목록과 조합 중인 글도 비운다)
- `pub fn get_text(&self) -> &str` (method, since 0.3.2): 값 반환.
  - returns &str: 입력한 글. (조합 중인 글은 빠진다)
- `pub fn get_display_text(&self) -> String` (method, since 0.3.2): 보이는 글 반환. (값의 커서 자리에 조합 글을 끼운 것, 고른 채 조합하면 고른 글 자리를 조합 글로 갈음한 것. 원본 getDisplayText)
  - returns String: 보이는 글. (조합 중이 아니면 값 그대로)
- `pub fn get_composition(&self) -> &str` (method, since 0.3.2): 조합 중인 글 반환.
  - returns &str: IME 가 조합 중인 글. (없으면 빈 글)
- `pub fn is_composing(&self) -> bool` (method, since 0.3.2): IME 조합 중인지.
  - returns bool: 조합 중이면 참.
- `pub fn set_placeholder(&mut self, placeholder: &str)` (method, since 0.3.2): 안내 글 설정. (값이 비었을 때 보인다)
  - `placeholder` &str: 값이 비었을 때 보일 글.
- `pub fn get_placeholder(&self) -> &str` (method, since 0.3.2): 안내 글 반환.
  - returns &str: 플레이스홀더 글.
- `pub fn set_max_length(&mut self, max_length: usize)` (method, since 0.3.2): 최대 글자 수 설정. (원본처럼 UTF-16 단위, 0 이면 제한 없음)
  - `max_length` usize: 최대 글자 수. (UTF-16 단위, 0 이면 제한하지 않는다, 지금 값은 자르지 않는다)
- `pub fn get_max_length(&self) -> usize` (method, since 0.3.2): 최대 글자 수 반환.
  - returns usize: 최대 글자 수. (0 이면 제한하지 않는다)
- `pub fn set_font_size(&mut self, font_size: f64)` (method, since 0.3.2): 글자 크기 설정.
  - `font_size` f64: 글자 크기. (내용 크기 단위, 기본 28)
- `pub fn get_font_size(&self) -> f64` (method, since 0.3.2): 글자 크기 반환.
  - returns f64: 글자 크기.
- `pub fn set_font_family(&mut self, font_family: &str)` (method, since 0.3.2): 폰트 이름 설정. (원본 setFont 자리. Graphic 에 등록한 이름, 없으면 기본 폰트)
  - `font_family` &str: Graphic 에 등록한 폰트 이름. (처음 "default", 엔진 기본 폰트)
- `pub fn get_font_family(&self) -> &str` (method, since 0.3.2): 폰트 이름 반환.
  - returns &str: 폰트 이름. (처음 "default")
- `pub fn set_padding(&mut self, padding: f64)` (method, since 0.3.2): 안쪽 여백 설정. (글 왼쪽 여백)
  - `padding` f64: 왼쪽과 오른쪽 안쪽 여백. (내용 크기 단위, 기본 16, 여러 줄 필드는 위아래에도)
- `pub fn get_padding(&self) -> f64` (method, since 0.3.2): 안쪽 여백 반환.
  - returns f64: 왼쪽과 오른쪽 안쪽 여백.
- `pub fn set_background_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 바탕색 설정.
  - `color` impl Into<Color>: 배경색. (기본 흰색)
- `pub fn get_background_color(&self) -> Color` (method, since 0.3.2): 바탕색 반환.
  - returns Color: 배경색.
- `pub fn set_round_size(&mut self, round_size: f64)` (method, since 0.3.2): 바탕 둥글기 설정. (포커스 테두리도 따른다)
  - `round_size` f64: 배경과 포커스 테두리의 모서리 반지름. (기본 8)
- `pub fn get_round_size(&self) -> f64` (method, since 0.3.2): 바탕 둥글기 반환.
  - returns f64: 배경의 모서리 반지름.
- `pub fn set_text_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 글자 색 설정.
  - `color` impl Into<Color>: 값 글자의 색. (기본 #222222)
- `pub fn get_text_color(&self) -> Color` (method, since 0.3.2): 글자 색 반환.
  - returns Color: 값 글자의 색.
- `pub fn set_placeholder_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 안내 글 색 설정.
  - `color` impl Into<Color>: 플레이스홀더 글자의 색. (기본 #999999)
- `pub fn get_placeholder_color(&self) -> Color` (method, since 0.3.2): 안내 글 색 반환.
  - returns Color: 플레이스홀더 글자의 색.
- `pub fn set_cursor_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 커서 색 설정. (조합 밑줄도 같은 색. 원본과 같음)
  - `color` impl Into<Color>: 커서와 조합 밑줄의 색. (기본 #5b8def)
- `pub fn get_cursor_color(&self) -> Color` (method, since 0.3.2): 커서 색 반환.
  - returns Color: 커서 색.
- `pub fn set_focus_border_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 포커스 테두리 색 설정.
  - `color` impl Into<Color>: 포커스 테두리 색. (기본 #f97316)
- `pub fn set_focus_border_width(&mut self, focus_border_width: f64)` (method, since 0.3.2): 포커스 테두리 두께 설정. (0 이면 그리지 않는다)
  - `focus_border_width` f64: 포커스 테두리 두께. (0 이하면 그리지 않는다, 기본 3)
- `pub fn set_selection_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 선택 영역 색 설정.
  - `color` impl Into<Color>: 선택 영역을 칠할 색. (기본 알파 0.35 의 파랑)
- `pub fn set_on_change(&mut self, change_event: UIInputFieldEvent)` (method, since 0.3.2): 바뀜 이벤트 설정. (사용자 입력으로 값이 바뀔 때. 원본 setOnChange)
  - `change_event` UIInputFieldEvent: 사용자 입력으로 값이 바뀔 때마다 부를 함수. (필드와 문맥을 받는다, 값은 `field.get_text()`, set_text 로 바꿀 때는 부르지 않는다)
- `pub fn set_on_submit(&mut self, submit_event: UIInputFieldEvent)` (method, since 0.3.2): 제출 이벤트 설정. (Enter. 원본 setOnSubmit)
  - `submit_event` UIInputFieldEvent: 포커스된 채 Enter 를 누르면 부를 함수. (한 줄 필드만, 필드와 문맥을 받는다, 값은 `field.get_text()`)
- `pub fn attach(&mut self)` (method, since 0.3.2): 입력 받기 시작. (원본 attach: DOM 입력 또는 캔버스 키보드, 문맥 메뉴)
- `pub fn detach(&mut self)` (method, since 0.3.2): 입력 받기 끝. (원본 detach. DOM 입력을 쓰던 필드는 포커스와 조합 글도 잃는다)
- `pub fn is_attached(&self) -> bool` (method, since 0.3.2): 입력을 받기로 했는지.
  - returns bool: attach 뒤 detach 전이면 true.
- `pub fn focus(&mut self)` (method, since 0.3.2): 포커스 주기. (원본 focus. 플랫폼 입력은 다음 프레임에 이 필드로 온다)
- `pub fn blur(&mut self)` (method, since 0.3.2): 포커스 빼기. (원본 blur. 조합 중이던 글은 확정한다. 씬 코드에서 부르면 바뀜 이벤트는 부르지 않는다)
- `pub fn is_focused(&self) -> bool` (method, since 0.3.2): 포커스를 가졌는지.
  - returns bool: 포커스를 가졌으면 참.
- `pub fn select_all(&mut self)` (method, since 0.3.2): 모두 선택.
- `pub fn has_selection(&self) -> bool` (method, since 0.3.2): 선택이 있는지.
  - returns bool: 선택한 글이 있으면 참.
- `pub fn get_selection_range(&self) -> Option<(usize, usize)>` (method, since 0.3.2): 선택 범위. (앞, 뒤. 원본처럼 UTF-16 단위, 없으면 None)
  - returns Option<(usize, usize)>: 선택 범위 (앞, 뒤). (UTF-16 단위, 앞이 작은 쪽, 선택이 없으면 None)
- `pub fn get_selection_text(&self) -> String` (method, since 0.3.2): 선택된 글.
  - returns String: 선택한 글. (없으면 빈 글)
- `pub fn get_cursor_index(&self) -> usize` (method, since 0.3.2): 커서 자리. (원본처럼 UTF-16 단위)
  - returns usize: 커서 자리. (값 안의 글자 위치, 0 ~ 값 길이)
- `pub fn get_selection_start(&self) -> usize` (method, since 0.3.2): 선택 시작 자리. (원본처럼 UTF-16 단위)
  - returns usize: 선택의 고정 끝. (커서 자리와 같으면 선택이 없다)
- `pub fn move_cursor(&mut self, new_index: usize, is_selection_extended: bool)` (method, since 0.3.2): 커서 옮기기. (원본 moveCursor, 자리는 UTF-16 단위)
  - `new_index` usize: 옮길 자리. (UTF-16 단위, 0 ~ 값 길이로 자른다, 서로게이트 쌍 가운데면 그 글자 뒤로 본다)
  - `is_selection_extended` bool: 참이면 선택의 고정 끝을 두고 선택을 늘린다.
- `pub fn replace_selection(&mut self, context: &mut ComponentContext, text: &str)` (method, since 0.3.2): 선택을 글로 바꾸고 바뀜 이벤트 부르기. (원본 replaceSelection)
  - `context` &mut ComponentContext: 바뀜 이벤트에 넘길 컴포넌트 문맥.
  - `text` &str: 넣을 글. (빈 글이면 선택을 지운다)
- `pub fn cut(&mut self, context: &mut ComponentContext)` (method, since 0.3.2): 잘라내기. (선택을 클립보드에 쓰고 지운다)
  - `context` &mut ComponentContext: 클립보드를 쓸 엔진과 바뀜 이벤트에 넘길 컴포넌트 문맥.
- `pub fn copy(&self, engine: &Engine)` (method, since 0.3.2): 복사. (선택을 클립보드에 쓴다)
  - `engine` &Engine: 클립보드를 쓸 엔진.
- `pub fn paste(&mut self, context: &mut ComponentContext)` (method, since 0.3.2): 붙여넣기. (데스크탑은 클립보드를 그 자리에서 읽는다. 웹은 원본처럼 비동기로 읽고, 다 읽으면 이 필드의 글 입력 줄로 넣어 다음 tick 에 붙인다)
  - `context` &mut ComponentContext: 클립보드를 읽을 엔진과 바뀜 이벤트에 넘길 컴포넌트 문맥. (웹은 쓰지 않는다)
- `pub fn request_menu_action(&mut self, menu_action: UIInputFieldMenuAction)` (method, since 0.3.2): 문맥 메뉴 항목 부탁. (문맥 메뉴가 부른다. 다음 tick 에 이 필드의 문맥으로 한다)
  - `menu_action` UIInputFieldMenuAction: 할 항목. (UIInputFieldMenuAction 의 값)
- `pub fn measure_index_at_local_x(&self, local_x: f64) -> usize` (method, since 0.3.2): 노드 x(content 영역 기준) → 글자 자리. (원본처럼 UTF-16 단위)
  - `local_x` f64: 노드 안의 X. (내용 영역 왼쪽이 0)
  - returns usize: 그 자리에 가장 가까운 글자 묶음 경계. (UTF-16 단위, 0 ~ 값 길이, 아직 그려 재지 않았으면 값 길이)

## Functions and constants

- `pub fn find_character_index_at_offset(character_offsets: &[f64], target_x: f64) -> usize` (method, since 0.3.2): 글자 경계 x 목록에서 누른 x 에 가까운 글자 자리 찾기. (원본 measureIndexAtLocalX 의 비교)
  - `character_offsets[i]` 는 앞 i 글자의 폭이다. (0 번은 0)
  - `character_offsets` &[f64]: 앞 i 글자의 폭 목록. (0 번은 0, 글자 수 + 1 개)
  - `target_x` f64: 누른 x. (첫 글자 왼쪽이 0)
  - returns usize: 가장 가까운 글자 경계의 자리. (0 ~ 글자 수)

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

문맥 메뉴 항목. (원본 UIInputFieldMenuAction 의 잘라내기 / 복사 / 붙여넣기 / 모두 선택, request_menu_action 이 받는다)

- `Cut`: 잘라내기.
- `Copy`: 복사.
- `Paste`: 붙여넣기.
- `SelectAll`: 모두 선택.

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

되돌리기 묶음 종류. (블링크 TypingCommand 와 붙여넣기)

- `InsertText`: 글자 넣기. (열린 묶음이 있으면 종류를 가리지 않고 그 묶음에 붙고, 묶음은 글자 넣기가 된다)
- `DeleteBackward`: 뒤로 지우기. (열린 묶음이 뒤로 지우기일 때만 붙고, 아니면 새 묶음)
- `DeleteForward`: 앞으로 지우기. (열린 묶음이 앞으로 지우기일 때만 붙고, 아니면 새 묶음)
- `Paste`: 붙여넣기와 잘라내기, 낱말 지우기 키로 고른 것 지우기. (블링크 ReplaceSelectionCommand, DeleteSelectionCommand 라 늘 따로 한 묶음이고, 그 뒤 글자 넣기도 새 묶음)
- `DeleteWordBackward`: 낱말 뒤로 지우기. (블링크는 늘 새 TypingCommand 를 열어 새 묶음이고, 그 뒤 뒤로 지우기와 글자 넣기는 이 묶음에 붙는다)
- `DeleteWordForward`: 낱말 앞으로 지우기. (늘 새 묶음이고, 그 뒤 앞으로 지우기와 글자 넣기는 이 묶음에 붙는다)
