vanilladocs
vanillapunch.com
API / ui/uiwindowlayer

ui/uiwindowlayer

창 층. (vanilla.js 의 ui/uiwindowlayer.js, UIWindowLayer)

  • 영역 위에 UIWindow 를 쌓는다. 창을 띄우면 맨 위에 쌓고, 맨 위의 창만 보인다. 위의 창이 닫히면 아래 창이 다시 보인다.
  • 닫으면 목록에서 바로 빠져 누름과 덮임이 바로 풀리고, 닫는 움직임(PopupMotion)이 끝난 뒤에 창 노드를 층에서 떼어 낸다. 덮여 있던 창을 닫으면 바로 떼어 낸다. 떼어 낸 창 노드는 지우지 않아 open_window 로 다시 띄울 수 있다. (원본과 같음) 다시 쓰지 않을 창은 씬이 destroy_node 로 지운다.
  • 휠은 맨 위의 창이 먼저 받고(UIWindowBehavior::handle_wheel), 받지 않으면 그 자리의 스크롤 뷰가 받는다. (scroll_window_at, GameSceneBase 가 창 층 안을 가리킨 휠을 넘긴다)
  • 이 층은 UI 배율(UIScale::read)만큼 커지고, 창에는 그만큼 나눈 영역의 크기와 세이프에어리어 너비를 알린다. (작은 화면에서도 글자가 읽히게) set_ui_scale_options(None) 이면 키우지 않는다.
  • 창이 하나라도 떠 있는 동안은 놀이 밖이다. 창이 뜨고 닫힐 때 알린다(set_window_change_event, 떠 있는 창 수를 넘긴다). 씬이 has_open_window 를 보고 놀이를 멈춰도 된다.
  • 사용: (영역 노드의 맨 위 자식으로 두고, 영역 크기가 바뀔 때마다 알린다)
let layer_id = UIWindowLayer::create(node_tree, play_area_id);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |layer, tree| {
    layer.set_view_size(tree, width, height, view_manager.get_css_pixel_scale());
    layer.set_view_bleed(tree, top, right, bottom, left);
});
let window_id = UIConfirmWindow::create(node_tree, layer_id, "quit", UIConfirmWindowOptions { title: ..., ..UIConfirmWindowOptions::default() });
UIWindowLayer::open_window_in_tree(node_tree, layer_id, window_id);
  • 원본과 다른 것:
  • 원본은 WorldNode 를 상속한 노드다. 러스트 판은 층 노드에 붙는 컴포넌트이고 창은 그 노드의 자식 노드다. 바꾸는 함수는 트리를 받는다.
  • 원본은 떼어 낸 창 객체를 들고 있으면 다시 띄운다. 러스트 판은 떼어 낸 노드가 트리 저장소에 남아 있으므로 그 핸들로 다시 띄운다. 원본에서 아무도 들지 않은 창은 가비지 컬렉터가 치우지만, 러스트 판에서는 씬이 지우거나 씬이 끝날 때 함께 지워진다.
  • 원본은 층이 UIScale 에 엔진의 CSS 배율을 묻는다. 러스트 판은 set_view_size 가 CSS 배율(ViewManager::get_css_pixel_scale)을 받는다.
  • 창 알림은 Box<dyn FnMut(usize)> 다. (떠 있는 창 수)

Window layer. (vanilla.js ui/uiwindowlayer.js, UIWindowLayer)

  • Stacks UIWindows over the area. Opening a window stacks it on top, and only the top window is visible. When the upper window closes, the window below becomes visible again.
  • On close it leaves the list right away so presses and covering are released immediately, and after the close motion (PopupMotion) finishes the window node is detached from the layer. Closing a covered window detaches it right away. The detached window node is not removed, so it can be opened again with open_window. (same as the original) The scene removes windows it will not reuse with destroy_node.
  • The top window gets the wheel first (UIWindowBehavior::handle_wheel), and if it does not take it, the scroll view at that spot does. (scroll_window_at, GameSceneBase passes wheel input pointing inside the window layer)
  • This layer is enlarged by the UI scale (UIScale::read), and windows are told the area size and safe area widths divided by that much. (so text is readable even on small screens) With set_ui_scale_options(None), it does not enlarge.
  • While even one window is open, play is suspended. It notifies when windows open and close (set_window_change_event, passes the number of open windows). The scene may check has_open_window and pause play.
  • Usage: (placed as the top child of the area node, notified whenever the area size changes)
