vanilladocs
vanillapunch.com
API / ui/uiconfirmwindow

ui/uiconfirmwindow

확인 창. (vanilla.js 의 ui/uiconfirmwindow.js, UIConfirmWindow)

  • 제목, 묻는 글, 취소와 확인 두 단추. UIWindow 라 UIWindowLayer 로 띄운다.
  • 묻는 글은 판의 너비에서 줄을 바꾸고 줄 수에 맞춰 판의 세로가 정해진다. 글이 길어 영역의 세로를 넘으면 글 칸만 스크롤되고 두 단추는 늘 보인다.
  • 단추는 왼쪽이 취소, 오른쪽이 확인(강조)이다. 오른쪽에서 왼쪽 언어(set_right_to_left)면 차례를 뒤집는다.
  • 확인을 누르면 확인 알림 뒤 닫힌다. 취소, 바깥 누르기, close_top_window, close_all_windows 로 닫히면 취소 알림이다.
  • 사용:
let window_id = UIConfirmWindow::create(node_tree, layer_id, "quit", UIConfirmWindowOptions { title: String::from("나가기"), message: String::from("정말 나갈까요?"), ..UIConfirmWindowOptions::default() });
if let Some(confirm_window) = node_tree[window_id].get_component_mut::<UIWindow>().and_then(|window| window.get_behavior_mut::<UIConfirmWindow>()) {
    confirm_window.set_confirm_event(Some(Box::new(move || { leave_requested.set(true); })));
}
UIWindowLayer::open_window_in_tree(node_tree, layer_id, window_id);
  • 원본과 다른 것:
  • 원본은 UIWindow 를 상속한다. 러스트 판은 UIWindow 의 덮어쓸 자리(UIWindowBehavior)를 구현한 값이다. (UIWindow::get_behavior_mut 으로 꺼낸다)
  • 글 줄 수는 원본처럼 레이아웃 때 바로 잰다. Graphic 이 없는 자리라 등록된 글꼴로 잰다. (UILabel 이 품은 Text 의 wrap_lines_without_graphic) 글꼴이 하나도 없어 잴 수 없을 때만(데스크탑에 글꼴 파일이 없는 경우) 한 줄로 놓고, 글이 한 번 그려져 줄을 나누면 다음 tick 에 다시 놓는다.
  • 제목과 묻는 글은 원본처럼 UILabel 이다. 오른쪽에서 왼쪽 언어면 원본처럼 두 글에 Rtl 방향을 걸고(아니면 Inherit) 단추 차례를 뒤집는다. set_right_to_left 는 창 노드를 받지 않아 글 방향을 다음 놓을 때 건다. 원본처럼 글 방향을 바로 걸려면 set_right_to_left_in_tree 를 부른다. (단추 차례는 원본도 다음 놓을 때)
  • 알림은 인자 없는 Box<dyn FnMut()> 다.

Confirm window. (vanilla.js ui/uiconfirmwindow.js, UIConfirmWindow)

  • A title, a question text, and two buttons, cancel and confirm. It is a UIWindow, so it is opened with UIWindowLayer.
  • The question text wraps at the panel width, and the panel height is set to fit the number of lines. If the text is long and exceeds the area height, only the text area scrolls and the two buttons are always visible.
  • The buttons are cancel on the left and confirm (highlighted) on the right. For right-to-left languages (set_right_to_left), the order is reversed.
  • Pressing confirm closes it after the confirm notification. Closing by cancel, outside press, close_top_window, or close_all_windows gives the cancel notification.
  • Usage:
