vanilladocs
vanillapunch.com
API / platform/desktop/textinput

platform/desktop/textinput

데스크탑 글 입력. (winit 0.30 창 이벤트 → 엔진 글 입력 줄, 시스템 클립보드)

  • 원본 UIInputField 의 DOM <input>(set_use_dominput(true)) 자리와 document keydown(캔버스 모드) 자리를 함께 맡는다.
  • KeyboardInput: 편집 키(Backspace, Delete, 화살표, Home, End, Enter, Tab), Ctrl/Cmd + A/C/V/X, KeyEvent.text 의 글자 → 글 입력 줄.
  • Ime: Preedit 는 조합 시작 / 조합 글 / 조합 끝으로, Commit 은 확정 글로 바꾼다. (Preedit 커서는 바이트 자리라 문자 자리로 바꾼다)
  • 프레임마다 지난 프레임 필드 상태를 읽어, 포커스를 가진 필드가 플랫폼 입력(use_dominput)을 쓸 때만 IME 를 켜고 후보 창 자리를 맞춘다. 포커스가 다른 필드로 옮겨 가거나 조합 중에 필드 안을 눌러 필드가 조합 글을 확정하면 IME 를 껐다 켜서 조합을 끊는다. (끊긴 조합 글은 필드가 이미 확정했으므로 OS 가 다시 보낸 같은 Commit 은 버린다)
  • 클립보드는 arboard 로 읽고 쓴다. (winit 에 클립보드가 없다. 리눅스는 Clipboard 객체가 살아 있어야 내용이 남아서 스레드에 하나 들고 있는다)

Desktop text input. (winit 0.30 window events → engine text input queue, system clipboard)

  • Covers both the role of the DOM <input> (set_use_dominput(true)) of the original UIInputField and that of document keydown (canvas mode).
  • KeyboardInput: editing keys (Backspace, Delete, arrows, Home, End, Enter, Tab), Ctrl/Cmd + A/C/V/X, characters of KeyEvent.text → text input queue.
  • Ime: Preedit becomes composition start / composition text / composition end, and Commit becomes committed text. (the Preedit cursor is a byte position, so it is converted to a character position)
  • Every frame reads the previous frame's field state, and turns IME on and positions the candidate window only when the focused field uses platform input (use_dominput). When focus moves to another field, or the field commits the composition text because it was pressed inside during composition, IME is turned off and on to cut the composition. (the field has already committed the cut composition text, so the same Commit sent again by the OS is discarded)
  • The clipboard is read and written with arboard. (winit has no clipboard. On Linux the content only stays while a Clipboard object is alive, so one is held per thread)
예제Example클립보드에 쓰고 다시 읽기 (시스템 클립보드를 바꿔서 실행하지 않는다)Write to the clipboard and read it back (not run since it changes the system clipboard)
use vanilla::platform;

platform::write_clipboard_text("vanilla");
assert_eq!(platform::read_clipboard_text().as_deref(), Some("vanilla"));
platform::read_clipboard_text_with_callback(Box::new(|text: String| {
	println!("{}", text);
}));

함수Functions

함수functionpub fn write_clipboard_text(text: &str)#0.3.2 부터since 0.3.2소스source

시스템 클립보드에 글 쓰기.

  • 클립보드를 열지 못하면 건너뛰고, 쓰지 못하면 표준 오류에 로그를 낸다.

Writes text to the system clipboard.

  • Skips if the clipboard cannot be opened, and logs to standard error if it cannot write.
text&str
쓸 글.Text to write.
함수functionpub fn read_clipboard_text() -> Option<String>#0.3.2 부터since 0.3.2소스source

시스템 클립보드 글 읽기. (글이 없거나 읽을 수 없으면 None)

Reads text from the system clipboard. (None if there is no text or it cannot be read)

반환ReturnsOption<String> 클립보드의 글. 글이 없거나 클립보드를 열거나 읽을 수 없으면 None.Clipboard text. None if there is no text or the clipboard cannot be opened or read.

함수functionpub fn read_clipboard_text_with_callback(callback: Box<dyn FnOnce(String)>)#0.4.0 부터since 0.4.0소스source

시스템 클립보드 글을 읽어 콜백에 넘기기. (원본 readClipboard 자리, 데스크탑은 그 자리에서 읽어 바로 부른다. 못 읽으면 빈 글)

Reads the system clipboard text and passes it to a callback. (in place of the original readClipboard, desktop reads it on the spot and calls right away. Empty text if it cannot be read)

callbackBox<dyn FnOnce(String)>
읽은 글을 받을 함수. (돌아오기 전에 한 번 불린다)Function to receive the text read. (called once before returning)
함수functionpub fn read_optional_clipboard_text_with_callback(callback: Box<dyn FnOnce(Option<String>)>)#0.4.0 부터since 0.4.0소스source

시스템 클립보드 글을 읽어 콜백에 넘기기. (원본 engine.readClipboardText 자리, 데스크탑은 그 자리에서 읽어 바로 부른다. 못 읽으면 None)

Reads the system clipboard text and passes it to a callback. (in place of the original engine.readClipboardText, desktop reads it on the spot and calls right away. None if it cannot be read)

callbackBox<dyn FnOnce(Option<String>)>
읽은 글을 받을 함수. (돌아오기 전에 한 번 불린다, 못 읽으면 None)Function to receive the text read. (called once before returning, None if it cannot be read)