vanilladocs
vanillapunch.com
API / core/modaldialog

core/modaldialog

모달 질문 창. (게임이 부르던 브라우저 window.alert, window.confirm, window.prompt 자리, 원본 core/modaldialog.js 와 같다)

  • 러스트 판은 엔진 함수 Engine::alert, Engine::confirm, Engine::prompt, 원본은 engine.alert, confirm, prompt 다. DevTools 의 Local Storage 탭도 이 창으로 키와 값을 묻고 지울지 묻는다.
  • 두 엔진 모두, 웹과 데스크탑 모두 엔진이 캔버스 위에 크롬 탭 모달 대화 상자(JavaScriptTabModalDialogViewViews)와 같은 질문 창을 그린다. (브라우저 창을 띄우지 않는다)
  • 자리: 캔버스(창) 안쪽 가로 가운데, 위 끝. (크롬은 탭 내용 영역 가로 가운데에서 툴바 아래 끝과 3px 겹친다. 캔버스에는 툴바가 없어 위 끝이다)
  • 제목: "이 페이지 내용:" (크롬이 출처가 없는 페이지(file:, data:)에 쓰는 제목) 닫기 X 는 없다.
  • alert 는 확인만, confirm 과 prompt 는 확인과 취소. 기본 단추는 확인이다. 단추 차례는 크롬처럼 윈도우 [확인][취소], 맥과 리눅스 [취소][확인].
  • prompt 입력 칸은 기본값을 넣고 모두 고른 채로 초점을 받는다. Enter 는 확인, Escape 는 취소.
  • 글(제목, 확인, 취소)은 브라우저 화면 언어 자리인 시스템 언어로 고른다. (core/browseruitext.rs)
  • 떠 있는 동안 원본처럼 씬과 async 작업을 갱신하지 않고(그리기는 멈춘 화면 그대로), 입력은 창만 받는다. 닫히면 눌린 키와 단추를 비운다.
  • 입력 칸은 글 입력 줄(core/textinput.rs)에서 IME 와 편집 키를 받는다. 웹은 원본처럼 숨긴 DOM 입력이 글을 받는다. 누르고 끌어 커서와 선택을 정한다.
  • 여러 개를 한 프레임에 부르면 차례로 띄운다.
  • 러스트 판은 ModalDialogHandle 을 돌려주고, 답하면 끝난다. (is_finished, 원본은 Promise) 끝난 뒤 부를 함수는 set_callback 으로 건다. 엔진 작업 안에서는 Engine::alert_async, confirm_async, prompt_async 의 Promise 를 await 한다. (떠 있는 동안은 async 작업도 멈춘다)

Modal question dialog. (in place of the browser window.alert, window.confirm, window.prompt that games called, the same as the original core/modaldialog.js)

  • The Rust version has the engine functions Engine::alert, Engine::confirm, Engine::prompt, the original has engine.alert, confirm, prompt. The DevTools Local Storage tab also asks for keys and values, and whether to delete, with this dialog.
  • In both engines, on the web and the desktop alike, the engine draws on the canvas a question dialog like the Chrome tab modal dialog (JavaScriptTabModalDialogViewViews). (no browser dialog is shown)
  • Position: horizontal center, top edge inside the canvas (window). (Chrome overlaps the bottom of the toolbar by 3px at the horizontal center of the tab content area. The canvas has no toolbar, so it is the top edge)
  • Title: "This page says" (the title Chrome uses for pages without an origin (file:, data:)) There is no close X.
  • alert has only OK, confirm and prompt have OK and Cancel. The default button is OK. Button order is like Chrome: Windows [OK][Cancel], macOS and Linux [Cancel][OK].
  • The prompt input field gets the default value and receives focus with everything selected. Enter confirms, Escape cancels.
  • The text (title, OK, Cancel) is chosen by the system language standing in for the browser UI language. (core/browseruitext.rs)
  • While it is open, the scene and async tasks are not updated like the original (drawing keeps the frozen screen), and only the dialog receives input. When it closes, pressed keys and buttons are cleared.
  • The input field receives IME and edit keys from the text input queue (core/textinput.rs). On the web a hidden DOM input receives the text like the original. Pressing and dragging sets the cursor and selection.
  • Several calls in one frame are shown one after another.
  • The Rust version returns a ModalDialogHandle, which finishes when answered. (is_finished, the original returns a Promise) Attach a function to call afterwards with set_callback. Inside engine tasks, await the Promise of Engine::alert_async, confirm_async, prompt_async. (async tasks also pause while it is open)

ModalDialogHandlestruct traits Clone

짝Counterpart: vanilla.js ModalDialogHandle소스source

질문 창 손잡이. (clone 은 같은 창을 가리킨다)

  • Engine::alert, confirm, prompt 가 돌려준다. 답하면 끝나고(is_finished), 답은 get_result, is_confirmed, get_prompt_text 로 읽는다.

Question dialog handle. (clones refer to the same dialog)

  • Returned by Engine::alert, confirm, prompt. Finishes when answered (is_finished), and the answer is read with get_result, is_confirmed, get_prompt_text.
