vanilladocs
vanillapunch.com
API / core/textinput

core/textinput

글 입력 줄. (InputManager 가 든다)

  • 원본에는 이런 층이 없다. 원본 UIInputField 는 DOM <input> 과 document keydown 에 직접 리스너를 단다. 러스트 판은 플랫폼이 창 이벤트(데스크탑 winit 의 KeyboardInput / Ime, 웹 숨긴 <input> 의 input / composition / keydown)를 여기 줄에 넣고, 포커스를 가진 입력 필드가 tick 에서 꺼내 쓴다. (ui/uiinputfield.rs)
  • 컴포넌트는 &Engine 만 받는다. 그래서 필드가 쓰는 쪽(꺼내기, 상태 올리기)은 RefCell 로 &self 에서 되게 했다. 플랫폼은 &Engine 을 쥐므로 넣는 쪽은 &mut self 다.
  • 프레임 흐름:
1. 플랫폼이 프레임 사이에 이벤트를 넣는다. (push_event)
2. 씬 tick 에서 필드가 자기 몫을 꺼낸다. (take_events_for_field) 붙어 있는(attach) 필드와 포커스를 가진 필드는 상태를 올린다. (register_field_state)
3. 프레임 끝에 엔진이 finish_frame 을 부른다. 남은 이벤트를 버리고, 올라온 상태를 "지난 프레임 상태"로 넘긴다.
4. 플랫폼이 지난 프레임 상태를 읽어 적용한다. (데스크탑: IME 켜고 끄기와 후보 창 자리, 웹: 숨긴 <input> 자리, 값, 포커스)
  • 글자 자리는 모두 문자(char) 단위다. 원본(자바스크립트 문자열)은 UTF-16 단위다. 한글은 둘이 같고, 이모지 같은 글자에서만 다르다. 웹 플랫폼은 DOM 의 UTF-16 자리를 여기 함수로 바꿔 넣는다.

Text input queue. (held by InputManager)

  • The original has no such layer. The original UIInputField attaches listeners directly to a DOM <input> and document keydown. In the Rust version the platform puts window events (desktop winit's KeyboardInput / Ime, the web hidden <input>'s input / composition / keydown) into this queue, and the input field with focus takes them out on tick. (ui/uiinputfield.rs)
  • Components receive only &Engine. So the side the field uses (taking out, publishing state) is made to work from &self with RefCell. The platform holds &Engine, so the pushing side is &mut self.
  • Frame flow:
1. The platform pushes events between frames. (push_event)
2. On scene tick, a field takes out its share. (take_events_for_field) Attached fields and the field with focus publish their state. (register_field_state)
3. At the end of the frame the engine calls finish_frame. It drops the remaining events and moves the published states to the "last frame states".
4. The platform reads the last frame states and applies them. (desktop: turning IME on and off and the candidate window position, web: hidden <input> position, value, focus)
  • All character positions are in characters (char). The original (JavaScript strings) uses UTF-16 units. They are the same for Hangul and differ only for characters like emoji. The web platform converts DOM UTF-16 positions with the functions here before pushing.
예제Example문자 자리와 바이트 자리, UTF-16 자리 바꾸기Convert between character positions, byte positions and UTF-16 positions
use vanilla::core::textinput::{convert_byte_index_to_character_index, convert_character_index_to_byte_index, convert_character_index_to_utf16_index, convert_utf16_index_to_character_index, count_characters};

let text = "a\u{D55C}\u{1F600}b";
assert_eq!(count_characters(text), 4);
assert_eq!(convert_character_index_to_byte_index(text, 2), 4);
assert_eq!(convert_byte_index_to_character_index(text, 4), 2);
assert_eq!(convert_character_index_to_utf16_index(text, 3), 4);
assert_eq!(convert_utf16_index_to_character_index(text, 4), 3);

TextInputEventstruct traits Clone, Debug, PartialEq

소스source

글 입력 이벤트. (받을 필드 + 내용)

Text input event. (receiving field + content)

예제Example포커스를 가진 필드에 확정 글 보내기Send committed text to the field with focus
use vanilla::{TextInput, TextInputEvent, TextInputEventKind};

let mut text_input = TextInput::new();
text_input.push_event(TextInputEvent {
	target_field_id: 0,
	kind: TextInputEventKind::Commit(String::from("hello")),
});
assert_eq!(text_input.get_event_count(), 1);
필드fieldpub target_field_id: u64#0.3.2 부터since 0.3.2소스source

받을 필드 id. 0 이면 지금 포커스를 가진 필드. (데스크탑 키와 IME, 웹 캔버스 모드 키)

Receiving field id. 0 means the field that currently has focus. (desktop keys and IME, web canvas mode keys)

반환Returnsu64

필드fieldpub kind: TextInputEventKind#0.3.2 부터since 0.3.2소스source

이벤트 내용.

Event content.

반환ReturnsTextInputEventKind

TextInputFieldStatestruct traits Clone, Debug, PartialEq

소스source

필드가 프레임마다 올리는 상태. (플랫폼이 IME 와 숨긴 <input> 을 맞출 때 읽는다)

  • 자리는 창 안쪽 논리 좌표(웹은 캔버스 기준 CSS 픽셀)다.

State a field publishes every frame. (read by the platform to sync the IME and the hidden <input>)

  • Positions are logical coordinates inside the window (on the web, CSS pixels relative to the canvas).
