ui/uiwindow
창 쌓기의 창 하나. (vanilla.js 의 ui/uiwindow.js, UIWindow)
- 영역 전체를 어둡게 덮고(뒤로 누름이 가지 않는다) 가운데에 판을 띄운다. 어둠은 세이프에어리어(set_view_bleed)까지 덮는다.
- 판은 영역의 가로에 맞춰 넓어지되 maximum_width 를 넘지 않는다. 세로는 layout_content 가 돌려준 값이고, 영역보다 크면 판을 통째로 줄인다.
- 열고 닫는 움직임은 PopupMotion 이다. 닫는 움직임이 끝나면 창 층(UIWindowLayer)이 노드를 지운다. (그동안은 누름을 받지 않는다)
- 바깥(어둠)을 누르면 닫힌다. 창마다 set_outside_close_enabled 로 끈다. 창 층의 close_top_window(뒤로 가기)도 이 값을 따른다.
- 노드 구성: 창(영역 크기) ├ 어둠(Paint + UIButton) └ 틀(판 가운데 피봇, 움직임 배율) └ 판(Paint 한 장, 내용은 여기)
- 원본과 다른 것:
- 원본은 WorldNode 를 상속한 노드이고 파생 클래스가 layoutContent, layoutPanel, applyMotion, setCovered, handleWheel, dispose 를 덮어쓴다. 러스트 판은 창 노드에 붙는 컴포넌트이고, 덮어쓸 자리는 UIWindowBehavior 트레이트다. (기본 구현은 UIWindowDefaultBehavior, 덮어쓴 쪽이 원본 super 처럼 기본을 부르려면 UIWindow::layout_panel_default, apply_motion_default, set_covered_default) 판 모양(그림자, 테, 글로시)은 게임이 build 에서 틀에 꾸밈 노드를 붙이고(판 뒤는 set_sibling_index(0)) layout_panel 에서 놓는다.
- 창 노드는 UIWindow::create(node_tree, layer_id, name, behavior) 로 창 층 노드 밑에 만든다. 닫는 움직임이 끝나면 층에서 떼어 내고 지우지 않으므로 원본처럼 같은 창 노드를 다시 띄울 수 있다. (UIWindowLayer::open_window) 원본 창은 띄울 때 층에 붙으므로 create 는 띄우기 전까지 노드를 끈다. 붙을 때는 원본 생성자처럼 노드를 끄지 않는다. (UI 문서가 창 노드를 원본처럼 켜진 채로 읽고 쓴다)
- 닫기는 창 층을 거친다. 씬과 콜백 코드는 UIWindow::close_in_tree(node_tree, window_id) 를 부른다.
- 알림(set_close_event)은 인자 없는
Box<dyn FnMut()>다. (PopupMotion 알림과 같은 꼴, 노드를 바꿀 일은 씬이 tick 에서 상태를 보고 한다) - 휠은 원본처럼 GameSceneBase 가 창 층 안을 가리킨 휠을 UIWindowLayer::scroll_window_at 으로 넘겨 맨 위 창(UIWindowBehavior::handle_wheel)이 먼저 받고, 받지 않으면 그 자리의 스크롤 뷰가 받는다. GameSceneBase 를 거치지 않는 엔진의 휠 전달(가리킨 노드부터 부모 쪽)로 창에 온 휠도 창이 받고 늘 삼킨다.
- 판과 어둠의 Paint 는 노드의 컴포넌트라 get_panel_paint, get_dim_paint 가 트리를 받는다.
A single window in the window stack. (vanilla.js ui/uiwindow.js, UIWindow)
- Dims the whole area (presses do not pass through to what is behind) and shows a panel in the center. The dim also covers the safe area (set_view_bleed).
- The panel widens to fit the area's width but does not exceed maximum_width. Its height is the value returned by layout_content, and if it is larger than the area the whole panel is scaled down.
- The open and close motion is PopupMotion. When the close motion finishes, the window layer (UIWindowLayer) removes the node. (it does not receive presses in the meantime)
- Pressing outside (the dim) closes it. Turned off per window with set_outside_close_enabled. The window layer's close_top_window (back) also follows this value.
- Node structure: window (area size) ├ dim (Paint + UIButton) └ frame (panel center pivot, motion scale) └ panel (a single Paint, content goes here)
- Differences from the original:
- In the original it is a node inheriting WorldNode, and derived classes override layoutContent, layoutPanel, applyMotion, setCovered, handleWheel, dispose. The Rust version is a component attached to the window node, and the override points are the UIWindowBehavior trait. (the default implementation is UIWindowDefaultBehavior, and an override that wants to call the default like the original super uses UIWindow::layout_panel_default, apply_motion_default, set_covered_default) The panel look (shadow, border, gloss) is done by the game attaching decoration nodes to the frame in build (set_sibling_index(0) for behind the panel) and placing them in layout_panel.
- The window node is created under the window layer node with UIWindow::create(node_tree, layer_id, name, behavior). When the close motion finishes, it is detached from the layer and not removed, so the same window node can be opened again as in the original. (UIWindowLayer::open_window) The original window attaches to the layer when opened, so create keeps the node off until it is opened. When attached, it does not turn the node off as the original constructor does. (so the UI document reads and writes the window node as active, as in the original)
- Closing goes through the window layer. Scene and callback code calls UIWindow::close_in_tree(node_tree, window_id).
- The notification (set_close_event) is an argumentless
Box<dyn FnMut()>. (same form as the PopupMotion notification, node changes are done by the scene checking the state in tick) - As in the original, GameSceneBase passes wheel input pointing inside the window layer to UIWindowLayer::scroll_window_at so the top window (UIWindowBehavior::handle_wheel) gets it first, and if it does not take it, the scroll view at that spot does. Wheel input that reaches a window through the engine's wheel delivery (from the pointed node toward the parents) without going through GameSceneBase is also taken by the window and always swallowed.
- The panel and dim Paints are components of nodes, so get_panel_paint and get_dim_paint take the tree.
UIWindowEventtype
알림. (인자 없음)
Notification. (no arguments)
pub type UIWindowEvent = Box<dyn FnMut()>UIWindowPartsstruct traits Clone, Copy, Debug, PartialEq
창의 노드와 지금 놓인 값. (UIWindowBehavior 가 받는다)
The window's nodes and current layout values. (received by UIWindowBehavior)
use vanilla::{NodeTree, Rect, 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);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
window_layer.set_view_size(tree, 800.0, 600.0, 1.0);
});
let window_id = UIWindow::create(&mut node_tree, layer_id, "notice", Box::new(UIWindowDefaultBehavior));
node_tree[window_id].get_component_mut::<UIWindow>().expect("window").set_panel_height(300.0);
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
let parts = node_tree[window_id].get_component::<UIWindow>().expect("window").get_parts().expect("parts");
assert_eq!(parts.window_id, window_id);
assert_eq!(parts.view_width, 800.0);
assert_eq!(parts.panel_rect, Rect::create(160.0, 150.0, 480.0, 300.0));
assert_eq!(parts.panel_scale, 1.0);창 노드. (UIWindow 가 붙은 노드, 영역 크기)
Window node. (the node with UIWindow attached, area size)
반환ReturnsNodeId
어둠 노드. (Paint + UIButton, 바깥 누르기를 받는다)
Dim node. (Paint + UIButton, receives outside presses)
반환ReturnsNodeId
틀 노드. (판 가운데 피봇, 움직임 배율이 걸린다)
Frame node. (panel center pivot, the motion scale is applied)
반환ReturnsNodeId
판 노드. (Paint 한 장, 내용을 여기에 붙인다)
Panel node. (a single Paint, content is attached here)
반환ReturnsNodeId
마지막으로 받은 영역의 크기. (UI 층 단위)
Size of the last received area. (UI layer units)
반환Returnsf64
마지막으로 받은 영역의 세로. (UI 층 단위)
Height of the last received area. (UI layer units)
반환Returnsf64
영역 가장자리와 판 사이 거리. (UI 층 단위, 기본 16)
Distance between the area edge and the panel. (UI layer units, default 16)
반환Returnsf64
layout_content 기본값이 돌려주는 판의 세로.
Panel height returned by the layout_content default.
반환Returnsf64
마지막으로 놓은 판의 자리. (창 좌표, 움직임 전, 줄인 배율을 곱한 크기)
Rect of the last placed panel. (window coordinates, before motion, size multiplied by the shrink scale)
반환ReturnsRect
판이 영역보다 커서 줄인 배율. (1 이하)
Scale by which the panel was shrunk because it was larger than the area. (1 or less)
반환Returnsf64
UIWindowBehaviortrait traits Any
창의 덮어쓸 자리. (원본 UIWindow 파생 클래스가 덮어쓰는 메서드)
- as_any, as_any_mut 만 꼭 구현하고(
self를 돌려준다) 나머지는 필요한 것만 덮어쓴다.
The window's override points. (methods that original UIWindow derived classes override)
- Only as_any and as_any_mut must be implemented (they return
self), and the rest are overridden only as needed.
use std::any::Any;
use vanilla::{NodeTree, UIWindow, UIWindowBehavior, UIWindowLayer, UIWindowParts};
struct NoticeWindow {
is_closed: bool,
}
impl UIWindowBehavior for NoticeWindow {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn layout_content(&mut self, _node_tree: &mut NodeTree, _parts: &UIWindowParts, _panel_width: f64) -> f64 {
200.0
}
fn handle_closed(&mut self) {
self.is_closed = true;
}
}
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, 1.0);
});
let window_id = UIWindow::create(&mut node_tree, layer_id, "notice", Box::new(NoticeWindow { is_closed: false }));
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
assert_eq!(node_tree[window_id].get_component::<UIWindow>().expect("window").get_panel_rect().size.y, 200.0);
UIWindow::close_in_tree(&mut node_tree, window_id);
let window = node_tree[window_id].get_component::<UIWindow>().expect("window");
assert!(window.get_behavior::<NoticeWindow>().expect("notice").is_closed);구체 타입으로 꺼내기. (UIWindow::get_behavior 가 쓴다, 변경용은 as_any_mut 으로 get_behavior_mut 이 쓴다)
Takes it out as the concrete type. (used by UIWindow::get_behavior, the mutable version as_any_mut is used by get_behavior_mut)
반환Returns&dyn Any 자기 자신. (&dyn Any, UIWindow::get_behavior 가 downcast_ref 로 꺼낸다)Itself. (&dyn Any, UIWindow::get_behavior takes it out with downcast_ref)
구체 타입으로 꺼내기. (변경용, UIWindow::get_behavior_mut 이 쓴다)
Takes it out as the concrete type. (for modification, used by UIWindow::get_behavior_mut)
반환Returns&mut dyn Any 자기 자신. (&mut dyn Any, UIWindow::get_behavior_mut 이 downcast_mut 으로 꺼낸다)Itself. (&mut dyn Any, UIWindow::get_behavior_mut takes it out with downcast_mut)
창 노드를 다 만든 뒤 한 번. (내용과 꾸밈 노드를 만든다, 원본 파생 클래스 생성자 자리)
Once after the window node is fully created. (creates the content and decoration nodes, where the original derived class constructor goes)
- _node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- _parts&UIWindowParts
- 창의 노드. (내용은 판 parts.panel_id 밑에, 판과 함께 커지고 주는 꾸밈은 틀 parts.frame_id 밑에 붙인다. 영역 크기는 아직 처음 값 1)The window's nodes. (content goes under the panel parts.panel_id, decorations that grow and shrink with the panel go under the frame parts.frame_id. The area size is still the initial value 1)
fn layout_content(&mut self, _node_tree: &mut NodeTree, parts: &UIWindowParts, _panel_width: f64) -> f64#내용 놓기. (판 안에 내용을 놓고 판의 세로를 돌려준다, 기본은 parts.panel_height)
Lays out the content. (places the content inside the panel and returns the panel's height, default is parts.panel_height)
- _node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- parts&UIWindowParts
- 창의 노드와 지금 놓인 값. (view_width, view_height 는 이번 영역의 크기, panel_rect 와 panel_scale 은 아직 지난번 값)The window's nodes and current layout values. (view_width, view_height are this area's size, panel_rect and panel_scale are still the previous values)
- _panel_widthf64
- 판의 가로. (영역 가로 - margin x 2 를 가로 한계로 자른 값, 1 이상, UI 층 단위)Panel width. (area width - margin x 2 clamped to the width limit, 1 or more, UI layer units)
반환Returnsf64 판의 세로. (UI 층 단위, 1 보다 작으면 1 로 올린다. 영역 세로 - margin x 2 보다 크면 창이 판을 통째로 줄인다)Panel height. (UI layer units, raised to 1 if less than 1. If larger than area height - margin x 2, the window scales down the whole panel)
fn layout_panel(&mut self, node_tree: &mut NodeTree, parts: &UIWindowParts, panel_width: f64, panel_height: f64)#판 놓기. (판의 크기를 정한다, 꾸밈이 있으면 덮어써 layout_panel_default 뒤에 놓는다)
Lays out the panel. (sets the panel size, if there are decorations override this and place them after layout_panel_default)
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- parts&UIWindowParts
- 창의 노드와 이번에 놓인 값. (panel_rect, panel_scale 이 정해진 뒤)The window's nodes and the values laid out this time. (after panel_rect and panel_scale are set)
- panel_widthf64
- 판의 가로. (줄이기 전, UI 층 단위)Panel width. (before scaling down, UI layer units)
- panel_heightf64
- layout_content 가 돌려준 판의 세로. (줄이기 전, 1 이상)Panel height returned by layout_content. (before scaling down, 1 or more)
fn apply_motion(&mut self, node_tree: &mut NodeTree, parts: &UIWindowParts, popup_motion: &PopupMotion)#움직임을 틀과 어둠에 걸기. (기본: 틀 배율 = 줄인 배율 x 움직임 배율, 어둠 진하기 = 움직임 비율)
- 다시 놓을 때, 열고 닫는 움직임을 시작할 때, 매 tick 부른다.
Applies the motion to the frame and the dim. (default: frame scale = reduced scale x motion scale, dim strength = motion ratio)
- Called on relayout, when an open or close motion starts, and every tick.
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- parts&UIWindowParts
- 창의 노드와 지금 놓인 값.The window's nodes and current layout values.
- popup_motion&PopupMotion
- 창의 움직임. (get_scale 은 틀 배율, get_dim_ratio 는 0 ~ 1 어둠 진하기)The window's motion. (get_scale is the frame scale, get_dim_ratio is the dim strength from 0 ~ 1)
fn set_covered(&mut self, node_tree: &mut NodeTree, parts: &UIWindowParts, is_covered: bool)#다른 창에 덮였는지 알리기. (기본은 덮이면 창 노드를 끄고 드러나면 켠다)
Notifies whether it is covered by another window. (by default turns the window node off when covered and on when revealed)
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- parts&UIWindowParts
- 창의 노드와 지금 놓인 값.The window's nodes and current layout values.
- is_coveredbool
- 위에 다른 창이 떠 있으면 true, 맨 위가 되면 false.true if another window is open above, false once it becomes the top.
fn handle_wheel(&mut self, _node_tree: &mut NodeTree, _parts: &UIWindowParts, _view_input_position: Vector2, _wheel_delta: Vector2) -> bool#그 자리의 스크롤 뷰가 받지 않은 휠. (받았으면 true, 창은 어느 쪽이든 휠을 삼킨다)
Wheel input not taken by the scroll view at that spot. (true if taken, the window swallows the wheel either way)
- _node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- _parts&UIWindowParts
- 창의 노드와 지금 놓인 값.The window's nodes and current layout values.
- _view_input_positionVector2
- 휠을 굴린 자리. (뷰 좌표)Position where the wheel was rolled. (view coordinates)
- _wheel_deltaVector2
- 휠을 굴린 양.Amount the wheel was rolled.
반환Returnsbool 받았으면 true. (기본 false, UIWindowLayer::scroll_window_at 에서 false 면 그 자리의 스크롤 뷰에 넘긴다)true if taken. (default false, if false UIWindowLayer::scroll_window_at passes it to the scroll view at that spot)
창 층에서 내려감. (닫기, 바깥 누르기, close_all_windows 모두, set_close_event 알림 다음)
Removed from the window layer. (close, outside press, close_all_windows alike, after the set_close_event notification)
레이아웃을 다시 해야 하는지. (그린 뒤에야 알 수 있는 크기를 기다릴 때 true, 창이 tick 에서 다시 놓는다)
Whether layout needs to be redone. (true while waiting for a size known only after drawing, the window lays out again in tick)
- _node_tree&NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- _parts&UIWindowParts
- 창의 노드와 지금 놓인 값.The window's nodes and current layout values.
반환Returnsbool 다시 놓아야 하면 true. (true 면 그 tick 에 UIWindow::refresh_layout 으로 다시 놓는다, 기본 false)true if it needs to be laid out again. (if true, it is laid out again with UIWindow::refresh_layout in that tick, default false)
창 층이 창을 떼어 낼 때. (엔진 밖에 붙인 것을 정리한다, 노드는 지우지 않고 남아 다시 띄울 수 있다)
When the window layer detaches the window. (cleans up what was attached outside the engine, the node is not deleted and remains so it can be shown again)
- _node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- _parts&UIWindowParts
- 창의 노드와 지금 놓인 값.The window's nodes and current layout values.
UIWindowDefaultBehaviorstruct traits UIWindowBehavior
기본 창. (덮어쓴 것 없음, 판 세로는 UIWindow::set_panel_height)
Default window. (nothing overridden, panel height is UIWindow::set_panel_height)
use vanilla::{UIWindow, UIWindowDefaultBehavior};
let mut window = UIWindow::create_with_behavior(Box::new(UIWindowDefaultBehavior));
window.set_panel_height(320.0);
assert_eq!(window.get_panel_height(), 320.0);
assert!(window.get_behavior::<UIWindowDefaultBehavior>().is_some());UIWindowstruct traits UIDocumentNode, Component
창.
Window.
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{Engine, EngineConfiguration, NodeTree, UIWindow, UIWindowDefaultBehavior, UIWindowLayer};
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);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
window_layer.set_view_size(tree, 800.0, 600.0, 1.0);
});
let window_id = UIWindow::create(&mut node_tree, layer_id, "settings", Box::new(UIWindowDefaultBehavior));
let close_count = Rc::new(Cell::new(0));
let close_counter = close_count.clone();
if let Some(window) = node_tree[window_id].get_component_mut::<UIWindow>() {
window.set_panel_height(300.0);
window.set_close_event(Some(Box::new(move || {
close_counter.set(close_counter.get() + 1);
})));
}
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
assert!(node_tree[window_id].is_active());
node_tree.tick(&engine, 0.5);
UIWindow::close_in_tree(&mut node_tree, window_id);
assert_eq!(close_count.get(), 1);
node_tree.tick(&engine, 0.3);
node_tree.tick(&engine, 0.016);
assert_eq!(node_tree.get_parent_id(window_id), None);생성. (노드에는 node_tree.add_component 로 붙인다, 보통은 UIWindow::create)
Constructor. (attach to a node with node_tree.add_component, usually UIWindow::create)
- behaviorBox<dyn UIWindowBehavior>
- 덮어쓸 자리. (UIWindowDefaultBehavior 나 게임이 구현한 값)Override points. (UIWindowDefaultBehavior or a value implemented by the game)
반환ReturnsUIWindow 붙기 전의 창. (가로 한계 480, 여백 16, 판 세로 240, 바깥 닫기 켬)Window before being attached. (width limit 480, margin 16, panel height 240, outside close on)
pub fn create(node_tree: &mut NodeTree, layer_id: NodeId, name: &str, behavior: Box<dyn UIWindowBehavior>) -> NodeId#창 노드 만들기. (layer_id 창 층 노드 밑에 name 노드를 만들고 창을 붙인다, 띄우는 것은 UIWindowLayer::open_window)
Creates a window node. (creates a name node under the layer_id window layer node and attaches the window, opening is UIWindowLayer::open_window)
- node_tree&mut NodeTree
- 노드 트리.Node tree.
- layer_idNodeId
- 창 층 노드. (UIWindowLayer::create 가 돌려준 것)Window layer node. (the one returned by UIWindowLayer::create)
- name&str
- 창 노드 이름. (어둠, 틀, 판 노드는 이 이름 뒤에 Dim, Frame, Panel 을 붙인 이름)Window node name. (the dim, frame and panel nodes are this name followed by Dim, Frame, Panel)
- behaviorBox<dyn UIWindowBehavior>
- 덮어쓸 자리.Override points.
반환ReturnsNodeId 만든 창 노드. (띄우기 전이라 꺼져 있다)The created window node. (off since it is not opened yet)
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, "help", Box::new(UIWindowDefaultBehavior));
assert!(!node_tree[window_id].is_active());
let panel_id = node_tree[window_id].get_component::<UIWindow>().expect("window").get_panel_node().expect("panel");
assert_eq!(node_tree[panel_id].get_name(), "helpPanel");
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
assert!(node_tree[window_id].is_active());창 닫기. (창 노드의 창 층을 찾아 close_window, 씬 코드와 단추 콜백에서 부른다, 떠 있지 않으면 아무 일도 없다)
Closes the window. (finds the window node's window layer and calls close_window, called from scene code and button callbacks, does nothing if not open)
- node_tree&mut NodeTree
- 노드 트리. (단추 콜백에서는 context.get_node_tree_mut())Node tree. (context.get_node_tree_mut() in button callbacks)
- window_idNodeId
- 닫을 창 노드.Window node to close.
use vanilla::{ComponentContext, NodeId, UIButton, UIWindow};
fn bind_close_button(button: &mut UIButton, window_id: NodeId) {
button.set_clicked_event(Box::new(move |_button: &mut UIButton, context: &mut ComponentContext| {
UIWindow::close_in_tree(context.get_node_tree_mut(), window_id);
}));
}창 다시 놓기. (내용이 바뀌어 판의 세로가 달라질 때, 씬 코드에서)
Lays out the window again. (when the content changes and the panel height differs, from scene code)
- node_tree&mut NodeTree
- 노드 트리.Node tree.
- window_idNodeId
- 다시 놓을 창 노드. (UIWindow 가 없으면 아무 일도 없다)Window node to lay out again. (does nothing if there is no UIWindow)
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);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
window_layer.set_view_size(tree, 800.0, 600.0, 1.0);
});
let window_id = UIWindow::create(&mut node_tree, layer_id, "list", Box::new(UIWindowDefaultBehavior));
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
node_tree[window_id].get_component_mut::<UIWindow>().expect("window").set_panel_height(400.0);
UIWindow::refresh_layout_in_tree(&mut node_tree, window_id);
assert_eq!(node_tree[window_id].get_component::<UIWindow>().expect("window").get_panel_rect().size.y, 400.0);pub fn layout_panel_default(node_tree: &mut NodeTree, parts: &UIWindowParts, panel_width: f64, panel_height: f64)#판 놓기 기본. (판을 틀의 왼쪽 위에 그 크기로)
Default panel layout. (the panel at the frame's top left at its size)
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- parts&UIWindowParts
- 창의 노드와 지금 놓인 값.The window's nodes and current layout values.
- panel_widthf64
- 판의 가로. (줄이기 전, UI 층 단위)Panel width. (before scaling down, UI layer units)
- panel_heightf64
- 판의 세로. (줄이기 전, UI 층 단위)Panel height. (before scaling down, UI layer units)
use std::any::Any;
use vanilla::{NodeId, NodeTree, UIWindow, UIWindowBehavior, UIWindowParts, Vector2};
struct ShadowWindow {
shadow_id: Option<NodeId>,
}
impl UIWindowBehavior for ShadowWindow {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn build(&mut self, node_tree: &mut NodeTree, parts: &UIWindowParts) {
let shadow_id = node_tree.create_child(parts.frame_id, "Shadow");
node_tree.set_sibling_index(shadow_id, 0);
self.shadow_id = Some(shadow_id);
}
fn layout_panel(&mut self, node_tree: &mut NodeTree, parts: &UIWindowParts, panel_width: f64, panel_height: f64) {
UIWindow::layout_panel_default(node_tree, parts, panel_width, panel_height);
if let Some(shadow_node) = self.shadow_id.and_then(|shadow_id| node_tree.get_node_mut(shadow_id)) {
shadow_node.set_content_size(Vector2::create(panel_width + 8.0, panel_height + 8.0));
}
}
}pub fn apply_motion_default(node_tree: &mut NodeTree, parts: &UIWindowParts, popup_motion: &PopupMotion)#움직임 걸기 기본. (틀 배율 = 줄인 배율 x 움직임 배율, 어둠 진하기 = 움직임 비율)
Default motion application. (frame scale = reduced scale x motion scale, dim strength = motion ratio)
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- parts&UIWindowParts
- 창의 노드와 지금 놓인 값. (panel_scale 을 쓴다)The window's nodes and current layout values. (uses panel_scale)
- popup_motion&PopupMotion
- 창의 움직임. (get_scale, get_dim_ratio 를 쓴다)The window's motion. (uses get_scale, get_dim_ratio)
pub fn set_covered_default(node_tree: &mut NodeTree, parts: &UIWindowParts, is_covered: bool)#덮기 기본. (덮이면 창 노드를 끄고 드러나면 켠다)
Default covering. (turns the window node off when covered and on when revealed)
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- parts&UIWindowParts
- 창의 노드와 지금 놓인 값.The window's nodes and current layout values.
- is_coveredbool
- 위에 다른 창이 떠 있으면 true.true if another window is open above.
덮어쓸 자리 꺼내기. (구체 타입이 맞으면)
Takes out the override points. (if the concrete type matches)
반환ReturnsOption<&T> 덮어쓸 자리가 T 면 Some(&T), 다른 타입이면 None.Some(&T) if the override points are T, None if another type.
덮어쓸 자리 꺼내기. (변경용)
Takes out the override points. (for modification)
반환ReturnsOption<&mut T> 덮어쓸 자리가 T 면 Some(&mut T), 다른 타입이면 None.Some(&mut T) if the override points are T, None if another type.
use vanilla::{NodeTree, UIConfirmWindow, UIConfirmWindowOptions, 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 = UIConfirmWindow::create(&mut node_tree, layer_id, "quit", UIConfirmWindowOptions::default());
let window = node_tree[window_id].get_component_mut::<UIWindow>().expect("window");
if let Some(confirm_window) = window.get_behavior_mut::<UIConfirmWindow>() {
confirm_window.set_confirm_event(Some(Box::new(|| {})));
}
assert!(window.get_behavior_mut::<UIWindowDefaultBehavior>().is_none());창의 노드와 지금 놓인 값. (만들기 전이면 None)
The window's nodes and current layout values. (None if not created yet)
반환ReturnsOption<UIWindowParts> 노드와 놓인 값. (트리에 붙기 전이면 None)Nodes and layout values. (None if not attached to the tree yet)
판 노드. (내용을 여기에 붙인다)
Panel node. (content is attached here)
반환ReturnsOption<NodeId> 판 노드. (트리에 붙기 전이면 None)Panel node. (None if not attached to the tree yet)
짝Counterpart: vanilla.js UIWindow.getPanelNode
틀 노드. (판과 함께 커지고 주는 꾸밈을 붙인다)
Frame node. (decorations that grow and shrink with the panel are attached here)
반환ReturnsOption<NodeId> 틀 노드. (트리에 붙기 전이면 None)Frame node. (None if not attached to the tree yet)
짝Counterpart: vanilla.js UIWindow.getFrameNode
어둠 노드.
Dim node.
반환ReturnsOption<NodeId> 어둠 노드. (트리에 붙기 전이면 None)Dim node. (None if not attached to the tree yet)
짝Counterpart: vanilla.js UIWindow.getDimNode
판의 Paint. (기본 판 그림, 바꾸거나 끌 때. 붙기 전이면 None)
The panel's Paint. (the default panel graphic, for changing or turning it off. None if not attached yet)
- node_tree&'a NodeTree
- 창이 든 노드 트리.Node tree holding the window.
반환ReturnsOption<&'a Paint> 판 노드의 Paint. (붙기 전이거나 판 노드나 Paint 가 없으면 None)The panel node's Paint. (None if not attached yet or if there is no panel node or Paint)
짝Counterpart: vanilla.js UIWindow.getPanelPaint
pub fn get_panel_paint_mut<'a>(&self, node_tree: &'a mut NodeTree) -> Option<&'a mut Paint>#판의 Paint. (변경용)
The panel's Paint. (for modification)
- node_tree&'a mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
반환ReturnsOption<&'a mut Paint> 판 노드의 Paint. (붙기 전이거나 판 노드나 Paint 가 없으면 None)The panel node's Paint. (None if not attached yet or if there is no panel node or Paint)
짝Counterpart: vanilla.js UIWindow.getPanelPaint
use vanilla::{Color, NodeTree, Paint, 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, "shop", Box::new(UIWindowDefaultBehavior));
let panel_id = node_tree.with_component_mut::<UIWindow, _>(window_id, |window, tree| {
if let Some(panel_paint) = window.get_panel_paint_mut(tree) {
panel_paint.set_color(Color::create(0.2, 0.1, 0.1, 1.0));
}
window.get_panel_node()
}).flatten().expect("panel");
assert_eq!(node_tree[panel_id].get_component::<Paint>().expect("paint").get_color(), Color::create(0.2, 0.1, 0.1, 1.0));어둠의 Paint. (붙기 전이면 None)
The dim's Paint. (None if not attached yet)
- node_tree&'a NodeTree
- 창이 든 노드 트리.Node tree holding the window.
반환ReturnsOption<&'a Paint> 어둠 노드의 Paint. (붙기 전이거나 어둠 노드나 Paint 가 없으면 None)The dim node's Paint. (None if not attached yet or if there is no dim node or Paint)
짝Counterpart: vanilla.js UIWindow.getDimPaint
어둠의 Paint. (변경용)
The dim's Paint. (for modification)
- node_tree&'a mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
반환ReturnsOption<&'a mut Paint> 어둠 노드의 Paint. (붙기 전이거나 어둠 노드나 Paint 가 없으면 None)The dim node's Paint. (None if not attached yet or if there is no dim node or Paint)
짝Counterpart: vanilla.js UIWindow.getDimPaint
마지막으로 받은 영역의 가로. (UI 층 단위)
Width of the last received area. (UI layer units)
반환Returnsf64 영역의 가로. (1 이상, 받기 전에는 1)Area width. (1 or more, 1 before receiving)
짝Counterpart: vanilla.js UIWindow.getViewWidth
마지막으로 받은 영역의 세로. (UI 층 단위)
Height of the last received area. (UI layer units)
반환Returnsf64 영역의 세로. (1 이상, 받기 전에는 1)Area height. (1 or more, 1 before receiving)
짝Counterpart: vanilla.js UIWindow.getViewHeight
영역 가장자리와 판 사이 거리 반환.
Returns the distance between the area edge and the panel.
반환Returnsf64 거리. (UI 층 단위, 기본 16)Distance. (UI layer units, default 16)
짝Counterpart: vanilla.js UIWindow.getMargin
판의 세로 반환. (set_panel_height 의 값)
Returns the panel height. (the set_panel_height value)
반환Returnsf64 판의 세로. (UI 층 단위, 기본 240)Panel height. (UI layer units, default 240)
짝Counterpart: vanilla.js UIWindow.getPanelHeight
마지막으로 놓은 판의 자리. (창 좌표, 움직임 전, 줄인 배율을 곱한 크기)
Rect of the last placed panel. (window coordinates, before motion, size multiplied by the shrink scale)
반환ReturnsRect 판의 사각형. (놓기 전에는 (0, 0, 1, 1))The panel's rectangle. ((0, 0, 1, 1) before layout)
짝Counterpart: vanilla.js UIWindow.getPanelRect
판이 영역보다 커서 줄인 배율. (1 이하)
Scale by which the panel was shrunk because it was larger than the area. (1 or less)
반환Returnsf64 배율. (0 보다 크고 1 이하, 줄이지 않았으면 1)Scale. (greater than 0 and at most 1, 1 if not scaled down)
짝Counterpart: vanilla.js UIWindow.getPanelScale
pub fn handle_wheel(&mut self, node_tree: &mut NodeTree, view_input_position: Vector2, wheel_delta: Vector2) -> bool#휠 받기. (UIWindowBehavior::handle_wheel, 받았으면 true, 원본 handleWheel)
Receives the wheel. (UIWindowBehavior::handle_wheel, true if taken, original handleWheel)
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- view_input_positionVector2
- 휠을 굴린 자리. (뷰 좌표)Position where the wheel was rolled. (view coordinates)
- wheel_deltaVector2
- 휠을 굴린 양.Amount the wheel was rolled.
반환Returnsbool 덮어쓸 자리가 받았으면 true. (트리에 붙기 전이면 false)true if the override points took it. (false if not attached to the tree yet)
짝Counterpart: vanilla.js UIWindow.handleWheel
움직임 반환.
Returns the motion.
반환Returns&PopupMotion 창의 열고 닫는 움직임.The window's open and close motion.
짝Counterpart: vanilla.js UIWindow.getPopupMotion
움직임 반환. (변경용, set_instant_enabled 로 움직임 없이 열고 닫는다)
Returns the motion. (for modification, opens and closes without motion via set_instant_enabled)
반환Returns&mut PopupMotion 창의 열고 닫는 움직임.The window's open and close motion.
짝Counterpart: vanilla.js UIWindow.getPopupMotion
바깥 누르기(와 창 층의 close_top_window)로 닫히는지 설정. (기본 true)
Sets whether an outside press (and the window layer's close_top_window) closes it. (default true)
- is_outside_close_enabledbool
- 바깥 누르기와 뒤로 가기로 닫히면 true.true if it closes on outside press and back.
짝Counterpart: vanilla.js UIWindow.setOutsideCloseEnabled
바깥 누르기로 닫히는지.
Whether pressing outside closes it.
반환Returnsbool 닫히면 true. (기본 true)true if it closes. (default true)
짝Counterpart: vanilla.js UIWindow.isOutsideCloseEnabled
창 층에서 내려갈 때 알림 설정.
Sets the notification for when it is removed from the window layer.
- close_eventOption<UIWindowEvent>
- 알림. (None 이면 끈다, UIWindowBehavior::handle_closed 보다 먼저 부른다)Notification. (None turns it off, called before UIWindowBehavior::handle_closed)
짝Counterpart: vanilla.js UIWindow.setCloseEvent
창의 가로 한계 설정. (영역이 좁으면 그보다 좁아진다, 다음 놓을 때부터)
Sets the window's width limit. (narrower than that if the area is narrow, from the next layout)
- maximum_widthf64
- 판의 가로 한계. (UI 층 단위, 1 보다 작으면 1)Panel width limit. (UI layer units, 1 if less than 1)
짝Counterpart: vanilla.js UIWindow.setMaximumWidth
창의 가로 한계 반환.
Returns the window's width limit.
반환Returnsf64 판의 가로 한계. (UI 층 단위, 기본 480)Panel width limit. (UI layer units, default 480)
짝Counterpart: vanilla.js UIWindow.getMaximumWidth
영역 가장자리와 판 사이 거리 설정.
Sets the distance between the area edge and the panel.
- marginf64
- 거리. (UI 층 단위, 0 보다 작으면 0, 다음 놓을 때부터)Distance. (UI layer units, 0 if less than 0, from the next layout)
짝Counterpart: vanilla.js UIWindow.setMargin
판의 세로 설정. (layout_content 를 덮어쓰지 않은 창이 쓴다)
Sets the panel height. (used by windows that do not override layout_content)
- panel_heightf64
- 판의 세로. (UI 층 단위, 1 보다 작으면 1, 다음 놓을 때부터)Panel height. (UI layer units, 1 if less than 1, from the next layout)
짝Counterpart: vanilla.js UIWindow.setPanelHeight
어둠 색 설정. (값만 담는다, 붙기 전에 정한다. 붙은 뒤에 바꾸려면 어둠 노드의 Paint 색을 바꾼다)
Sets the dim color. (only stores the value, set it before attaching. To change it after attaching, change the Paint color of the dim node)
- dim_colorimpl Into<Color>
- 어둠 색. (기본
Color::create(0.0, 0.0, 0.0, 0.55), 트리에 붙을 때 어둠 Paint 에 쓴다)Dim color. (defaultColor::create(0.0, 0.0, 0.0, 0.55), applied to the dim Paint when attached to the tree)
짝Counterpart: vanilla.js UIWindow.setDimColor
판 색 설정. (값만 담는다, 붙기 전에 정한다. 붙은 뒤에 바꾸려면 판 노드의 Paint 색을 바꾼다)
Sets the panel color. (only stores the value, set it before attaching. To change it after attaching, change the Paint color of the panel node)
- panel_colorimpl Into<Color>
- 판 색. (기본
Color::create(0.13, 0.15, 0.2, 1.0), 트리에 붙을 때 판 Paint 에 쓴다)Panel color. (defaultColor::create(0.13, 0.15, 0.2, 1.0), applied to the panel Paint when attached to the tree)
짝Counterpart: vanilla.js UIWindow.setPanelColor
띄운 창 층 노드. (띄우기 전이나 내려간 뒤면 None)
The window layer node it is open on. (None before opening or after removal)
반환ReturnsOption<NodeId> 창 층 노드. (떠 있을 때만 Some)Window layer node. (Some only while open)
띄운 창 층 노드 설정. (창 층이 부른다)
Sets the window layer node it is open on. (called by the window layer)
- window_layer_idOption<NodeId>
- 띄운 창 층 노드. (내려가면 None)The window layer node it is open on. (None when removed)
영역 밖으로 더 덮는 너비 반환. (위, 오른쪽, 아래, 왼쪽)
Returns the extra coverage width beyond the area. (top, right, bottom, left)
반환Returns[f64; 4] [위, 오른쪽, 아래, 왼쪽] 너비. (UI 층 단위, 처음은 모두 0)[top, right, bottom, left] widths. (UI layer units, all 0 initially)
짝Counterpart: vanilla.js UIWindow.getViewBleed
pub fn set_view_bleed(&mut self, node_tree: &mut NodeTree, top: f64, right: f64, bottom: f64, left: f64)#영역 밖으로 더 덮는 너비 알리기. (세이프에어리어, UI 층 단위, 어둠이 그 밑까지 덮는다)
Notifies the extra width covered outside the area. (safe area, UI layer units, the dim covers underneath it too)
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- 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 UIWindow.setViewBleed
pub fn set_view_size(&mut self, node_tree: &mut NodeTree, view_width: f64, view_height: f64)#영역의 크기 알리기. (어둠을 덮고, 판의 가로를 정해 내용을 놓은 뒤 가운데에 둔다)
Notifies the area size. (covers it with the dim, sets the panel width, lays out the content, then centers it)
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- view_widthf64
- 영역의 가로. (UI 층 단위, 1 보다 작으면 1)Area width. (UI layer units, 1 if less than 1)
- view_heightf64
- 영역의 세로. (UI 층 단위, 1 보다 작으면 1)Area height. (UI layer units, 1 if less than 1)
짝Counterpart: vanilla.js UIWindow.setViewSize
다시 놓기. (마지막 영역의 크기로)
Lays out again. (with the last area size)
- node_tree&mut NodeTree
- 창이 든 노드 트리. (트리에 붙기 전이면 아무 일도 없다)Node tree holding the window. (does nothing if not attached to the tree yet)
짝Counterpart: vanilla.js UIWindow.refreshLayout
덮였는지 알리기. (창 층이 부른다)
Notifies whether it is covered. (called by the window layer)
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
- is_coveredbool
- 위에 다른 창이 떠 있으면 true. (UIWindowBehavior::set_covered 에 넘긴다)true if another window is open above. (passed to UIWindowBehavior::set_covered)
짝Counterpart: vanilla.js UIWindow.setCovered
여는 움직임 시작. (창 층이 띄울 때 부른다, 창 노드를 켠다)
Starts the open motion. (called by the window layer when opening, turns the window node on)
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
짝Counterpart: vanilla.js UIWindow.startOpenMotion
닫는 움직임 시작. (창 층이 내릴 때 부른다, 그동안은 누름을 받지 않는다)
Starts the close motion. (called by the window layer when removing, it does not receive presses in the meantime)
- node_tree&mut NodeTree
- 창이 든 노드 트리.Node tree holding the window.
짝Counterpart: vanilla.js UIWindow.startCloseMotion
닫는 움직임이 끝났는지.
Whether the close motion has finished.
반환Returnsbool 움직임이 닫힘 상태면 true. (띄운 적이 없어도 true, 즉시 전환이면 닫자마자 true)true if the motion is in the closed state. (true even if never opened, true right after closing for instant transitions)
짝Counterpart: vanilla.js UIWindow.isCloseMotionFinished
창 층에서 내려감. (창 층이 부른다: 알림 → UIWindowBehavior::handle_closed)
Removed from the window layer. (called by the window layer: notification → UIWindowBehavior::handle_closed)
짝Counterpart: vanilla.js UIWindow.handleClosed
창 층이 창을 떼어 낼 때. (창 층이 부른다, 노드는 지우지 않고 남아 다시 띄울 수 있다)
When the window layer detaches the window. (called by the window layer, the node is not deleted and remains so it can be shown again)
- node_tree&mut NodeTree
- 창이 든 노드 트리. (UIWindowBehavior::dispose 에 넘긴다)Node tree holding the window. (passed to UIWindowBehavior::dispose)
짝Counterpart: vanilla.js UIWindow.dispose