let layer_id = UIWindowLayer::create(node_tree, play_area_id);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |layer, tree| {
    layer.set_view_size(tree, width, height, view_manager.get_css_pixel_scale());
    layer.set_view_bleed(tree, top, right, bottom, left);
});
let window_id = UIConfirmWindow::create(node_tree, layer_id, "quit", UIConfirmWindowOptions { title: ..., ..UIConfirmWindowOptions::default() });
UIWindowLayer::open_window_in_tree(node_tree, layer_id, window_id);
  • Differences from the original:
  • In the original it is a node inheriting WorldNode. The Rust version is a component attached to the layer node, and windows are child nodes of that node. Functions that change things take the tree.
  • The original reopens a detached window object if it is held. In the Rust version the detached node remains in the tree storage, so it is reopened with that handle. In the original a window held by no one is cleaned up by the garbage collector, but in the Rust version the scene removes it or it is removed together when the scene ends.
  • In the original the layer asks UIScale for the engine's CSS scale. In the Rust version set_view_size takes the CSS scale (ViewManager::get_css_pixel_scale).
  • The window notification is Box<dyn FnMut(usize)>. (number of open windows)

UIWindowChangeEventtype

소스source

창이 뜨거나 닫힐 때 알림. (떠 있는 창 수)

Notification when a window opens or closes. (number of open windows)

pub type UIWindowChangeEvent = Box<dyn FnMut(usize)>

UIWindowLayerstruct traits UIDocumentNode, Default, Component

짝Counterpart: vanilla.js UIWindowLayer소스source

창 층.

Window layer.

예제Example영역 노드 밑에 층을 두고 확인 창 띄우기Placing a layer under the area node and opening a confirm window
use vanilla::{NodeTree, UIConfirmWindow, UIConfirmWindowOptions, UIWindowLayer, Vector2};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let play_area_id = node_tree.create_child(root_id, "PlayArea");
node_tree[play_area_id].set_content_size(Vector2::create(800.0, 600.0));
let layer_id = UIWindowLayer::create(&mut node_tree, play_area_id);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
	window_layer.set_view_size(tree, 800.0, 600.0, 1.0);
	window_layer.set_view_bleed(tree, 40.0, 0.0, 30.0, 0.0);
});
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);
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
let window_layer = node_tree[layer_id].get_component::<UIWindowLayer>().expect("layer");
assert!(window_layer.has_open_window());
assert_eq!(window_layer.get_top_window(), Some(window_id));
assert_eq!(window_layer.find_window(&node_tree, "quit"), Some(window_id));
Placing a layer under the area node and opening a confirm window
생성자constructorpub fn new() -> UIWindowLayer#0.4.0 부터since 0.4.0소스source

생성. (노드에는 node_tree.add_component 로 붙인다, 보통은 UIWindowLayer::create)

Constructor. (attach to a node with node_tree.add_component, usually UIWindowLayer::create)

반환ReturnsUIWindowLayer 붙기 전의 층. (띄운 창 없음, UI 배율 설정은 UIScaleOptions::default)Layer before being attached. (no open windows, UI scale settings are UIScaleOptions::default)

짝Counterpart: vanilla.js UIWindowLayer.constructor

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

층 노드 만들기. (parent_id 밑에 "UIWindowLayer" 노드를 만들어 붙인다, 원본 new UIWindowLayer() + add_child)

Creates a layer node. (creates and attaches a "UIWindowLayer" node under parent_id, original new UIWindowLayer() + add_child)

node_tree&mut NodeTree
노드 트리.Node tree.
parent_idNodeId
영역 노드. (층은 그 맨 위 자식으로 두고 쓴다)Area node. (the layer is used as its top child)

반환ReturnsNodeId 만든 층 노드.The created layer node.

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