예제Example필드 상태를 올리고 프레임 끝에 넘기기Publish field state and move it on at the end of the frame
use vanilla::{Rect, TextInput, TextInputFieldState};

let mut text_input = TextInput::new();
text_input.register_field_state(TextInputFieldState {
	field_id: 3,
	focus_serial: 1,
	is_focused: true,
	is_attached: true,
	use_dominput: true,
	use_touch_end_focus: false,
	use_direct_touch: false,
	is_visible: true,
	field_rect: Rect::create(10.0, 20.0, 200.0, 40.0),
	caret_rect: Rect::create(10.0, 20.0, 1.0, 40.0),
	value: String::from("abc"),
	selection_start: 0,
	cursor_index: 3,
	max_length: 0,
	value_revision: 0,
	is_multiline: false,
});
text_input.finish_frame();
assert_eq!(text_input.get_published_field_states().len(), 1);
assert_eq!(text_input.get_published_field_states()[0].value, "abc");
필드fieldpub field_id: u64#0.3.2 부터since 0.3.2소스source

필드 id. (UIInputField 가 만들 때 1 부터 매긴다)

Field id. (numbered from 1 when UIInputField creates it)

반환Returnsu64

필드fieldpub focus_serial: u64#0.3.2 부터since 0.3.2소스source

포커스를 얻은 차례. (클수록 나중. 포커스가 없으면 0)

Order in which it got focus. (larger is later. 0 if no focus)

반환Returnsu64

필드fieldpub is_focused: bool#0.3.2 부터since 0.3.2소스source

포커스를 가졌는지.

Whether it has focus.

반환Returnsbool

필드fieldpub is_attached: bool#0.3.2 부터since 0.3.2소스source

attach() 로 입력을 받기로 했는지.

Whether it chose to receive input with attach().

반환Returnsbool

필드fieldpub use_dominput: bool#0.3.2 부터since 0.3.2소스source

플랫폼 글 입력(IME, 시스템 키보드, 웹 숨긴 <input>)을 쓰는지. (원본 setUseDOMInput)

Whether platform text input (IME, system keyboard, hidden web <input>) is used. (the original setUseDOMInput)

반환Returnsbool

필드fieldpub use_touch_end_focus: bool#0.3.2 부터since 0.3.2소스source

손을 뗄 때도 포커스를 줄지. (웹 DOM 입력 전용)

Whether to give focus on release too. (web DOM input only)

반환Returnsbool

필드fieldpub use_direct_touch: bool#0.3.2 부터since 0.3.2소스source

DOM 입력을 필드 위에서 직접 누르게 할지. (웹 DOM 입력 전용)

Whether to let the DOM input be pressed directly over the field. (web DOM input only)

반환Returnsbool

필드fieldpub is_visible: bool#0.3.2 부터since 0.3.2소스source

노드와 조상이 모두 보이는지.

Whether the node and all its ancestors are visible.

반환Returnsbool

필드fieldpub field_rect: Rect#0.3.2 부터since 0.3.2소스source

필드 사각형.

Field rectangle.

반환ReturnsRect

필드fieldpub caret_rect: Rect#0.3.2 부터since 0.3.2소스source

커서 사각형. (필드 높이만큼의 세로 막대)

Cursor rectangle. (a vertical bar the height of the field)

반환ReturnsRect

필드fieldpub value: String#0.3.2 부터since 0.3.2소스source

지금 값.

Current value.

반환ReturnsString

필드fieldpub selection_start: usize#0.3.2 부터since 0.3.2소스source

선택 시작 자리. (문자 단위, 선택을 늘릴 때 고정되는 쪽. cursor_index 와 같으면 선택 없음)

Selection start position. (in characters, the side fixed when extending the selection. No selection if equal to cursor_index)

반환Returnsusize

필드fieldpub cursor_index: usize#0.3.2 부터since 0.3.2소스source

커서 자리. (문자 단위)

Cursor position. (in characters)

반환Returnsusize

필드fieldpub max_length: usize#0.3.2 부터since 0.3.2소스source

최대 길이. (UTF-16 단위, 0 이면 제한 없음)

Maximum length. (in UTF-16 units, no limit if 0)

반환Returnsusize

필드fieldpub value_revision: u64#0.3.2 부터since 0.3.2소스source

필드 쪽에서 값이나 커서를 바꿀 때마다 는다. (웹이 숨긴 <input> 에 다시 써야 하는지 볼 때)

Increases whenever the field side changes the value or cursor. (used by the web to see whether the hidden <input> needs rewriting)

반환Returnsu64

필드fieldpub is_multiline: bool#0.4.0 부터since 0.4.0소스source

여러 줄 필드인지. (웹은 숨긴 <textarea> 를 쓴다)

Whether it is a multiline field. (the web uses a hidden <textarea>)

반환Returnsbool

TextInputstruct traits Default

소스source

글 입력 줄.

  • InputManager 가 하나 든다. 플랫폼이 이벤트를 넣고, 입력 필드가 꺼내 쓰고, 엔진이 프레임 끝에 finish_frame 을 부른다.

Text input queue.

  • InputManager holds one. The platform pushes events, input fields take them out, and the engine calls finish_frame at the end of the frame.
예제Example넣고, 필드가 꺼내고, 프레임 끝에 남은 것을 버리기Push, let a field take out, and drop the rest at the end of the frame
use vanilla::{TextInput, TextInputEvent, TextInputEventKind};