예제Example확인 창을 띄우고 답 기다리기Show a confirm dialog and wait for the answer
use vanilla::{Engine, EngineConfiguration, ModalDialogResult};

let engine = Engine::new(EngineConfiguration::new());
let modal_dialog_handle = engine.confirm("Delete the save data?");
assert!(!modal_dialog_handle.is_finished());
assert_eq!(modal_dialog_handle.get_result(), None);
assert!(!modal_dialog_handle.is_confirmed());
modal_dialog_handle.set_callback(|result: &ModalDialogResult| {
	if let ModalDialogResult::Confirmed(_) = result {
		println!("deleted");
	}
});
예제Example씬에서 이름 묻기Ask for a name in a scene
use vanilla::Engine;

fn ask_player_name(engine: &Engine) {
	let modal_dialog_handle = engine.prompt("Name?", "Player");
	let callback_handle = modal_dialog_handle.clone();
	modal_dialog_handle.set_callback(move |_result| {
		match callback_handle.get_prompt_text() {
			Some(player_name) => {
				println!("{}", player_name);
			}
			None => {
				println!("cancelled");
			}
		}
	});
}
메서드methodpub fn is_finished(&self) -> bool#0.4.0 부터since 0.4.0소스source

답했는지.

Whether answered.

반환Returnsbool 확인이나 취소로 답했으면 true.true if answered with OK or Cancel.

짝Counterpart: vanilla.js ModalDialogHandle.isFinished

메서드methodpub fn get_result(&self) -> Option<ModalDialogResult>#0.4.0 부터since 0.4.0소스source

답. (아직이면 None)

Answer. (None if not yet)

반환ReturnsOption<ModalDialogResult> 답의 복사본. (아직 답하지 않았으면 None)A copy of the answer. (None if not answered yet)

짝Counterpart: vanilla.js ModalDialogHandle.getResult

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

확인했는지. (원본 confirm 이 돌려주는 값, 아직이거나 취소면 거짓)

Whether confirmed. (the value the original confirm returns, false if not yet or cancelled)

반환Returnsbool 확인으로 답했으면 true. (아직이거나 취소면 false)true if answered with OK. (false if not yet or cancelled)

짝Counterpart: vanilla.js ModalDialogHandle.isConfirmed

메서드methodpub fn get_prompt_text(&self) -> Option<String>#0.4.0 부터since 0.4.0소스source

입력한 글. (원본 prompt 가 돌려주는 값, 취소면 원본 null 처럼 None. 아직이어도 None)

The entered text. (the value the original prompt returns, None on cancel like the original null. Also None if not yet)

반환ReturnsOption<String> 확인했을 때의 입력 글. (alert 와 confirm 을 확인했으면 빈 글, 아직이거나 취소면 None)Input text when confirmed. (empty text if alert or confirm was confirmed, None if not yet or cancelled)

짝Counterpart: vanilla.js ModalDialogHandle.getPromptText

메서드methodpub fn set_callback(&self, callback: impl FnOnce(&ModalDialogResult) + 'static)#0.4.0 부터since 0.4.0소스source

끝난 뒤 부를 함수 걸기. (이미 끝났으면 바로 부른다)

  • 한 번만 불린다. 다시 걸면 앞의 함수를 바꾼다. (아직 끝나지 않았을 때)

Sets the function to call when finished. (calls it right away if already finished)

  • Called only once. Setting it again replaces the previous function. (while not finished yet)
callbackimpl FnOnce(&ModalDialogResult) + 'static
답을 받는 함수. (끝날 때 한 번)Function that receives the answer. (once, when finished)

짝Counterpart: vanilla.js ModalDialogHandle.setCallback

ModalDialogKindenum traits Clone, Copy, Debug, PartialEq, Eq

짝Counterpart: vanilla.js ModalDialogKind소스source

질문 창 종류. (원본 ModalDialogKind 의 alert, confirm, prompt)

Question dialog kind. (alert, confirm, prompt of the original ModalDialogKind)

이름Name설명Description
Alert알림 창. (window.alert 자리, 확인만 있다)Alert dialog. (in place of window.alert, only OK)
Confirm확인 창. (window.confirm 자리, 확인과 취소)Confirm dialog. (in place of window.confirm, OK and Cancel)
Prompt입력 창. (window.prompt 자리, 입력 칸과 확인과 취소)Prompt dialog. (in place of window.prompt, an input field with OK and Cancel)

ModalDialogResultenum traits Clone, Debug, PartialEq, Eq

짝Counterpart: vanilla.js ModalDialogResult소스source

질문 창의 답.

Answer of a dialog.

이름Name값Value설명Description
ConfirmedConfirmed(String)확인. (prompt 는 입력한 글, alert 와 confirm 은 빈 글)OK. (the entered text for prompt, empty text for alert and confirm)
Cancelled취소. (원본 prompt 의 null, confirm 의 false)Cancel. (null for the original prompt, false for confirm)