let window_id = UIConfirmWindow::create(node_tree, layer_id, "quit", UIConfirmWindowOptions { title: String::from("Leave"), message: String::from("Really leave?"), ..UIConfirmWindowOptions::default() });
if let Some(confirm_window) = node_tree[window_id].get_component_mut::<UIWindow>().and_then(|window| window.get_behavior_mut::<UIConfirmWindow>()) {
    confirm_window.set_confirm_event(Some(Box::new(move || { leave_requested.set(true); })));
}
UIWindowLayer::open_window_in_tree(node_tree, layer_id, window_id);
  • Differences from the original:
  • The original inherits UIWindow. The Rust version is a value implementing UIWindow's override points (UIWindowBehavior). (taken out with UIWindow::get_behavior_mut)
  • The number of text lines is measured right at layout as in the original. Since there is no Graphic there, it measures with the registered fonts. (wrap_lines_without_graphic of the Text that UILabel holds) Only when it cannot measure because there are no fonts at all (no font files on desktop), it lays out as one line, and once the text is drawn and wraps, it lays out again on the next tick.
  • The title and question text are UILabels as in the original. For right-to-left languages, as in the original, it sets the Rtl direction on both texts (Inherit otherwise) and reverses the button order. set_right_to_left does not take the window node, so the text direction is applied at the next layout. To apply the text direction right away as in the original, call set_right_to_left_in_tree. (the button order is at the next layout in the original too)
  • The notification is an argumentless Box<dyn FnMut()>.

UIConfirmWindowOptionsstruct traits Clone, Debug, PartialEq, Default

소스source

확인 창 설정. (원본 options = { title = "", message = "", cancelText = "취소", confirmText = "확인" })

Confirm window settings. (original options = { title = "", message = "", cancelText = "Cancel", confirmText = "OK" })

예제Example제목과 묻는 글만 바꾸고 단추 글은 기본값Changing only the title and question text, with default button texts
use vanilla::UIConfirmWindowOptions;

let options = UIConfirmWindowOptions {
	title: String::from("Delete"),
	message: String::from("Delete this save file?"),
	..UIConfirmWindowOptions::default()
};
assert_eq!(options.cancel_text, UIConfirmWindowOptions::default().cancel_text);
assert!(UIConfirmWindowOptions::default().title.is_empty());
필드fieldpub title: String#0.4.0 부터since 0.4.0소스source

비면 제목 줄을 없앤다.

If empty, the title line is removed.

반환ReturnsString

필드fieldpub message: String#0.4.0 부터since 0.4.0소스source

묻는 글. (판의 너비에서 줄을 바꾼다, 기본 빈 글)

Question text. (wraps at the panel width, default empty string)

반환ReturnsString

필드fieldpub cancel_text: String#0.4.0 부터since 0.4.0소스source

취소 단추 글. (기본 "취소")

Cancel button text. (default "Cancel")

반환ReturnsString

필드fieldpub confirm_text: String#0.4.0 부터since 0.4.0소스source

확인 단추 글. (기본 "확인")

Confirm button text. (default "OK")

반환ReturnsString

UIConfirmWindowstruct traits UIWindowBehavior

짝Counterpart: vanilla.js UIConfirmWindow소스source

확인 창.

Confirm window.

예제Example확인 알림을 걸고 띄운 뒤 확인하기Setting a confirm notification, opening, then confirming
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{NodeTree, UIConfirmWindow, UIConfirmWindowOptions, UIWindow, UIWindowLayer};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let layer_id = UIWindowLayer::create(&mut node_tree, root_id);
let options = UIConfirmWindowOptions {
	title: String::from("Quit"),
	message: String::from("Leave the game?"),
	..UIConfirmWindowOptions::default()
};
let window_id = UIConfirmWindow::create(&mut node_tree, layer_id, "quit", options);
let leave_requested = Rc::new(Cell::new(false));
let leave_requested_event = leave_requested.clone();
if let Some(confirm_window) = node_tree[window_id].get_component_mut::<UIWindow>().and_then(|window| window.get_behavior_mut::<UIConfirmWindow>()) {
	confirm_window.set_confirm_event(Some(Box::new(move || {
		leave_requested_event.set(true);
	})));
}
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
UIConfirmWindow::confirm_in_tree(&mut node_tree, window_id);
assert!(leave_requested.get());
assert!(!node_tree[layer_id].get_component::<UIWindowLayer>().expect("layer").has_open_window());
정적staticpub fn create_with_options(options: UIConfirmWindowOptions) -> UIConfirmWindow#0.4.0 부터since 0.4.0소스source