let mut text_input = TextInput::new();
text_input.push_focused_field_event(TextInputEventKind::Commit(String::from("a")));
text_input.push_event(TextInputEvent {
	target_field_id: 7,
	kind: TextInputEventKind::FocusGained,
});
text_input.push_event(TextInputEvent {
	target_field_id: 9,
	kind: TextInputEventKind::FocusLost,
});
let taken_list = text_input.take_events_for_field(7, true);
assert_eq!(taken_list, vec![TextInputEventKind::Commit(String::from("a")), TextInputEventKind::FocusGained]);
assert_eq!(text_input.get_event_count(), 1);
text_input.finish_frame();
assert_eq!(text_input.get_event_count(), 0);
생성자constructorpub fn new() -> TextInput#0.3.2 부터since 0.3.2소스source

생성.

Constructor.

반환ReturnsTextInput 이벤트도 필드 상태도 없는 빈 줄.An empty queue with no events and no field states.

메서드methodpub fn push_event(&mut self, event: TextInputEvent)#0.3.2 부터since 0.3.2소스source

이벤트 넣기. (플랫폼)

Pushes an event. (platform)

eventTextInputEvent
넣을 이벤트. (target_field_id 가 0 이면 포커스를 가진 필드 몫)Event to push. (for the field with focus if target_field_id is 0)
메서드methodpub fn push_focused_field_event(&mut self, kind: TextInputEventKind)#0.3.2 부터since 0.3.2소스source

포커스를 가진 필드에 갈 이벤트 넣기. (플랫폼)

Pushes an event bound for the field with focus. (platform)

kindTextInputEventKind
넣을 이벤트 내용. (target_field_id 0 으로 넣는다)Event content to push. (pushed with target_field_id 0)
메서드methodpub fn get_event_count(&self) -> usize#0.3.2 부터since 0.3.2소스source

쌓인 이벤트 수.

Number of queued events.

반환Returnsusize 아직 아무도 꺼내지 않은 이벤트 수.Number of events nobody has taken out yet.

메서드methodpub fn take_events_for_field(&self, field_id: u64, accepts_focused_field_events: bool) -> Vec<TextInputEventKind>#0.3.2 부터since 0.3.2소스source

필드 몫의 이벤트 꺼내기. (자기 id 로 온 것, 그리고 포커스 이벤트를 받을 수 있으면 0 으로 온 것)

  • 꺼낸 이벤트는 줄에서 빠진다. 포커스를 가진 필드가 둘이 되는 한 프레임 동안에도 같은 글이 두 번 들어가지 않는다.

Takes out the field's share of events. (those sent to its id, and those sent to 0 if it can receive focus events)

  • Taken events leave the queue. Even during a frame where two fields have focus, the same text does not go in twice.
field_idu64
꺼낼 필드 id.Field id to take out for.
accepts_focused_field_eventsbool
true 면 target_field_id 가 0 인 이벤트(포커스를 가진 필드 몫)도 꺼낸다.If true, also takes out events whose target_field_id is 0 (the share for the field with focus).

반환ReturnsVec<TextInputEventKind> 꺼낸 이벤트 내용 목록. (넣은 차례대로, 없으면 빈 목록)List of taken event contents. (in the order pushed, an empty list if none)

예제Exampleid 로 온 것과 포커스 몫 꺼내기Take out those sent to the id and the focus share
use vanilla::{TextInput, TextInputEvent, TextInputEventKind};

let mut text_input = TextInput::new();
text_input.push_focused_field_event(TextInputEventKind::CompositionStart);
text_input.push_event(TextInputEvent {
	target_field_id: 5,
	kind: TextInputEventKind::FocusGained,
});
assert!(text_input.take_events_for_field(3, false).is_empty());
assert_eq!(text_input.take_events_for_field(5, false), vec![TextInputEventKind::FocusGained]);
assert_eq!(text_input.take_events_for_field(3, true), vec![TextInputEventKind::CompositionStart]);
메서드methodpub fn register_field_state(&self, field_state: TextInputFieldState)#0.3.2 부터since 0.3.2소스source

필드 상태 올리기. (필드 tick, 같은 필드가 두 번 올리면 뒤의 것)

Publishes field state. (field tick, if the same field publishes twice, the later one)

field_stateTextInputFieldState
올릴 상태. (finish_frame 뒤 get_published_field_states 로 보인다)State to publish. (visible via get_published_field_states after finish_frame)
메서드methodpub fn get_published_field_states(&self) -> &[TextInputFieldState]#0.3.2 부터since 0.3.2소스source

지난 프레임에 올라온 필드 상태 목록. (올라온 순서 = 트리 순서)

List of field states published last frame. (published order = tree order)

반환Returns&[TextInputFieldState] 지난 프레임 상태 목록. (첫 finish_frame 전에는 비었다)List of last frame states. (empty before the first finish_frame)

메서드methodpub fn get_latest_focus_serial(&self) -> u64#0.3.2 부터since 0.3.2소스source

지난 프레임에 가장 나중에 포커스를 얻은 필드의 포커스 차례. (없으면 0)

Focus order of the field that got focus most recently last frame. (0 if none)

반환Returnsu64 포커스를 가진 필드의 focus_serial 가운데 가장 큰 값. (없으면 0)The largest focus_serial among fields with focus. (0 if none)

