ui/uiinputfield
입력 필드 (캔버스 기반).
Input field (canvas based).
UIInputFieldextends WorldNode
입력 필드 (캔버스 기반).
- 텍스트 렌더링은 UILabel 자식 노드 두 개로 (값 라벨 + 플레이스홀더 라벨).
- 클릭/드래그/커서 이동/선택은 모두 캔버스 측에서 직접 처리.
- DOM <input> 사용 여부는 옵션 (setUseDOMInput, 기본 false). true 일 때만 한글 IME / 모바일 소프트 키보드 / 시스템 클립보드가 동작. false 면 ASCII 위주 키보드 직접 처리.
- 우클릭 시 컨텍스트 메뉴 (잘라내기 / 복사 / 붙여넣기 / 모두 선택). 직접 누름(setUseDirectTouch) 필드도 브라우저 편집 칸 메뉴 대신 같은 메뉴다.
- 커서 이동과 Delete 는 크롬처럼 글자 묶음 단위, 뒤로 지우기는 블링크 BackspaceStateMachine 처럼 코드 포인트 하나(이모지 묶음은 통째로).
- DOM 입력은 크롬 입력 칸처럼 마우스로 두 번 누르면 낱말(윈도우는 뒤 공백까지), 세 번 누르면 글 전체를 고른다. (누름 수는 mousedown 의 detail)
- 캔버스 모드의 낱말 이동과 지우기는 크롬처럼 윈도우와 리눅스는 Ctrl, 맥은 Option 과 왼쪽, 오른쪽 화살표, Backspace, Delete 다. (블링크 NextWordPosition, PreviousWordPosition)
- 되돌리기와 다시 하기는 두 모드 모두 엔진이 이력을 맡는다. (러스트 판 TextEditBuffer 와 같은 블링크 묶음 규칙: 이어 친 글자는 한 번에, 커서를 옮기거나 선택을 바꾸면 끊긴다, 새 편집은 다시 하기 목록을 지운다, setText 는 목록을 비운다) 키는 Ctrl(맥은 Cmd) + Z, Ctrl(맥은 Cmd) + Shift + Z, 윈도우와 리눅스는 Ctrl + Y, 윈도우는 Alt + Backspace 도. DOM 입력은 브라우저의 되돌리기 키와 historyUndo, historyRedo 를 막고 엔진 이력으로 한다. IME 조합 중에는 되돌리지 않는다.
- setMultiline(true) 면 크롬 textarea 같은 여러 줄 입력이다. (DOM 입력은 숨긴 textarea) 글은 white-space: pre-wrap, overflow-wrap: break-word 처럼 줄바꿈 문자와 폭으로 나눈다. 줄 나눔 자리는 크롬 자신의 줄 나누기에서 읽는다. (러스트 판 ui/textarealayout.rs 와 같은 셈) Enter 는 줄을 넣고, 위아래와 page 는 엔진 배치로 옮기고, Home 과 End 는 보이는 줄의 앞과 끝, Ctrl(맥은 Cmd) + Home, End 는 글 앞과 끝이다. 넘치면 커서가 보이게 스크롤한다.
Input field (canvas based).
- Text rendering uses two UILabel child nodes (value label + placeholder label).
- Click/drag/cursor movement/selection are all handled directly on the canvas side.
- Using a DOM <input> is optional (setUseDOMInput, default false). Korean IME / mobile soft keyboard / system clipboard work only when true. When false, the keyboard is handled directly, mostly ASCII.
- Context menu on right click (cut / copy / paste / select all). Direct-touch fields (setUseDirectTouch) also get this menu instead of the browser edit-field menu.
- Cursor movement and Delete work per grapheme cluster like Chrome, Backspace removes one code point like Blink's BackspaceStateMachine (emoji sequences as a whole).
- With DOM input, a mouse double click selects a word (with trailing whitespace on Windows) and a triple click selects all text, like a Chrome text field. (The click count is the mousedown detail)
- In canvas mode, word movement and deletion use Ctrl on Windows and Linux and Option on Mac with the left and right arrows, Backspace and Delete, like Chrome. (Blink NextWordPosition, PreviousWordPosition)
- Undo and redo are handled by an engine history in both modes. (The same Blink grouping rules as TextEditBuffer in the Rust edition: consecutively typed characters undo at once, moving the cursor or changing the selection breaks the group, a new edit clears the redo list, setText clears the lists) Keys are Ctrl (Cmd on Mac) + Z, Ctrl (Cmd on Mac) + Shift + Z, Ctrl + Y on Windows and Linux, and also Alt + Backspace on Windows. DOM input blocks the browser's undo keys and historyUndo, historyRedo and uses the engine history. It does not undo during IME composition.
- With setMultiline(true) it is a multiline input like a Chrome textarea. (DOM input uses a hidden textarea) Text is split by line break characters and width like white-space: pre-wrap, overflow-wrap: break-word. Line break opportunities are read from Chrome's own line breaking. (the same computation as ui/textarealayout.rs in the Rust edition) Enter inserts a line, up, down and page keys move by the engine layout, Home and End go to the start and end of the visible line, and Ctrl (Cmd on Mac) + Home, End go to the start and end of the text. When it overflows it scrolls to keep the caret visible.
import { Engine, EngineConfiguration, UIScene, UIInputField, Vector2 } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
}
initialize(engine) {
super.initialize(engine);
const inputField = new UIInputField();
inputField.setEngine(engine);
inputField.setLocalPosition(Vector2.create(40, 40));
inputField.setContentSize(Vector2.create(320, 56));
inputField.setPlaceholder("Your name");
inputField.setMaxLength(16);
inputField.setOnChange((value) => {
console.log("change", value);
});
inputField.setOnSubmit((value) => {
console.log("submit", value);
});
const root = this.getRoot();
root.addChild(inputField);
inputField.attach();
inputField.setText("Player");
console.log(inputField.getText(), inputField.getCursorIndex());
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());설정.
Settings.
- engineEngine
- 엔진. (DOM 입력의 자리, 캔버스 사건, 문맥 메뉴에 쓴다, 주지 않으면 Engine.getEngine() 을 쓴다)Engine. (used for the DOM input position, canvas events and the context menu; Engine.getEngine() is used when not given)
DOM 입력 사용 설정. (attach 때 보므로 그 전에 정한다)
Sets whether to use the DOM input. (read at attach, so set it before)
- useboolean
- 참이면 숨은 DOM input 으로 글을 받는다. (한글 IME, 모바일 화면 키보드, 시스템 클립보드가 된다, 기본 거짓)If true, takes text through a hidden DOM input. (enables Korean IME, mobile on-screen keyboards and the system clipboard, default false)
짝Counterpart: vanilla-engine UIInputField.set_use_dom_input
import { Engine, EngineConfiguration, UIScene, UIInputField, Vector2 } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
}
initialize(engine) {
super.initialize(engine);
const inputField = new UIInputField();
inputField.setEngine(engine);
inputField.setUseDOMInput(true);
inputField.setUseTouchEndFocus(true);
inputField.setLocalPosition(Vector2.create(40, 40));
inputField.setContentSize(Vector2.create(320, 56));
inputField.setPlaceholder("Message");
const root = this.getRoot();
root.addChild(inputField);
inputField.attach();
console.log(inputField.isUsingDOMInput(), inputField.isFocused());
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());DOM 입력 사용 여부 반환.
Returns whether the DOM input is used.
반환Returnsboolean DOM 입력을 쓰면 참.True if the DOM input is used.
짝Counterpart: vanilla-engine UIInputField.is_using_dom_input
DOM 입력일 때 손을 뗄 때(touchend)도 포커스를 줄지. (기본 false, 꺼져 있으면 touchstart 에서만 준다) 켜면 사용자 활성화가 한 번도 없던 때(페이지의 첫 touchstart)에 얻은 포커스를 손을 뗄 때 다시 줘, 그런 포커스에 키보드를 띄우지 않는 브라우저(안드로이드 크롬, 웹뷰)에서도 키보드가 뜨게 한다.
Whether to also give focus on release (touchend) for DOM input. (default false, when off it is given only on touchstart) When on, focus obtained while there was no user activation yet (the page's first touchstart) is given again on release, so the keyboard appears even in browsers that do not show the keyboard for such focus (Android Chrome, webviews).
- useboolean
- 참이면 touchend 에서도 포커스를 준다. (기본 거짓)If true, also gives focus on touchend. (default false)
짝Counterpart: vanilla-engine UIInputField.set_use_touch_end_focus
touchend 포커스 사용 여부 반환.
Returns whether touchend focus is used.
반환Returnsboolean touchend 에서도 포커스를 주면 참.True if focus is also given on touchend.
짝Counterpart: vanilla-engine UIInputField.is_using_touch_end_focus
DOM 입력을 필드 위에서 손가락(마우스)이 직접 누르게 할지. (기본 false, 꺼져 있으면 DOM 입력은 누름을 받지 않고 캔버스가 포커스를 준다) 켜면 필드가 보이는 동안 투명한 DOM 입력이 필드 자리에서 누름을 받아, 브라우저의 기본 동작으로 포커스(다른 출처의 iframe 이면 그 프레임까지)와 키보드를 연다. 코드로 준 포커스를 받지 않는 웹뷰(앱 안의 iframe 등)에서 쓴다. 포커스를 받으면 커서는 글 끝에 둔다. 그 DOM 입력의 오른쪽 클릭은 브라우저 편집 칸 메뉴 대신 다른 필드와 같은 엔진 문맥 메뉴를 띄운다. (러스트 데스크탑과 같은 항목)
Whether to let the finger (mouse) press the DOM input directly over the field. (default false, when off the DOM input does not receive presses and the canvas gives focus) When on, while the field is visible a transparent DOM input receives presses at the field's position and, through the browser's default behavior, opens focus (including that frame for a cross-origin iframe) and the keyboard. Used in webviews that do not accept focus given by code (iframes inside apps, etc). On focus, the cursor is placed at the end of the text. Right-clicking that DOM input opens the same engine context menu as other fields instead of the browser edit-field menu. (the same items as the Rust desktop)
- useboolean
- 참이면 투명한 DOM 입력이 필드 자리에서 누름을 직접 받는다. (기본 거짓)If true, a transparent DOM input takes presses directly over the field. (default false)
짝Counterpart: vanilla-engine UIInputField.set_use_direct_touch
직접 누름 사용 여부 반환.
Returns whether direct touch is used.
반환Returnsboolean DOM 입력이 누름을 직접 받으면 참.True if the DOM input takes presses directly.
짝Counterpart: vanilla-engine UIInputField.is_using_direct_touch
여러 줄 설정. (크롬 textarea 처럼, DOM 입력은 숨긴 textarea 를 쓴다, 바꾸면 스크롤을 처음으로)
- 여러 줄이면 Enter 가 줄을 넣고(제출 콜백을 부르지 않는다), 글을 폭에 맞춰 나누고, 위아래로 옮기고, 넘치면 스크롤한다.
- UI 문서에 적는 원본 필드 속성이 아니다. (러스트 판도 반사에서 뺀다)
Sets multiline. (Like a Chrome textarea, DOM input uses a hidden textarea, changing it resets the scroll to the top)
- When multiline, Enter inserts a line (the submit callback is not called), text wraps to the width, the caret moves up and down, and it scrolls when it overflows.
- It is not an original field property written to UI documents. (the Rust edition also leaves it out of reflection)
- isMultilineboolean
- 참이면 여러 줄, 거짓이면 한 줄. (처음 거짓)True for multiline, false for single line. (false at first)
짝Counterpart: vanilla-engine UIInputField.set_multiline
import { Engine, EngineConfiguration, UIScene, UIInputField, Vector2 } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
}
initialize(engine) {
super.initialize(engine);
const inputField = new UIInputField();
inputField.setEngine(engine);
inputField.setMultiline(true);
inputField.setTabSize(4);
inputField.setLineHeight(32);
inputField.setLocalPosition(Vector2.create(40, 40));
inputField.setContentSize(Vector2.create(320, 160));
inputField.setPlaceholder("Memo");
const root = this.getRoot();
root.addChild(inputField);
inputField.attach();
inputField.setText("first line\nsecond line");
console.log(inputField.isMultiline(), inputField.getLineHeight(), inputField.getTabSize());
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());여러 줄인지.
Whether it is multiline.
반환Returnsboolean 여러 줄이면 참.True if multiline.
짝Counterpart: vanilla-engine UIInputField.is_multiline
줄 높이 설정. (여러 줄 필드, null 이면 CSS normal 이다. 크롬처럼 첫째 글꼴의 위아래 길이와 줄 사이로 셈한다)
Sets the line height. (Multiline field, null is CSS normal. Like Chrome it is computed from the ascent, descent and line gap of the primary font)
- lineHeightnumber | null
- 줄 높이. (내용 크기 단위, null 이면 CSS normal)Line height. (content size units, null for CSS normal)
짝Counterpart: vanilla-engine UIInputField.set_line_height
줄 높이 반환. (여러 줄 필드)
Returns the line height. (multiline field)
반환Returnsnumber 줄 높이. (정하지 않았으면 CSS normal 로 잰 값, 잴 문서가 없으면 글꼴 크기의 1.2 배를 반올림한 값)Line height. (the measured CSS normal value if not set, or the font size times 1.2 rounded when there is no document to measure with)
짝Counterpart: vanilla-engine UIInputField.get_line_height
탭 크기 설정. (여러 줄 필드, 공백 몇 개 폭, CSS tab-size)
Sets the tab size. (multiline field, width in spaces, CSS tab-size)
- tabSizenumber
- 탭 크기. (공백 몇 개 폭, 음수는 0, 기본 8)Tab size. (width in spaces, negative becomes 0, default 8)
짝Counterpart: vanilla-engine UIInputField.set_tab_size
탭 크기 반환.
Returns the tab size.
반환Returnsnumber 탭 크기. (공백 몇 개 폭)Tab size. (width in spaces)
짝Counterpart: vanilla-engine UIInputField.get_tab_size
위로 굴려 넘긴 만큼 반환. (여러 줄 필드, textarea scrollTop)
Returns the amount scrolled up. (multiline field, textarea scrollTop)
반환Returnsnumber 위로 넘긴 만큼. (내용 크기 단위)Amount scrolled up. (content size units)
짝Counterpart: vanilla-engine UIInputField.get_scroll_top
위로 굴려 넘기기. (여러 줄 필드, 다음 그리기에서 글 끝 안으로 줄인다)
Scrolls up. (Multiline field, clamped within the end of the text on the next draw)
- scrollTopnumber
- 위로 넘길 만큼. (내용 크기 단위, 음수는 0)Amount to scroll up. (content size units, negative becomes 0)
짝Counterpart: vanilla-engine UIInputField.set_scroll_top
되돌릴 것이 있는지.
Whether there is anything to undo.
반환Returnsboolean 되돌릴 묶음이 있으면 참.True if there is a group to undo.
짝Counterpart: vanilla-engine UIInputField.can_undo
import { Engine, EngineConfiguration, UIScene, UIInputField, Vector2 } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
}
initialize(engine) {
super.initialize(engine);
const inputField = new UIInputField();
inputField.setEngine(engine);
inputField.setLocalPosition(Vector2.create(40, 40));
inputField.setContentSize(Vector2.create(320, 56));
const root = this.getRoot();
root.addChild(inputField);
inputField.attach();
inputField.replaceSelection("a");
inputField.replaceSelection("b");
console.log(inputField.getText(), inputField.canUndo(), inputField.canRedo());
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());다시 할 것이 있는지.
Whether there is anything to redo.
반환Returnsboolean 다시 할 묶음이 있으면 참.True if there is a group to redo.
짝Counterpart: vanilla-engine UIInputField.can_redo
값 설정. (최대 길이를 넘으면 서로게이트 쌍을 쪼개지 않는 데까지 자르고 커서를 끝에 둔다, 바뀜 콜백은 부르지 않는다, 되돌리기와 다시 하기 목록과 조합 중인 글을 비운다)
Sets the value. (Cuts it to the maximum length without splitting a surrogate pair and puts the cursor at the end, does not call the change callback, clears the undo and redo lists and the composition text)
- textstring
- 넣을 글. (거짓 값이면 빈 글, 그 밖은 String 으로 바꾼다)Text to set. (empty for a falsy value, otherwise converted with String)
짝Counterpart: vanilla-engine UIInputField.set_text
값 반환.
Returns the value.
반환Returnsstring 입력한 글. (조합 중인 글은 빠진다)The entered text. (text being composed is not included)
짝Counterpart: vanilla-engine UIInputField.get_text
플레이스홀더 설정.
Sets the placeholder.
- textstring
- 값이 비었을 때 보일 글. (거짓 값이면 빈 글)Text shown when the value is empty. (empty for a falsy value)
짝Counterpart: vanilla-engine UIInputField.set_placeholder
최대 길이 설정.
Sets the maximum length.
- nnumber
- 최대 글자 수. (글의 length 로 센다, 소수는 버린다, 0 이하면 제한하지 않는다, 지금 값은 자르지 않는다)Maximum character count. (counted by the string length, the fraction is dropped, no limit if 0 or less, the current value is not cut)
짝Counterpart: vanilla-engine UIInputField.set_max_length
글자 크기 설정.
Sets the font size.
- sizenumber
- 글자 크기. (내용 크기 단위, 기본 28)Font size. (content size units, default 28)
짝Counterpart: vanilla-engine UIInputField.set_font_size
글꼴 설정.
Sets the font.
- fontFontFace | FontAsset | null
- 글꼴. (FontAsset 이면 그 fontFace, null 이나 undefined 면 시스템 글꼴, 그 밖의 꼴은 무시한다)Font. (A FontAsset uses its fontFace, null or undefined means the system font, other types are ignored)
안쪽 여백 설정.
Sets the inner padding.
- paddingnumber
- 왼쪽과 오른쪽 안쪽 여백. (내용 크기 단위, 기본 16)Left and right inner padding. (content size units, default 16)
짝Counterpart: vanilla-engine UIInputField.set_padding
배경색 설정.
Sets the background color.
- colorColor | string
- 배경색. (기본 흰색)Background color. (default white)
짝Counterpart: vanilla-engine UIInputField.set_background_color
모서리 둥글기 설정.
Sets the corner roundness.
- roundSizenumber
- 배경과 포커스 테두리의 모서리 반지름. (기본 8)Corner radius of the background and the focus border. (default 8)
짝Counterpart: vanilla-engine UIInputField.set_round_size
글자 색 설정.
Sets the text color.
- colorColor | string
- 값 글자의 색. (기본 #222222)Color of the value text. (default #222222)
짝Counterpart: vanilla-engine UIInputField.set_text_color
플레이스홀더 색 설정.
Sets the placeholder color.
- colorColor | string
- 플레이스홀더 글자의 색. (기본 #999999)Color of the placeholder text. (default #999999)
짝Counterpart: vanilla-engine UIInputField.set_placeholder_color
커서 색 설정. (조합 중 밑줄 색도 함께 바꾼다)
Sets the cursor color. (also changes the composition underline color)
- colorColor | string
- 커서와 조합 밑줄의 색. (기본 #5b8def)Color of the cursor and the composition underline. (default #5b8def)
짝Counterpart: vanilla-engine UIInputField.set_cursor_color
포커스 테두리 색 설정.
Sets the focus border color.
- colorColor | string
- 포커스 테두리 색. (기본 #f97316)Focus border color. (default #f97316)
짝Counterpart: vanilla-engine UIInputField.set_focus_border_color
포커스 테두리 두께 설정.
Sets the focus border width.
- widthnumber
- 포커스 테두리 두께. (0 이하면 그리지 않는다, 기본 3)Focus border width. (not drawn if 0 or less, default 3)
짝Counterpart: vanilla-engine UIInputField.set_focus_border_width
선택 영역 색 설정.
Sets the selection color.
- colorColor | string
- 선택 영역을 칠할 색. (기본 알파 0.35 의 파랑)Color to fill the selection with. (default blue with alpha 0.35)
짝Counterpart: vanilla-engine UIInputField.set_selection_color
플레이스홀더 반환.
Returns the placeholder.
반환Returnsstring 플레이스홀더 글.Placeholder text.
짝Counterpart: vanilla-engine UIInputField.get_placeholder
최대 길이 반환.
Returns the maximum length.
반환Returnsnumber 최대 글자 수. (0 이면 제한하지 않는다)Maximum character count. (0 means no limit)
짝Counterpart: vanilla-engine UIInputField.get_max_length
글자 크기 반환.
Returns the font size.
반환Returnsnumber 글자 크기.Font size.
짝Counterpart: vanilla-engine UIInputField.get_font_size
안쪽 여백 반환.
Returns the inner padding.
반환Returnsnumber 왼쪽과 오른쪽 안쪽 여백.Left and right inner padding.
짝Counterpart: vanilla-engine UIInputField.get_padding
배경색 반환.
Returns the background color.
반환ReturnsColor 배경색.Background color.
짝Counterpart: vanilla-engine UIInputField.get_background_color
모서리 둥글기 반환.
Returns the corner roundness.
반환Returnsnumber 배경의 모서리 반지름.Corner radius of the background.
짝Counterpart: vanilla-engine UIInputField.get_round_size
글자 색 반환.
Returns the text color.
반환ReturnsColor 값 글자의 색.Color of the value text.
짝Counterpart: vanilla-engine UIInputField.get_text_color
플레이스홀더 색 반환.
Returns the placeholder color.
반환ReturnsColor 플레이스홀더 글자의 색.Color of the placeholder text.
짝Counterpart: vanilla-engine UIInputField.get_placeholder_color
커서 색 반환.
Returns the cursor color.
반환ReturnsColor 커서 색.Cursor color.
짝Counterpart: vanilla-engine UIInputField.get_cursor_color
커서 자리 반환.
Returns the cursor position.
반환Returnsnumber 커서 자리. (값 안의 글자 위치, 0 ~ 값 길이)Cursor position. (character position in the value, 0 ~ value length)
짝Counterpart: vanilla-engine UIInputField.get_cursor_index
선택 시작 자리 반환.
Returns the selection start position.
반환Returnsnumber 선택의 고정 끝. (커서 자리와 같으면 선택이 없다)The fixed end of the selection. (no selection if equal to the cursor position)
짝Counterpart: vanilla-engine UIInputField.get_selection_start
조합 중인 글 반환.
Returns the text being composed.
반환Returnsstring IME 가 조합 중인 글. (없으면 빈 글)Text being composed by the IME. (empty if none)
짝Counterpart: vanilla-engine UIInputField.get_composition
보이는 글 반환. (값의 커서 자리에 조합 글을 끼운 것, 고른 채 조합하면 고른 글 자리를 조합 글로 갈음한 것)
Returns the visible text. (The value with the composition text inserted at the cursor position, or replacing the selected text when composing with a selection)
반환Returnsstring 보이는 글. (조합 중이 아니면 값 그대로)The displayed text. (the value itself when not composing)
짝Counterpart: vanilla-engine UIInputField.get_display_text
IME 조합 중인지.
Whether IME composition is in progress.
반환Returnsboolean 조합 중이면 참.True while composing.
짝Counterpart: vanilla-engine UIInputField.is_composing
바뀜 콜백 설정.
Sets the change callback.
- callback(value: string) => void
- 사용자 입력으로 값이 바뀔 때마다 부를 함수. (인자는 새 값, setText 로 바꿀 때는 부르지 않는다, null 이면 부르지 않는다)Function called whenever user input changes the value. (the argument is the new value, not called when changed with setText, not called if null)
짝Counterpart: vanilla-engine UIInputField.set_on_change
제출 콜백 설정.
Sets the submit callback.
- callback(value: string) => void
- 포커스된 채 Enter 를 누르면 부를 함수. (인자는 지금 값, null 이면 부르지 않는다)Function called when Enter is pressed while focused. (the argument is the current value, not called if null)
짝Counterpart: vanilla-engine UIInputField.set_on_submit
입력 라이프사이클: 활성화(attach) / 비활성화(detach).
Input lifecycle: activation (attach) / deactivation (detach).
짝Counterpart: vanilla-engine UIInputField.attach
입력 끄기. (DOM 입력, 키보드, 문맥 메뉴 사건을 떼고 메뉴를 닫는다)
Turns input off. (removes the DOM input, keyboard and context menu events and closes the menu)
짝Counterpart: vanilla-engine UIInputField.detach
포커스 여부 반환.
Returns whether it has focus.
반환Returnsboolean 포커스를 가졌으면 참.True if it has focus.
짝Counterpart: vanilla-engine UIInputField.is_focused
매 프레임: 라벨 위치 / 텍스트 동기, DOM 위치 동기, 커서 깜빡임, selection 폴링.
Every frame: label position / text sync, DOM position sync, cursor blink, selection polling.
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
캔버스 측 터치 (포지션 기반 커서 / 드래그 선택). pointer-events: none 인 DOM input 이 클릭을 가로채지 않으므로 항상 여기로 들어옴.
Canvas side touch (position based cursor / drag selection). Since the DOM input with pointer-events: none does not intercept clicks, input always comes here.
- viewInputPositionVector2
- 누른 자리. (뷰 좌표)Press position. (view coordinates)
터치 이동. (누른 자리부터 지금 자리까지 선택한다)
Touch move. (selects from the press position to the current position)
- viewInputPositionVector2
- 옮긴 자리. (뷰 좌표)Moved position. (view coordinates)
터치 뗌. (끌어 선택하기를 끝낸다)
Touch release. (ends drag selection)
터치 취소. (끌어 선택하기를 끝낸다)
Touch cancel. (ends drag selection)
localX(노드 로컬 X) → 문자 인덱스. 측정은 오프스크린 2D ctx 로. (메인 캔버스는 WebGL2 컨텍스트라 2D 측정 불가)
localX (node local X) → character index. Measured with an offscreen 2D ctx. (The main canvas is a WebGL2 context, so 2D measurement is not possible)
- localXnumber
- 노드 안의 X. (내용 영역 왼쪽이 0)X inside the node. (0 at the left of the content area)
반환Returnsnumber 그 자리에 가장 가까운 글자 묶음 경계. (UTF-16 단위, 0 ~ 값 길이, 잴 컨텍스트가 없으면 값 길이)The grapheme cluster boundary nearest to that point. (UTF-16 units, 0 to the value length, the value length if there is no context to measure with)
짝Counterpart: vanilla-engine UIInputField.measure_index_at_local_x
캔버스 모드 키 입력 처리. (포커스일 때만, Ctrl 이나 Cmd 와 A, C, X, V, 지우기, 화살표, Home, End, Enter, 글자 한 개)
Handles canvas mode key input. (only while focused, Ctrl or Cmd with A, C, X, V, deletion, arrows, Home, End, Enter, a single character)
- eventKeyboardEvent
- 문서의 keydown 사건.The document's keydown event.
커서 옮기기.
Moves the cursor.
- newIndexnumber
- 옮길 자리. (UTF-16 단위, 0 ~ 값 길이로 자른다, 서로게이트 쌍 가운데면 그 글자 뒤로 본다)Index to move to. (UTF-16 units, clamped to 0 to the value length, an index inside a surrogate pair is taken as after that character)
- extendSelectionboolean
- 참이면 선택의 고정 끝을 두고 선택을 늘린다.If true, keeps the fixed end of the selection and extends the selection.
짝Counterpart: vanilla-engine UIInputField.move_cursor
선택 / 클립보드.
Selection / clipboard.
반환Returnsboolean 선택한 글이 있으면 참.True if text is selected.
짝Counterpart: vanilla-engine UIInputField.has_selection
선택 범위 반환.
Returns the selection range.
반환Returns{ start: number, end: number } | null 선택 범위. (start 가 작은 쪽, 선택이 없으면 null)Selection range. (start is the smaller side, null if there is no selection)
짝Counterpart: vanilla-engine UIInputField.get_selection_range
선택한 글 반환.
Returns the selected text.
반환Returnsstring 선택한 글. (없으면 빈 글)The selected text. (empty if none)
짝Counterpart: vanilla-engine UIInputField.get_selection_text
선택을 글로 바꾸기. (선택이 없으면 커서 자리에 끼운다, 바뀜 콜백을 부른다)
- 최대 길이가 있으면 블링크 입력 칸처럼 넣는 글을 남은 길이까지만 넣는다. (서로게이트 쌍은 쪼개지 않는다)
Replaces the selection with text. (Inserts at the cursor if there is no selection, calls the change callback)
- With a maximum length, inserts only as much of the text as the remaining length allows, like a Blink text field. (Surrogate pairs are not split)
- textstring
- 넣을 글. (빈 글이면 선택을 지운다, 글자 넣기 되돌리기 묶음이다)Text to insert. (an empty string deletes the selection, it is an insert text undo group)
짝Counterpart: vanilla-engine UIInputField.replace_selection
잘라내기. (선택한 글을 클립보드에 쓰고 지운다, 선택이 없으면 아무것도 하지 않는다)
Cut. (writes the selected text to the clipboard and deletes it, does nothing if there is no selection)
짝Counterpart: vanilla-engine UIInputField.cut
복사. (선택한 글을 클립보드에 쓴다, 선택이 없으면 아무것도 하지 않는다)
Copy. (writes the selected text to the clipboard, does nothing if there is no selection)
짝Counterpart: vanilla-engine UIInputField.copy
붙여넣기. (클립보드 글을 비동기로 읽어 선택 자리에 넣는다, 읽지 못하거나 비었으면 무시한다)
Paste. (reads the clipboard text asynchronously and inserts it at the selection, ignored if it cannot be read or is empty)
짝Counterpart: vanilla-engine UIInputField.paste
문맥 메뉴 항목 부탁. (다음 tick 에 한다, UIInputFieldMenuAction)
Requests a context menu item. (Done on the next tick, UIInputFieldMenuAction)
- menuActionstring
- 할 항목. (UIInputFieldMenuAction 의 값)Item to perform. (a UIInputFieldMenuAction value)
짝Counterpart: vanilla-engine UIInputField.request_menu_action
import { Engine, EngineConfiguration, UIScene, UIInputField, UIInputFieldMenuAction, Vector2 } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
}
initialize(engine) {
super.initialize(engine);
const inputField = new UIInputField();
inputField.setEngine(engine);
inputField.setLocalPosition(Vector2.create(40, 40));
inputField.setContentSize(Vector2.create(320, 56));
const root = this.getRoot();
root.addChild(inputField);
inputField.attach();
inputField.setText("Invite code 1234");
inputField.selectAll();
inputField.requestMenuAction(UIInputFieldMenuAction.copy);
console.log(inputField.getSelectionText());
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());문맥 메뉴 띄우기. (엔진이 그린 잘라내기, 복사, 붙여넣기, 모두 선택 메뉴, 러스트 판 show_context_menu 와 같다)
- 루트의 마지막 자식 노드(UIInputFieldContextMenu 컴포넌트)로 만들어 위에 그린다. 메뉴 왼쪽 위가 누른 자리다.
- 메뉴 밖을 누르거나, 필드가 포커스를 잃거나 트리에서 빠지면 닫힌다.
Shows the context menu. (An engine-drawn cut, copy, paste and select all menu, same as show_context_menu in the Rust edition)
- It is made as the last child node of the root (a UIInputFieldContextMenu component) and drawn on top. The menu top left is the pressed point.
- It closes when pressed outside the menu, or when the field loses focus or leaves the tree.
- viewPositionVector2
- 메뉴 왼쪽 위. (뷰 좌표)Top left of the menu. (view coordinates)
UIInputFieldMenuActionenum
문맥 메뉴 항목. (잘라내기 / 복사 / 붙여넣기 / 모두 선택, requestMenuAction 이 받는다)
Context menu item. (cut / copy / paste / select all, received by requestMenuAction)
| 이름Name | 값Value | 설명Description |
|---|---|---|
cut | cut | 잘라내기.Cut. |
copy | copy | 복사.Copy. |
paste | paste | 붙여넣기.Paste. |
selectAll | selectAll | 모두 선택.Selects all. |