생성. (UIWindow::create 에 넘긴다, 보통은 UIConfirmWindow::create)

Constructor. (passed to UIWindow::create, usually UIConfirmWindow::create)

optionsUIConfirmWindowOptions
확인 창 설정.Confirm window settings.

반환ReturnsUIConfirmWindow 창 노드에 붙기 전의 확인 창. (오른쪽에서 왼쪽 언어 꺼짐, 알림 없음)Confirm window before being attached to a window node. (right-to-left language off, no notifications)

정적staticpub fn create(node_tree: &mut NodeTree, layer_id: NodeId, name: &str, options: UIConfirmWindowOptions) -> NodeId#0.4.0 부터since 0.4.0소스source

확인 창 노드 만들기. (layer_id 창 층 노드 밑에, 띄우는 것은 UIWindowLayer::open_window)

Creates a confirm window node. (under the layer_id window layer node, opening is UIWindowLayer::open_window)

node_tree&mut NodeTree
노드 트리.Node tree.
layer_idNodeId
창 층 노드.Window layer node.
name&str
창 노드 이름. (제목, 글, 단추 노드는 이 이름 뒤에 Title, MessageScroll, Message, Cancel, Confirm 을 붙인 이름)Window node name. (the title, text and button nodes are this name followed by Title, MessageScroll, Message, Cancel, Confirm)
optionsUIConfirmWindowOptions
확인 창 설정.Confirm window settings.

반환ReturnsNodeId 만든 창 노드. (UIWindow 가 붙어 있고 띄우기 전이라 꺼져 있다)The created window node. (UIWindow attached, off since it is not opened yet)

정적staticpub fn confirm_in_tree(node_tree: &mut NodeTree, window_id: NodeId)#0.4.0 부터since 0.4.0소스source

확인. (확인 알림을 부르고 닫는다, 떠 있지 않으면 아무 일도 없다. 확인 단추가 부른다)

Confirms. (calls the confirm notification and closes, does nothing if not open. Called by the confirm button)

node_tree&mut NodeTree
노드 트리.Node tree.
window_idNodeId
확인 창 노드. (확인 창이 아니면 아무 일도 없다)Confirm window node. (does nothing if it is not a confirm window)
정적staticpub fn refresh_if_open_in_tree(node_tree: &mut NodeTree, window_id: NodeId)#0.4.0 부터since 0.4.0소스source

떠 있으면 다시 놓기. (원본 refreshIfOpen, 글이나 차례를 바꾼 뒤)

Lays out again if open. (original refreshIfOpen, after changing text or order)

node_tree&mut NodeTree
노드 트리.Node tree.
window_idNodeId
확인 창 노드. (떠 있지 않으면 아무 일도 없다)Confirm window node. (does nothing if not open)
정적staticpub fn set_title_in_tree(node_tree: &mut NodeTree, window_id: NodeId, title: &str)#0.4.0 부터since 0.4.0소스source

제목 바꾸기. (떠 있으면 다시 놓는다, 원본 setTitle)

Changes the title. (lays out again if open, original setTitle)

node_tree&mut NodeTree
노드 트리.Node tree.
window_idNodeId
확인 창 노드.Confirm window node.
title&str
새 제목. (빈 글이면 제목 줄을 없앤다)New title. (if an empty string, the title line is removed)
정적staticpub fn set_message_in_tree(node_tree: &mut NodeTree, window_id: NodeId, message: &str)#0.4.0 부터since 0.4.0소스source

묻는 글 바꾸기. (떠 있으면 다시 놓는다, 원본 setMessage)

Changes the question text. (lays out again if open, original setMessage)