메서드methodpub fn get_active_field_state(&self) -> Option<&TextInputFieldState>#0.3.2 부터since 0.3.2소스source

글 입력을 받는 필드 상태. (지난 프레임에 포커스를 가진, 붙어 있는 필드 가운데 가장 나중 것)

State of the field receiving text input. (the latest among attached fields that had focus last frame)

반환ReturnsOption<&TextInputFieldState> 그 필드 상태. 포커스를 가지고 붙어 있는(is_attached) 필드가 없으면 None.That field state. None if no field has focus and is attached (is_attached).

예제Example포커스를 가진 붙은 필드 가운데 나중 것The later of the attached fields with focus
use vanilla::{Rect, TextInput, TextInputFieldState};

fn create_field_state(field_id: u64, focus_serial: u64) -> TextInputFieldState {
	TextInputFieldState {
		field_id,
		focus_serial,
		is_focused: true,
		is_attached: true,
		use_dominput: true,
		use_touch_end_focus: false,
		use_direct_touch: false,
		is_visible: true,
		field_rect: Rect::zero(),
		caret_rect: Rect::zero(),
		value: String::new(),
		selection_start: 0,
		cursor_index: 0,
		max_length: 0,
		value_revision: 0,
		is_multiline: false,
	}
}

let mut text_input = TextInput::new();
text_input.register_field_state(create_field_state(1, 4));
text_input.register_field_state(create_field_state(2, 6));
assert!(text_input.get_active_field_state().is_none());
text_input.finish_frame();
assert_eq!(text_input.get_active_field_state().map(|field_state| field_state.field_id), Some(2));
assert_eq!(text_input.get_latest_focus_serial(), 6);
메서드methodpub fn set_context_menu_request_position(&mut self, view_position: Option<Vector2>)#0.3.2 부터since 0.3.2소스source

문맥 메뉴 요청 자리 설정. (데스크탑 오른쪽 단추, 웹 필드 위의 오른쪽 클릭, 뷰 좌표. 이번 프레임에만 남는다)

Sets the context menu request position. (the desktop right button, a right click on a web field, view coordinates. It lasts only this frame)

view_positionOption<Vector2>
요청 자리. (뷰 좌표, None 이면 요청 없음. finish_frame 이 None 으로 돌린다)Request position. (view coordinates, None means no request. finish_frame resets it to None)
메서드methodpub fn get_context_menu_request_position(&self) -> Option<Vector2>#0.3.2 부터since 0.3.2소스source

문맥 메뉴 요청 자리.

Context menu request position.

반환ReturnsOption<Vector2> 이번 프레임의 요청 자리. (뷰 좌표, 요청이 없으면 None)This frame's request position. (view coordinates, None if no request)

메서드methodpub fn set_ime_commit_guard(&self, committed_text: &str)#0.3.2 부터since 0.3.2소스source

포커스를 잃으며 필드가 스스로 확정한 조합 글 기록. (필드)

  • 데스크탑에서 IME 를 끄면 OS 가 같은 조합 글을 Commit 으로 한 번 더 보낼 수 있다. 플랫폼이 그것을 버리게 한다.

Records composition text the field committed by itself on losing focus. (field)

  • On desktop, turning off the IME can make the OS send the same composition text once more as Commit. This lets the platform drop it.
committed_text&str
필드가 확정한 글. (finish_frame 을 두 번 지나면 기록이 사라진다)Text the field committed. (the record disappears after two finish_frame calls)
메서드methodpub fn consume_ime_commit_guard(&mut self, committed_text: &str) -> bool#0.3.2 부터since 0.3.2소스source

IME 확정 글이 필드가 이미 확정한 글이면 true 를 돌려주고 기록을 지운다. (플랫폼)

Returns true if the IME commit text is text the field already committed, and clears the record. (platform)

committed_text&str
IME 가 보낸 확정 글.Commit text sent by the IME.

반환Returnsbool 기록된 글과 같으면 true. (기록이 없거나 다르면 false, 기록은 그대로 둔다)True if equal to the recorded text. (false if there is no record or it differs, and the record is kept)

예제Example같은 확정 글을 한 번만 막기Block the same commit text only once
use vanilla::TextInput;

let mut text_input = TextInput::new();
text_input.set_ime_commit_guard("abc");
assert!(!text_input.consume_ime_commit_guard("xyz"));
assert!(text_input.consume_ime_commit_guard("abc"));
assert!(!text_input.consume_ime_commit_guard("abc"));
메서드methodpub fn set_pointer_click_count(&self, pointer_click_count: u32)#0.4.0 부터since 0.4.0소스source

마우스 누름 수 넣기. (웹 플랫폼이 mousedown 의 detail 을 넣는다, 0 이면 1)

Sets the mouse click count. (the web platform sets the mousedown detail, 1 if 0)

pointer_click_countu32
누름 수. (mousedown 의 detail, 두 번 누름이면 2, 0 이면 1)Click count. (the mousedown detail, 2 for a double click, 1 if 0)
메서드methodpub fn get_pointer_click_count(&self) -> u32#0.4.0 부터since 0.4.0소스source

마지막 마우스 누름 수. (넣은 적이 없으면 1)

The last mouse click count. (1 if never set)

반환Returnsu32 마지막 누름 수. (1 이상, 넣은 적이 없으면 1)The last click count. (1 or more, 1 if never set)

