platform/web/textinput
웹 글 입력. (숨긴 DOM <input> → 엔진 글 입력 줄, 오른쪽 클릭, 캔버스 모드 키, 클립보드)
- 원본 UIInputField 의 DOM 쪽을 옮긴 것이다. 원본은 필드가 자기 <input> 을 만들고 리스너를 단다. 러스트 판은 필드가 프레임마다 상태(자리, 값, 선택, 포커스)를 엔진에 올리고, 여기서 attach 한 DOM 입력 필드마다 숨긴 <input> 을 하나씩 맞춘다.
- 값과 선택은 DOM 이 주인이다. input / compositionstart / compositionupdate / compositionend / Enter keydown / focus / blur 를 그 필드 id 로 글 입력 줄에 넣고(replaceValue, 조합, 포커스), 화살표 같은 네이티브 이동은 프레임마다 선택을 폴링해 넣는다. (원본 tick)
- 필드 쪽에서 값이나 커서를 바꾸면(set_text, 누른 자리, 잘라내기) 상태의 value_revision 이 늘고, 여기서 <input> 에 다시 쓴다. (조합 중엔 미룬다)
- iOS 는 사용자 제스처 안에서 focus() 해야 키보드가 뜬다. 원본처럼 캔버스 touchstart / mousedown(설정하면 touchend)에 동기 핸들러를 달아 지난 프레임 필드 자리로 맞춰 보고 그 자리에서 focus / blur 한다.
- 필드 위의 오른쪽 클릭은 원본처럼 브라우저 메뉴를 막고, 데스크탑 오른쪽 단추와 같은 문맥 메뉴 요청(set_context_menu_request_position)으로 넣는다. 필드가 엔진이 그린 메뉴(UIInputFieldContextMenu)를 연다. 그 메뉴 위의 오른쪽 클릭도 브라우저 메뉴를 막는다.
- use_dominput 이 꺼진 필드는 원본 캔버스 모드처럼 window keydown 을 편집 키와 글자로 바꿔 넣는다.
- DOM 이벤트 리스너는 엔진을 빌리지 않는다. 대기 줄(PENDING_EVENT_LIST)에 넣고 다음 프레임 시작에 엔진으로 옮긴다. (apply_frame 이 부르는 focus() 가 그 자리에서 focus / blur 이벤트를 부르기 때문)
- 원본과 다른 것: 숨긴 <input> 은 필드가 tick 을 도는 동안만 있다. (노드를 끄거나 지우면 함께 빠진다) setTimeout 으로 미루는 커서 옮기기는 원본과 같다.
Web text input. (hidden DOM <input> → engine text input queue, right clicks, canvas mode keys, clipboard)
- A port of the DOM side of the original UIInputField. In the original each field creates its own <input> and attaches listeners. In the Rust version fields post their state (position, value, selection, focus) to the engine every frame, and here one hidden <input> is matched to each attached DOM input field.
- The DOM owns the value and selection. input / compositionstart / compositionupdate / compositionend / Enter keydown / focus / blur are put into the text input queue with that field id (replaceValue, composition, focus), and native moves like arrows are put in by polling the selection every frame. (the original tick)
- When the field side changes the value or cursor (set_text, pressed position, cut), the state's value_revision increases and it is written back to the <input> here. (deferred during composition)
- iOS shows the keyboard only if focus() is called inside a user gesture. As in the original, synchronous handlers are attached to canvas touchstart / mousedown (touchend if set), which check against the previous frame's field positions and focus / blur on the spot.
- A right click on a field blocks the browser menu like the original and is put in as a context menu request (set_context_menu_request_position), the same as the desktop right button. The field opens the menu drawn by the engine (UIInputFieldContextMenu). A right click on that menu also blocks the browser menu.
- Fields with use_dominput off convert window keydown into editing keys and characters, like the original canvas mode.
- DOM event listeners do not borrow the engine. They go into a pending queue (PENDING_EVENT_LIST) and move to the engine at the start of the next frame. (because focus() called by apply_frame fires focus / blur events on the spot)
- Differences from the original: the hidden <input> exists only while the field runs its tick. (it goes away when the node is turned off or removed) Cursor moves deferred with setTimeout are the same as the original.
use vanilla::platform;
platform::write_clipboard_text("vanilla");
platform::read_clipboard_text_with_callback(Box::new(|text: String| {
println!("{}", text);
}));함수Functions
시스템 클립보드에 글 쓰기. (navigator.clipboard.writeText, 실패는 무시. 원본 writeClipboard)
Writes text to the system clipboard. (navigator.clipboard.writeText, failure ignored. the original writeClipboard)
- text&str
- 쓸 글.Text to write.
시스템 클립보드 글 읽기. (웹은 비동기라 그 자리에서 읽지 못한다. read_clipboard_text_with_callback 이나 request_clipboard_paste 로 읽는다)
Reads text from the system clipboard. (web is asynchronous and cannot read on the spot. Read with read_clipboard_text_with_callback or request_clipboard_paste)
반환ReturnsOption<String> 늘 None.Always None.
시스템 클립보드 글을 비동기로 읽어 콜백에 넘기기. (원본 readClipboard 의 navigator.clipboard.readText().then, 못 읽거나 거부되면 빈 글)
Reads the system clipboard text asynchronously and passes it to a callback. (navigator.clipboard.readText().then of the original readClipboard, empty text if it cannot be read or is refused)
- callbackBox<dyn FnOnce(String)>
- 읽은 글을 받을 함수. (readText 가 끝난 뒤 한 번 불린다)Function to receive the text read. (called once after readText finishes)
pub fn read_optional_clipboard_text_with_callback(callback: Box<dyn FnOnce(Option<String>)>)#시스템 클립보드 글을 비동기로 읽어 콜백에 넘기기. (원본 engine.readClipboardText, 클립보드가 없거나 거부되면 원본 null 자리의 None)
Reads the system clipboard text asynchronously and passes it to a callback. (the original engine.readClipboardText, None in place of the original null if there is no clipboard or it is refused)
- callbackBox<dyn FnOnce(Option<String>)>
- 읽은 글을 받을 함수. (readText 가 끝난 뒤 한 번, navigator.clipboard 가 없으면 그 자리에서 None 으로 불린다)Function to receive the text read. (called once after readText finishes, called on the spot with None if navigator.clipboard is missing)