node_tree&mut NodeTree
노드 트리.Node tree.
window_idNodeId
확인 창 노드.Confirm window node.
message&str
새 묻는 글.New question text.
예제Example띄운 뒤 글을 바꾸면 판의 세로를 다시 정한다Changing the text after opening sets the panel height again
use vanilla::{NodeTree, UIConfirmWindow, UIConfirmWindowOptions, UILabel, UIWindow, UIWindowLayer};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let layer_id = UIWindowLayer::create(&mut node_tree, root_id);
let window_id = UIConfirmWindow::create(&mut node_tree, layer_id, "save", UIConfirmWindowOptions::default());
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
UIConfirmWindow::set_message_in_tree(&mut node_tree, window_id, "Overwrite the save file?");
let window = node_tree[window_id].get_component::<UIWindow>().expect("window");
let message_id = window.get_behavior::<UIConfirmWindow>().expect("confirm").get_message_node().expect("message");
assert_eq!(node_tree[message_id].get_component::<UILabel>().expect("label").get_text(), "Overwrite the save file?");
정적staticpub fn set_right_to_left_in_tree(node_tree: &mut NodeTree, window_id: NodeId, is_right_to_left: bool)#0.4.0 부터since 0.4.0소스source

오른쪽에서 왼쪽 언어인지 설정하고 글 방향을 바로 건다. (원본 setRightToLeft, 단추 차례는 다음 놓을 때부터)

Sets whether it is a right-to-left language and applies the text direction right away. (original setRightToLeft, the button order from the next layout)

node_tree&mut NodeTree
노드 트리.Node tree.
window_idNodeId
확인 창 노드.Confirm window node.
is_right_to_leftbool
오른쪽에서 왼쪽 언어면 true. (제목과 묻는 글이 Rtl, 아니면 Inherit)true for a right-to-left language. (the title and question text are Rtl, otherwise Inherit)
메서드methodpub fn set_button_texts(&mut self, node_tree: &mut NodeTree, cancel_text: &str, confirm_text: &str)#0.4.0 부터since 0.4.0소스source

단추 글 설정. (원본 setButtonTexts)

  • 붙기 전이면 설정에만 적어 두고 단추를 만들 때 쓴다.

Sets the button texts. (original setButtonTexts)

  • If not attached yet, it only records them in the settings and uses them when creating the buttons.
node_tree&mut NodeTree
창이 든 노드 트리.Node tree holding the window.
cancel_text&str
취소 단추 글.Cancel button text.
confirm_text&str
확인 단추 글.Confirm button text.

짝Counterpart: vanilla.js UIConfirmWindow.setButtonTexts

메서드methodpub fn set_confirm_event(&mut self, confirm_event: Option<UIWindowEvent>)#0.4.0 부터since 0.4.0소스source

확인 알림 설정.

Sets the confirm notification.

confirm_eventOption<UIWindowEvent>
확인 단추를 누르면(또는 confirm_in_tree) 닫기 전에 부르는 알림. (None 이면 끈다)Notification called before closing when the confirm button is pressed (or confirm_in_tree). (None turns it off)

짝Counterpart: vanilla.js UIConfirmWindow.setConfirmEvent

메서드methodpub fn set_cancel_event(&mut self, cancel_event: Option<UIWindowEvent>)#0.4.0 부터since 0.4.0소스source

취소 알림 설정. (취소 단추, 바깥 누르기, 창 층이 닫을 때)

Sets the cancel notification. (cancel button, pressing outside, when the window layer closes it)

cancel_eventOption<UIWindowEvent>
확인이 아닌 길로 닫힐 때 부르는 알림. (None 이면 끈다)Notification called when closed by a path other than confirm. (None turns it off)

짝Counterpart: vanilla.js UIConfirmWindow.setCancelEvent

예제Example창 층이 모두 닫아도 취소 알림이 온다The cancel notification arrives even when the window layer closes all windows
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{NodeTree, UIConfirmWindow, UIConfirmWindowOptions, UIWindow, UIWindowLayer};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let layer_id = UIWindowLayer::create(&mut node_tree, root_id);
let window_id = UIConfirmWindow::create(&mut node_tree, layer_id, "retry", UIConfirmWindowOptions::default());
let cancel_count = Rc::new(Cell::new(0));
let cancel_counter = cancel_count.clone();
if let Some(confirm_window) = node_tree[window_id].get_component_mut::<UIWindow>().and_then(|window| window.get_behavior_mut::<UIConfirmWindow>()) {
	confirm_window.set_cancel_event(Some(Box::new(move || {
		cancel_counter.set(cancel_counter.get() + 1);
	})));
}
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
	window_layer.close_all_windows(tree);
});
assert_eq!(cancel_count.get(), 1);
메서드methodpub fn set_right_to_left(&mut self, is_right_to_left: bool)#0.4.0 부터since 0.4.0소스source