메서드methodpub fn request_ime_reset(&self)#0.3.2 부터since 0.3.2소스source

IME 조합 끊기 부탁. (필드가 조합 글을 스스로 확정했을 때. 데스크탑 플랫폼이 IME 를 껐다 켠다)

Requests breaking the IME composition. (when the field committed the composition text by itself. The desktop platform turns the IME off and on)

메서드methodpub fn take_ime_reset_request(&self) -> bool#0.3.2 부터since 0.3.2소스source

IME 조합 끊기 부탁 꺼내기. (플랫폼, 꺼내면 지워진다)

Takes out the IME composition break request. (platform, cleared when taken)

반환Returnsbool request_ime_reset 이 불렸으면 true.True if request_ime_reset was called.

메서드methodpub fn finish_frame(&mut self)#0.3.2 부터since 0.3.2소스source

프레임 마무리. (엔진이 프레임 끝에 부른다)

  • 아무도 꺼내지 않은 이벤트를 버리고, 이번 프레임에 올라온 상태를 지난 프레임 상태로 넘긴다.

Finishes the frame. (the engine calls it at the end of the frame)

  • Drops events nobody took out, and moves the states published this frame to the last frame states.

함수Functions

함수functionpub fn count_characters(text: &str) -> usize#0.3.2 부터since 0.3.2소스source

문자 수.

Character count.

text&str
셀 글.Text to count.

반환Returnsusize char 수. (바이트 수가 아니다)Number of chars. (not the byte count)

함수functionpub fn convert_character_index_to_byte_index(text: &str, character_index: usize) -> usize#0.3.2 부터since 0.3.2소스source

문자 자리 → 바이트 자리. (넘으면 끝)

Character position → byte position. (the end if beyond)

text&str
글.Text.
character_indexusize
문자 자리.Character position.

반환Returnsusize 그 문자가 시작하는 바이트 자리. (글 문자 수 이상이면 text.len())Byte position where that character starts. (text.len() if at or beyond the character count of the text)

함수functionpub fn convert_byte_index_to_character_index(text: &str, byte_index: usize) -> usize#0.3.2 부터since 0.3.2소스source

바이트 자리 → 문자 자리. (winit Ime::Preedit 의 커서가 바이트 단위다)

Byte position → character position. (the cursor of winit Ime::Preedit is in bytes)

text&str
글.Text.
byte_indexusize
바이트 자리.Byte position.

반환Returnsusize byte_index 앞에서 시작하는 문자 수. (글자 가운데 바이트면 그 글자 뒤 자리)Number of characters starting before byte_index. (the position after that character if the byte is in the middle of a character)

함수functionpub fn convert_utf16_index_to_character_index(text: &str, utf16_index: usize) -> usize#0.3.2 부터since 0.3.2소스source

UTF-16 자리 → 문자 자리. (DOM selection_start / selection_end)

UTF-16 position → character position. (DOM selection_start / selection_end)

text&str
글.Text.
utf16_indexusize
UTF-16 자리.UTF-16 position.

반환Returnsusize 문자 자리. (서로게이트 쌍 가운데면 그 글자 뒤 자리, 넘으면 문자 수)Character position. (the position after that character if in the middle of a surrogate pair, the character count if beyond)

예제Example이모지는 UTF-16 두 칸Emoji take two UTF-16 units
use vanilla::core::textinput::convert_utf16_index_to_character_index;

let text = "a\u{1F600}b";
assert_eq!(convert_utf16_index_to_character_index(text, 1), 1);
assert_eq!(convert_utf16_index_to_character_index(text, 2), 2);
assert_eq!(convert_utf16_index_to_character_index(text, 3), 2);
assert_eq!(convert_utf16_index_to_character_index(text, 99), 3);
함수functionpub fn convert_character_index_to_utf16_index(text: &str, character_index: usize) -> usize#0.3.2 부터since 0.3.2소스source

문자 자리 → UTF-16 자리. (DOM setSelectionRange)

Character position → UTF-16 position. (DOM setSelectionRange)

text&str
글.Text.
character_indexusize
문자 자리. (문자 수를 넘으면 끝으로 본다)Character position. (treated as the end if beyond the character count)

반환Returnsusize UTF-16 자리.UTF-16 position.

함수functionpub fn find_previous_grapheme_boundary(text: &str, character_index: usize) -> usize#0.4.0 부터since 0.4.0소스source