창 띄우기. (씬 코드용, with_component_mut 을 대신 부른다)

Opens a window. (for scene code, calls with_component_mut on your behalf)

node_tree&mut NodeTree
노드 트리.Node tree.
layer_idNodeId
창 층 노드. (UIWindowLayer 가 없으면 아무 일도 없다)Window layer node. (does nothing if there is no UIWindowLayer)
window_idNodeId
띄울 창 노드. (UIWindow::create 나 UIConfirmWindow::create 가 돌려준 것)Window node to open. (the one returned by UIWindow::create or UIConfirmWindow::create)
정적staticpub fn scroll_window_at(node_tree: &mut NodeTree, engine: &Engine, layer_id: NodeId, view_input_position: Vector2, wheel_delta: Vector2) -> bool#0.4.0 부터since 0.4.0소스source

마우스 휠을 맨 위의 창에 넘기기. (창이 받지 않으면 그 자리의 스크롤 뷰, 받았으면 true, 원본 scrollWindowAt)

Passes the mouse wheel to the top window. (the scroll view at that spot if the window does not take it, true if taken, original scrollWindowAt)

node_tree&mut NodeTree
층이 든 노드 트리.Node tree holding the layer.
engine&Engine
엔진. (스크롤 뷰에 휠을 넘길 때 쓴다)Engine. (used when passing the wheel to a scroll view)
layer_idNodeId
창 층 노드.Window layer node.
view_input_positionVector2
휠을 굴린 자리. (뷰 좌표)Position where the wheel was rolled. (view coordinates)
wheel_deltaVector2
휠을 굴린 양.Amount the wheel was rolled.

반환Returnsbool 맨 위 창이나 그 자리의 스크롤 뷰가 받았으면 true. (떠 있는 창이 없거나 받을 곳이 없으면 false)true if the top window or the scroll view at that spot took it. (false if no window is open or nothing takes it)

짝Counterpart: vanilla.js UIWindowLayer.scrollWindowAt

예제Example씬의 휠을 창 층에 먼저 넘기기Passing the scene's wheel input to the window layer first
use vanilla::{Engine, EngineConfiguration, NodeId, NodeTree, UIWindowLayer, Vector2};

fn handle_wheel(node_tree: &mut NodeTree, engine: &Engine, layer_id: NodeId, wheel_delta: Vector2) -> bool {
	let view_input_position = engine.get_input_manager().get_view_input_position();
	UIWindowLayer::scroll_window_at(node_tree, engine, layer_id, view_input_position, wheel_delta)
}

let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let layer_id = UIWindowLayer::create(&mut node_tree, root_id);
assert!(!handle_wheel(&mut node_tree, &engine, layer_id, Vector2::create(0.0, 120.0)));
정적staticpub fn find_scroll_view_at(node_tree: &NodeTree, node_id: NodeId, view_input_position: Vector2) -> Option<NodeId>#0.4.0 부터since 0.4.0소스source

그 자리를 덮는 맨 앞(나중에 그리는) 스크롤 뷰 노드 찾기. (켜진 노드만, 휠을 받는 칸(Component::is_wheel_receiver)이 붙은 노드, 없으면 None)

Finds the frontmost (drawn later) scroll view node covering that spot. (only active nodes, nodes with a wheel receiving slot (Component::is_wheel_receiver) attached, None if none)

node_tree&NodeTree
찾을 노드 트리.Node tree to search.
node_idNodeId
찾기 시작할 노드. (그 노드와 자손을 뒤의 자식부터 본다)Node to start searching from. (looks at that node and its descendants from the later children)
view_input_positionVector2
찾을 자리. (뷰 좌표)Position to look at. (view coordinates)

반환ReturnsOption<NodeId> 그 자리를 덮는 맨 앞 스크롤 뷰 노드. (시작 노드가 꺼졌거나 그런 노드가 없으면 None)The frontmost scroll view node covering that spot. (None if the start node is off or there is no such node)

짝Counterpart: vanilla.js UIWindowLayer.findScrollViewAt