오른쪽에서 왼쪽 언어인지 설정. (참이면 제목과 묻는 글이 Rtl 방향, 취소가 오른쪽, 확인이 왼쪽, 다음 놓을 때부터)

Sets whether it is a right-to-left language. (if true, the title and question text are in the Rtl direction, cancel on the right, confirm on the left, from the next layout)

is_right_to_leftbool
오른쪽에서 왼쪽 언어면 true.true for a right-to-left language.

짝Counterpart: vanilla.js UIConfirmWindow.setRightToLeft

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

오른쪽에서 왼쪽 언어인지.

Whether the language is right-to-left.

반환Returnsbool 오른쪽에서 왼쪽 언어면 true. (기본 false)true for a right-to-left language. (default false)

짝Counterpart: vanilla.js UIConfirmWindow.isRightToLeft

메서드methodpub fn set_title(&mut self, node_tree: &mut NodeTree, title: &str)#0.4.0 부터since 0.4.0소스source

제목 바꾸기. (빈 글이면 제목 줄을 없앤다, 떠 있으면 UIWindow::refresh_layout 으로 다시 놓는다)

Changes the title. (if an empty string, the title line is removed, if open it is laid out again with UIWindow::refresh_layout)

node_tree&mut NodeTree
창이 든 노드 트리.Node tree holding the window.
title&str
새 제목.New title.

짝Counterpart: vanilla.js UIConfirmWindow.setTitle

메서드methodpub fn set_message(&mut self, node_tree: &mut NodeTree, message: &str)#0.4.0 부터since 0.4.0소스source

묻는 글 바꾸기. (떠 있으면 UIWindow::refresh_layout 으로 다시 놓는다)

Changes the question text. (if open, it is laid out again with UIWindow::refresh_layout)

node_tree&mut NodeTree
창이 든 노드 트리.Node tree holding the window.
message&str
새 묻는 글.New question text.

짝Counterpart: vanilla.js UIConfirmWindow.setMessage

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

제목 노드. (UILabel)

Title node. (UILabel)

반환ReturnsOption<NodeId> 제목 노드. (창 노드가 만들어지기 전이면 None, 제목이 비면 꺼져 있다)Title node. (None before the window node is created, off if the title is empty)

짝Counterpart: vanilla.js UIConfirmWindow.getTitleNode

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

묻는 글 노드. (UILabel)

Question text node. (UILabel)

반환ReturnsOption<NodeId> 묻는 글 노드. (창 노드가 만들어지기 전이면 None)Question text node. (None before the window node is created)

짝Counterpart: vanilla.js UIConfirmWindow.getMessageNode

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

묻는 글의 스크롤 칸 노드. (UIScrollView)

Scroll area node of the question text. (UIScrollView)

반환ReturnsOption<NodeId> 스크롤 칸 노드. (창 노드가 만들어지기 전이면 None)Scroll area node. (None before the window node is created)

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

취소 단추 노드. (Paint, UIButton, UILabel)

Cancel button node. (Paint, UIButton, UILabel)

반환ReturnsOption<NodeId> 취소 단추 노드. (창 노드가 만들어지기 전이면 None)Cancel button node. (None before the window node is created)

짝Counterpart: vanilla.js UIConfirmWindow.getCancelButtonNode

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

확인 단추 노드. (Paint, UIButton, UILabel)

Confirm button node. (Paint, UIButton, UILabel)

반환ReturnsOption<NodeId> 확인 단추 노드. (창 노드가 만들어지기 전이면 None)Confirm button node. (None before the window node is created)

짝Counterpart: vanilla.js UIConfirmWindow.getConfirmButtonNode