앞 글자 묶음 경계. (크롬 왼쪽 화살표의 PositionMoveType::kGraphemeCluster, 확장 자소 묶음 UAX #29)

Previous grapheme cluster boundary. (PositionMoveType::kGraphemeCluster of the Chrome left arrow, extended grapheme clusters UAX #29)

text&str
글.Text.
character_indexusize
문자 자리.Character position.

반환Returnsusize 자리보다 앞인 가장 가까운 경계의 문자 자리. (0 이면 0, 묶음 가운데면 그 묶음 앞)Character position of the nearest boundary before the position. (0 if 0, the start of the cluster if in the middle of one)

함수functionpub fn find_next_grapheme_boundary(text: &str, character_index: usize) -> usize#0.4.0 부터since 0.4.0소스source

뒤 글자 묶음 경계. (크롬 오른쪽 화살표와 Delete 키의 PositionMoveType::kGraphemeCluster)

Next grapheme cluster boundary. (PositionMoveType::kGraphemeCluster of the Chrome right arrow and Delete key)

text&str
글.Text.
character_indexusize
문자 자리.Character position.

반환Returnsusize 자리보다 뒤인 가장 가까운 경계의 문자 자리. (글 끝이면 문자 수)Character position of the nearest boundary after the position. (the character count at the end of the text)

함수functionpub fn collect_grapheme_boundaries(text: &str) -> Vec<usize>#0.4.0 부터since 0.4.0소스source

글자 묶음 경계 목록. (0 과 문자 수를 넣는다, 오름차순)

List of grapheme cluster boundaries. (includes 0 and the character count, ascending)

text&str
나눌 글.Text to split.

반환ReturnsVec<usize> 글자 묶음 경계의 문자 자리 목록. (0 과 문자 수를 넣는다, 오름차순)List of character positions of grapheme cluster boundaries. (includes 0 and the character count, ascending)

함수functionpub fn find_backward_deletion_boundary(text: &str, character_index: usize) -> usize#0.4.0 부터since 0.4.0소스source

뒤로 지우기(Backspace)로 지울 범위의 앞. (블링크 BackspaceStateMachine 을 옮긴 것)

  • 크롬은 뒤로 지우기를 글자 묶음이 아니라 코드 포인트 하나씩 지운다. 다만 CR LF, 이모지 표현 선택자(VS)와 그 바탕, 피부색 조정자와 그 바탕, ZWJ 로 이은 이모지, 국기(지역 표시 글자 둘), 키캡, 태그 묶음은 통째로 지운다.
  • 블링크의 그림 문자(IsExtendedPictographicGb11)는 Extended_Pictographic 이나 Emoji 다.
  • VS 앞 글자의 결합 등급(canonical combining class)이 0 인지는 원본(브라우저는 알려 주지 않는다)과 같게 결합 부호(일반 범주 M)가 아닌지로 본다.

Start of the range Backspace deletes. (a port of Blink's BackspaceStateMachine)

  • Chrome deletes one code point at a time on Backspace, not a grapheme cluster. However, CR LF, an emoji variation selector (VS) and its base, a skin tone modifier and its base, emoji joined with ZWJ, flags (two regional indicators), keycaps and tag sequences are deleted whole.
  • Blink's pictographic characters (IsExtendedPictographicGb11) are Extended_Pictographic or Emoji.
  • Whether the canonical combining class of the character before a VS is 0 is judged, as in the original (the browser does not expose it), by whether it is not a combining mark (general category M).
text&str
글.Text.
character_indexusize
커서의 문자 자리.Character position of the cursor.

반환Returnsusize 지울 범위 앞의 문자 자리.Character position of the start of the range to delete.

함수functionpub fn collect_word_boundaries(text: &str) -> Vec<usize>#0.4.0 부터since 0.4.0소스source

낱말 경계 목록. (크롬 낱말 나누기와 같게)

  • ICU 낱말 나누기(segment_words)에 크로미엄 ICU 의 wordbrk.patch 규칙을 더한다. 크롬은 마침표(U+002E, U+FF0E)를 숫자 사이에서만 잇고, 쌍점(U+003A, U+FE55, U+FF1A)은 잇지 않는다. (웹의 크롬 Intl.Segmenter 는 이미 그렇다)

List of word boundaries. (the same as Chrome word breaking)

  • Adds the rules of Chromium ICU's wordbrk.patch to ICU word breaking (segment_words). Chrome joins periods (U+002E, U+FF0E) only between digits and does not join colons (U+003A, U+FE55, U+FF1A). (Chrome's Intl.Segmenter on the web already does this)
text&str
글.Text.

반환ReturnsVec<usize> 낱말 경계의 문자 자리 목록. (0 과 문자 수를 넣는다, 오름차순)List of character positions of word boundaries. (includes 0 and the character count, ascending)

예제Example주소는 마침표에서 나뉘고 소수는 한 낱말이다Addresses split at periods and decimals are one word
use vanilla::core::textinput::collect_word_boundaries;

assert_eq!(collect_word_boundaries("www.example.com 3.14"), vec![0, 3, 4, 11, 12, 15, 16, 20]);
함수functionpub fn find_next_word_position(text: &str, character_index: usize, is_skip_spaces: bool) -> usize#0.4.0 부터since 0.4.0소스source

다음 낱말 자리. (크롬 오른쪽 낱말 이동과 앞으로 낱말 지우기, 블링크 NextWordPosition)

  • 맥과 리눅스는 지금 낱말의 끝("abc| def|"), 윈도우는 뒤 공백을 건너뛴 다음 낱말 앞("abc |def")이다. (editing_behavior.h 의 ShouldSkipSpaceWhenMovingRight)
  • 줄 끝에서는 다음 줄 앞으로 간다. 글 끝이면 문자 수다.

Next word position. (Chrome's move word right and delete word forward, Blink NextWordPosition)

  • On macOS and Linux, the end of the current word ("abc| def|"); on Windows, the start of the next word after skipping the trailing space ("abc |def"). (ShouldSkipSpaceWhenMovingRight in editing_behavior.h)
  • At the end of a line, goes to the start of the next line. The character count at the end of the text.
text&str
글.Text.
character_indexusize
커서의 문자 자리.Character position of the cursor.
is_skip_spacesbool
뒤 공백을 건너뛸지. (윈도우면 true)Whether to skip the trailing space. (true on Windows)

반환Returnsusize 다음 낱말의 문자 자리.Character position of the next word.

예제Example맥, 리눅스와 윈도우의 오른쪽 낱말 이동Moving a word right on macOS, Linux and Windows
use vanilla::core::textinput::find_next_word_position;

assert_eq!(find_next_word_position("abc def", 0, false), 3);
assert_eq!(find_next_word_position("abc def", 0, true), 4);
함수functionpub fn find_previous_word_position(text: &str, character_index: usize) -> usize#0.4.0 부터since 0.4.0소스source

앞 낱말 자리. (크롬 왼쪽 낱말 이동과 뒤로 낱말 지우기, 블링크 PreviousWordPosition, 모든 플랫폼에서 낱말 앞 "|abc |def")

  • 크롬 textarea 처럼 글자가 있는 줄의 앞에서는 앞 줄로 넘어가지 않는다. 글 앞이면 0 이다.

Previous word position. (Chrome's move word left and delete word backward, Blink PreviousWordPosition, the start of the word on all platforms "|abc |def")

  • Like Chrome's textarea, does not cross to the previous line from the start of a line with text. 0 at the start of the text.
text&str
글.Text.
character_indexusize
커서의 문자 자리.Character position of the cursor.

반환Returnsusize 앞 낱말의 문자 자리.Character position of the previous word.

예제Example왼쪽 낱말 이동Moving a word left
use vanilla::core::textinput::find_previous_word_position;

assert_eq!(find_previous_word_position("abc def", 7), 4);
assert_eq!(find_previous_word_position("ab\ncd", 3), 3);

TextInputKeyenum traits Clone, Copy, Debug, PartialEq, Eq

소스source

편집 키. (원본 handleCanvasKeydown 이 보는 키)

Editing key. (keys the original handleCanvasKeydown looks at)

이름Name설명Description
Backspace커서 앞 글자 지우기. (선택이 있으면 선택을 지운다)Deletes the character before the cursor. (deletes the selection if there is one)
Delete커서 뒤 글자 지우기. (선택이 있으면 선택을 지운다)Deletes the character after the cursor. (deletes the selection if there is one)
Left커서를 한 글자 왼쪽으로. (is_shift 면 선택을 늘린다)Moves the cursor one character left. (extends the selection if is_shift)
Right커서를 한 글자 오른쪽으로. (is_shift 면 선택을 늘린다)Moves the cursor one character right. (extends the selection if is_shift)
WordLeft커서를 앞 낱말 앞으로. (윈도우와 리눅스 Ctrl + 왼쪽, 맥 Option + 왼쪽, is_shift 면 선택을 늘린다. 블링크 MoveWordLeft)Moves the cursor to the start of the previous word. (Ctrl + Left on Windows and Linux, Option + Left on macOS, extends the selection if is_shift. Blink MoveWordLeft)
WordRight커서를 낱말 하나 오른쪽으로. (윈도우와 리눅스 Ctrl + 오른쪽, 맥 Option + 오른쪽, is_shift 면 선택을 늘린다. 블링크 MoveWordRight)Moves the cursor one word right. (Ctrl + Right on Windows and Linux, Option + Right on macOS, extends the selection if is_shift. Blink MoveWordRight)
DeleteWordBackward커서 앞 낱말 지우기. (윈도우와 리눅스 Ctrl + Backspace, 맥 Option + Backspace, 선택이 있으면 선택을 지운다. 블링크 DeleteWordBackward)Deletes the word before the cursor. (Ctrl + Backspace on Windows and Linux, Option + Backspace on macOS, deletes the selection if there is one. Blink DeleteWordBackward)
DeleteWordForward커서 뒤 낱말 지우기. (윈도우와 리눅스 Ctrl + Delete, 맥 Option + Delete, 선택이 있으면 선택을 지운다. 블링크 DeleteWordForward)Deletes the word after the cursor. (Ctrl + Delete on Windows and Linux, Option + Delete on macOS, deletes the selection if there is one. Blink DeleteWordForward)
Home줄 앞. (여러 줄 필드는 보이는 줄의 앞, 한 줄 필드는 글 앞. 맥은 Cmd + 왼쪽도, is_shift 면 선택을 늘린다)Line start. (the start of the visible line in a multiline field, the start of the text in a single-line field. Cmd + Left too on Mac, extends the selection if is_shift)
End줄 끝. (여러 줄 필드는 보이는 줄의 끝, 한 줄 필드는 글 끝. 맥은 Cmd + 오른쪽도, is_shift 면 선택을 늘린다)Line end. (the end of the visible line in a multiline field, the end of the text in a single-line field. Cmd + Right too on Mac, extends the selection if is_shift)
Up위 줄. (여러 줄 필드, 한 줄 DOM 입력 칸은 글 앞)Line up. (multiline fields, the start of the text in a single-line DOM input box)
Down아래 줄. (여러 줄 필드, 한 줄 DOM 입력 칸은 글 끝)Line down. (multiline fields, the end of the text in a single-line DOM input box)
PageUp한 화면만큼 위. (여러 줄 필드, 맥은 Option 과 함께)Up by one screen. (multiline fields, with Option on Mac)
PageDown한 화면만큼 아래. (여러 줄 필드, 맥은 Option 과 함께)Down by one screen. (multiline fields, with Option on Mac)
DocumentStart글 앞. (Ctrl + Home, 맥은 Cmd + 위)Text start. (Ctrl + Home, Cmd + Up on Mac)
DocumentEnd글 끝. (Ctrl + End, 맥은 Cmd + 아래)Text end. (Ctrl + End, Cmd + Down on Mac)
ScrollToDocumentStart맥 Home, End. (맥 키 묶음의 scrollToBeginningOfDocument, scrollToEndOfDocument) - 크롬 맥은 커서를 두고 넘길 수 있는 상자를 처음과 끝으로 넘기고, 넘길 것이 없으면 블링크 키 표대로 줄 앞과 끝으로 옮긴다. - Shift 와 함께면(is_shift) 키 묶음의 moveToBeginningOfDocumentAndModifySelection 처럼 글 앞과 끝까지 고른다.Mac Home, End. (scrollToBeginningOfDocument, scrollToEndOfDocument of the Mac key bindings) - Chrome on macOS leaves the cursor and scrolls a scrollable box to the start and end, and if there is nothing to scroll, moves to the line start and end per the Blink key table. - With Shift (is_shift), selects to the start and end of the text like moveToBeginningOfDocumentAndModifySelection of the key bindings.
ScrollToDocumentEnd맥 End. (ScrollToDocumentStart 의 끝 쪽, 맥 키 묶음의 scrollToEndOfDocument)Mac End. (the end side of ScrollToDocumentStart, scrollToEndOfDocument of the Mac key bindings)
ScrollPageUp맥 PageUp, PageDown. (맥 키 묶음의 scrollPageUp, scrollPageDown, 크롬 맥은 커서를 두고 한 화면만큼 넘긴다)Mac PageUp, PageDown. (scrollPageUp, scrollPageDown of the Mac key bindings, Chrome on macOS leaves the cursor and scrolls by one screen)
ScrollPageDown맥 PageDown. (ScrollPageUp 의 아래 쪽, 맥 키 묶음의 scrollPageDown)Mac PageDown. (the downward side of ScrollPageUp, scrollPageDown of the Mac key bindings)
Enter엔터. (한 줄 필드는 제출 이벤트를 내고, 여러 줄 필드는 줄을 넣는다)Enter. (fires a submit event in a single-line field, inserts a line break in a multiline field)
Tab원본 캔버스 모드처럼 필드는 쓰지 않는다. (게임이 다음 칸으로 옮길 때 보라고 넘긴다)As in the original canvas mode, the field does not use it. (passed on for the game to check when moving to the next field)
SelectAllCtrl(맥은 Cmd) + ACtrl (Cmd on Mac) + A
CopyCtrl(맥은 Cmd) + CCtrl (Cmd on Mac) + C
CutCtrl(맥은 Cmd) + XCtrl (Cmd on Mac) + X
PasteCtrl(맥은 Cmd) + VCtrl (Cmd on Mac) + V
Undo되돌리기. (Ctrl(맥은 Cmd) + Z, 윈도우는 Alt + Backspace 도. 원본 DOM 입력 칸의 브라우저 실행 취소)Undo. (Ctrl (Cmd on Mac) + Z, also Alt + Backspace on Windows. The browser undo of the original DOM input field)
Redo다시 하기. (Ctrl(맥은 Cmd) + Shift + Z, 윈도우와 리눅스는 Ctrl + Y, 윈도우는 Alt + Shift + Backspace 도)Redo. (Ctrl (Cmd on Mac) + Shift + Z, Ctrl + Y on Windows and Linux, also Alt + Shift + Backspace on Windows)

TextInputEventKindenum traits Clone, Debug, PartialEq

소스source

글 입력 이벤트 내용.

Text input event content.

이름Name값Value설명Description
CommitCommit(String)확정된 글. (IME 확정, 키로 친 글자)Committed text. (IME commit, characters typed with keys)
CompositionStart조합 시작. (원본 compositionstart)Composition start. (the original compositionstart)
PreeditPreedit{ text: String, cursor_index: Option<usize>, }조합 중인 글. 커서는 조합 글 안의 문자 자리. (원본 compositionupdate, winit Ime::Preedit)Text being composed. The cursor is a character position within the composition text. (the original compositionupdate, winit Ime::Preedit)
CompositionEnd조합 끝. (원본 compositionend)Composition end. (the original compositionend)
KeyKey{ key: TextInputKey, is_shift: bool, }편집 키.Editing key.
PastePaste(String)붙여 넣을 글. (웹에서 클립보드를 비동기로 읽은 뒤)Text to paste. (after reading the clipboard asynchronously on the web)
ReplaceValueReplaceValue{ value: String, selection_start: usize, selection_end: usize, }숨긴 <input> 의 값이 바뀜. (웹, 원본 handleDOMInputEvent)The hidden <input>'s value changed. (web, the original handleDOMInputEvent)
SelectionSelection{ start: usize, end: usize, }숨긴 <input> 의 선택이 바뀜. (웹, 원본 tick 의 selection 폴링)The hidden <input>'s selection changed. (web, the original tick's selection polling)
FocusGained숨긴 <input> 이 포커스를 얻음. (웹, 원본 input focus 이벤트)The hidden <input> got focus. (web, the original input focus event)
FocusLost숨긴 <input> 이 포커스를 잃음. (웹, 원본 input blur 이벤트)The hidden <input> lost focus. (web, the original input blur event)