정적staticpub fn find_window_layer_of(node_tree: &NodeTree, node_id: NodeId) -> Option<NodeId>#0.4.0 부터since 0.4.0소스source

노드가 들어 있는 창 층 노드 찾기. (자기부터 부모 쪽으로, 없으면 None, 원본 findWindowLayerOf)

Finds the window layer node containing the node. (from itself toward the parents, None if none, original findWindowLayerOf)

node_tree&NodeTree
찾을 노드 트리.Node tree to search.
node_idNodeId
찾기 시작할 노드. (창 안의 단추 같은)Node to start searching from. (like a button inside a window)

반환ReturnsOption<NodeId> UIWindowLayer 가 붙은 가장 가까운 조상(자기 포함) 노드. (뿌리까지 없으면 None)The closest ancestor (including itself) node with UIWindowLayer attached. (None if none up to the root)

짝Counterpart: vanilla.js UIWindowLayer.findWindowLayerOf

예제Example판 안의 노드에서 창 층 찾기Finding the window layer from a node inside the panel
use vanilla::{NodeTree, UIWindow, UIWindowDefaultBehavior, 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 = UIWindow::create(&mut node_tree, layer_id, "inventory", Box::new(UIWindowDefaultBehavior));
let panel_id = node_tree[window_id].get_component::<UIWindow>().expect("window").get_panel_node().expect("panel");
let item_id = node_tree.create_child(panel_id, "Item");
assert_eq!(UIWindowLayer::find_window_layer_of(&node_tree, item_id), Some(layer_id));
assert_eq!(UIWindowLayer::find_window_layer_of(&node_tree, root_id), None);
메서드methodpub fn set_window_change_event(&mut self, window_change_event: Option<UIWindowChangeEvent>)#0.4.0 부터since 0.4.0소스source

창이 뜨거나 닫힐 때 알림 설정.

Sets the notification for when a window opens or closes.

window_change_eventOption<UIWindowChangeEvent>
알림. (떠 있는 창 수를 받는다, None 이면 끈다)Notification. (receives the number of open windows, None turns it off)

짝Counterpart: vanilla.js UIWindowLayer.setWindowChangeEvent

예제Example창이 떠 있는 동안 놀이 멈추기Pausing play while a window is open
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{NodeTree, UIWindow, UIWindowDefaultBehavior, 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 is_paused = Rc::new(Cell::new(false));
let is_paused_event = is_paused.clone();
node_tree[layer_id].get_component_mut::<UIWindowLayer>().expect("layer").set_window_change_event(Some(Box::new(move |window_count| {
	is_paused_event.set(window_count > 0);
})));
let window_id = UIWindow::create(&mut node_tree, layer_id, "pause", Box::new(UIWindowDefaultBehavior));
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
assert!(is_paused.get());
UIWindow::close_in_tree(&mut node_tree, window_id);
assert!(!is_paused.get());
메서드methodpub fn set_ui_scale_options(&mut self, node_tree: &mut NodeTree, ui_scale_options: Option<UIScaleOptions>)#0.4.0 부터since 0.4.0소스source

UI 배율 설정. (None 이면 키우지 않는다, 기본은 UIScaleOptions::default)

Sets the UI scale. (None means no enlargement, default is UIScaleOptions::default)

node_tree&mut NodeTree
층이 든 노드 트리. (마지막 영역의 크기로 다시 놓는다)Node tree holding the layer. (lays out again with the last area size)
ui_scale_optionsOption<UIScaleOptions>
UI 배율 설정. (None 이면 배율 1)UI scale settings. (None means scale 1)

짝Counterpart: vanilla.js UIWindowLayer.setUIScaleOptions

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

지금의 UI 배율.

Current UI scale.

반환Returnsf64 층을 키운 배율. (마지막 set_view_size 에서 읽은 값, 처음은 1)Scale the layer was enlarged by. (the value read at the last set_view_size, initially 1)

짝Counterpart: vanilla.js UIWindowLayer.getUIScale

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

창이 하나라도 떠 있는지. (닫는 움직임 중인 창은 셈하지 않는다)

Whether at least one window is open. (windows in the close motion are not counted)

반환Returnsbool 떠 있는 창이 있으면 true.true if a window is open.

짝Counterpart: vanilla.js UIWindowLayer.hasOpenWindow

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

떠 있는 창의 수.

Number of open windows.

반환Returnsusize 창 수. (닫는 움직임 중인 창은 빼고)Number of windows. (excluding windows in their close motion)

짝Counterpart: vanilla.js UIWindowLayer.getWindowCount

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

맨 위의 창. (없으면 None)

The top window. (None if none)

반환ReturnsOption<NodeId> 맨 위 창 노드. (떠 있는 창이 없으면 None)Top window node. (None if no window is open)

짝Counterpart: vanilla.js UIWindowLayer.getTopWindow

메서드methodpub fn find_window(&self, node_tree: &NodeTree, window_name: &str) -> Option<NodeId>#0.4.0 부터since 0.4.0소스source

그 이름의 창. (떠 있는 것 가운데 위에서부터, 없으면 None)

The window with that name. (from the top among open ones, None if none)

node_tree&NodeTree
층이 든 노드 트리.Node tree holding the layer.
window_name&str
찾을 창 노드 이름. (UIWindow::create 의 name)Window node name to find. (the name of UIWindow::create)

반환ReturnsOption<NodeId> 그 이름의 창 노드 가운데 가장 위의 것. (떠 있는 창에 없으면 None)The topmost of the window nodes with that name. (None if not among the open windows)

짝Counterpart: vanilla.js UIWindowLayer.findWindow

메서드methodpub fn set_view_size(&mut self, node_tree: &mut NodeTree, view_width: f64, view_height: f64, css_pixel_scale: f64)#0.4.0 부터since 0.4.0소스source

영역의 크기 알리기. (UI 배율을 다시 읽고, 띄운 창을 모두 다시 놓는다, css_pixel_scale 은 ViewManager::get_css_pixel_scale)

Notifies the area size. (reads the UI scale again and lays out all open windows again, css_pixel_scale is ViewManager::get_css_pixel_scale)

node_tree&mut NodeTree
층이 든 노드 트리.Node tree holding the layer.
view_widthf64
영역의 가로. (부모 단위, 1 보다 작으면 1)Area width. (parent units, 1 if less than 1)
view_heightf64
영역의 세로. (부모 단위, 1 보다 작으면 1)Area height. (parent units, 1 if less than 1)
css_pixel_scalef64
뷰 한 단위의 CSS 픽셀. (UIScale::read 가 배율을 정할 때 쓴다)CSS pixels of one view unit. (used by UIScale::read to determine the scale)

짝Counterpart: vanilla.js UIWindowLayer.setViewSize

예제Example작은 화면에서는 층이 커지고 창에는 나눈 크기를 알린다On a small screen the layer is enlarged and windows are told the divided size
use vanilla::{NodeTree, 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);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
	window_layer.set_view_size(tree, 800.0, 600.0, 0.4);
});
let ui_scale = node_tree[layer_id].get_component::<UIWindowLayer>().expect("layer").get_ui_scale();
assert!((ui_scale - 1.8).abs() < 0.0001);
assert!((node_tree[layer_id].get_content_size().x - 800.0 / 1.8).abs() < 0.001);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
	window_layer.set_ui_scale_options(tree, None);
});
assert_eq!(node_tree[layer_id].get_component::<UIWindowLayer>().expect("layer").get_ui_scale(), 1.0);
메서드methodpub fn set_view_bleed(&mut self, node_tree: &mut NodeTree, top: f64, right: f64, bottom: f64, left: f64)#0.4.0 부터since 0.4.0소스source

영역 밖으로 더 덮는 너비 알리기. (세이프에어리어, 부모 단위)

  • 창에는 UI 배율로 나눈 너비를 알린다.

Notifies the extra coverage width beyond the area. (safe area, parent units)

  • Windows are told the widths divided by the UI scale.
node_tree&mut NodeTree
층이 든 노드 트리.Node tree holding the layer.
topf64
위로 더 덮는 너비. (0 보다 작으면 0)Extra coverage width upward. (0 if less than 0)
rightf64
오른쪽으로 더 덮는 너비. (0 보다 작으면 0)Extra coverage width to the right. (0 if less than 0)
bottomf64
아래로 더 덮는 너비. (0 보다 작으면 0)Extra coverage width downward. (0 if less than 0)
leftf64
왼쪽으로 더 덮는 너비. (0 보다 작으면 0)Extra coverage width to the left. (0 if less than 0)

짝Counterpart: vanilla.js UIWindowLayer.setViewBleed

메서드methodpub fn open_window(&mut self, node_tree: &mut NodeTree, window_id: NodeId)#0.4.0 부터since 0.4.0소스source

창 띄우기. (맨 위에 쌓는다, 이미 떠 있으면 맨 위로 올린다, 층 노드의 자식이 아니면 붙인다. 떼어 낸 창도 다시 띄운다)

  • 층이 트리에 붙기 전이거나 창 노드가 트리에 없으면 아무 일도 없다.

Opens a window. (stacks it on top, brings it to the top if already open, attaches it if it is not a child of the layer node. Also reopens detached windows)

  • Does nothing if the layer is not attached to the tree yet or the window node is not in the tree.
node_tree&mut NodeTree
층이 든 노드 트리.Node tree holding the layer.
window_idNodeId
띄울 창 노드. (UIWindow 가 붙은 노드)Window node to open. (the node with UIWindow attached)

짝Counterpart: vanilla.js UIWindowLayer.openWindow

메서드methodpub fn close_window(&mut self, node_tree: &mut NodeTree, window_id: NodeId)#0.4.0 부터since 0.4.0소스source

창 닫기. (목록에서 빼고 닫는 움직임을 시작한다, 떠 있지 않으면 아무 일도 없다)

  • 덮여 숨은 창이나 즉시 전환인 창은 바로 떼어 낸다.

Closes a window. (removes it from the list and starts the close motion, does nothing if not open)

  • Windows hidden by covering or with instant transitions are detached right away.
node_tree&mut NodeTree
층이 든 노드 트리.Node tree holding the layer.
window_idNodeId
닫을 창 노드.Window node to close.

짝Counterpart: vanilla.js UIWindowLayer.closeWindow

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

창 모두 닫기. (위에서부터)

  • 바깥 닫기를 끈 창도 닫는다.

Closes all windows. (from the top)

  • Also closes windows with outside close turned off.
node_tree&mut NodeTree
층이 든 노드 트리.Node tree holding the layer.

짝Counterpart: vanilla.js UIWindowLayer.closeAllWindows

메서드methodpub fn close_top_window(&mut self, node_tree: &mut NodeTree) -> bool#0.4.0 부터since 0.4.0소스source

맨 위의 창 닫기. (기기의 뒤로 가기 자리, 바깥 닫기를 끈 창이면 닫지 않는다, 닫았으면 true)

Closes the top window. (for the device's back button, does not close a window with outside close turned off, true if closed)

node_tree&mut NodeTree
층이 든 노드 트리.Node tree holding the layer.

반환Returnsbool 닫았으면 true. (떠 있는 창이 없거나 맨 위 창이 바깥 닫기를 껐으면 false)true if closed. (false if no window is open or the top window has outside close turned off)

짝Counterpart: vanilla.js UIWindowLayer.closeTopWindow

예제Example뒤로 가기를 창이 먼저 받기Letting the window get back first
use vanilla::{NodeTree, UIWindow, UIWindowDefaultBehavior, 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 = UIWindow::create(&mut node_tree, layer_id, "tutorial", Box::new(UIWindowDefaultBehavior));
node_tree[window_id].get_component_mut::<UIWindow>().expect("window").set_outside_close_enabled(false);
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
let is_closed = node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
	window_layer.close_top_window(tree)
});
assert_eq!(is_closed, Some(false));
node_tree[window_id].get_component_mut::<UIWindow>().expect("window").set_outside_close_enabled(true);
let is_closed = node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
	window_layer.close_top_window(tree)
});
assert_eq!(is_closed, Some(true));