ui/uitoast
토스트. (원본 ui/uitoast.js 의 UIToast)
- show(message) 로 알약 모양 알림이 아래에서 떠올라(0.24 초) 잠시 머문 뒤(기본 1.8 초) 위로 빠지며 사라진다(0.2 초).
- 여러 번 부르면 줄을 세워 하나씩 보여 준다.
- 씬 뿌리의 맨 위(마지막 자식)에 두고 쓴다. 가로 자리를 정하지 않으면 부모 가로 가운데에 선다. (부모 크기를 모르면 480)
- 원본은 WorldNode 를 상속한 노드이고 노드 자신이 알약이다. 러스트 판은 노드(호스트)에 붙는 컴포넌트이고, 붙을 때 원본 생성자처럼 호스트를 꾸미고(가운데 피봇, 크기) Paint(둥근 알약)와 UILabel 을 호스트에 붙인다. UIToast::create(node_tree, parent_id, options) 가 new + add_child 자리다.
- 사용:
let toast_id = UIToast::create(node_tree, root_id, UIToastOptions::default());
node_tree[toast_id].get_component_mut::<UIToast>().unwrap().show("저장되었습니다.");- 원본과 다른 것:
- show 는 줄에 넣기만 하고, 꺼내서 보이는 것은 다음 tick 이 한다. (같은 tick 에 첫 걸음도 가므로 시간 흐름은 원본과 같다) 그래서 원본은 숨을 때 set_active(false) 하지만 러스트 판은 tick 이 돌아야 해서 set_visible(false) 로 숨긴다. UI 문서는 원본처럼 숨은 토스트를 active false 로 쓰고 읽는다. (uidocument.rs 의 UIDocumentNode)
- 등장 / 머묾 / 퇴장 시간과 곡선은 원본 그대로 이 안에서 센다. (Tween 은 쓰지 않는다)
- 가로 자리 rest_x 는
Option<f64>다. (원본 null = 부모 가운데) options 객체는 UIToastOptions 구조체다.
Toast. (UIToast of the original ui/uitoast.js)
- With show(message), a pill-shaped notification rises from below (0.24 seconds), stays a while (default 1.8 seconds), then exits upward and disappears (0.2 seconds).
- Calling it several times queues them and shows them one at a time.
- Place it at the top of the scene root (the last child). If the horizontal position is not set, it stands at the parent's horizontal center. (480 if the parent size is unknown)
- The original is a node that inherits WorldNode, and the node itself is the pill. The Rust version is a component attached to a node (host), and on attach, like the original constructor, it sets up the host (center pivot, size) and attaches Paint (rounded pill) and UILabel to the host. UIToast::create(node_tree, parent_id, options) takes the place of new + add_child.
- Usage:
let toast_id = UIToast::create(node_tree, root_id, UIToastOptions::default());
node_tree[toast_id].get_component_mut::<UIToast>().unwrap().show("Saved.");- Differences from the original:
- show only puts it in the queue, and the next tick takes it out and shows it. (the first step also happens on the same tick, so the timing is the same as the original) So while the original calls set_active(false) when hiding, the Rust version needs tick to run, so it hides with set_visible(false). The UI document writes and reads a hidden toast as active false, as in the original. (UIDocumentNode in uidocument.rs)
- The appear / stay / exit times and curves are counted inside here exactly as in the original. (Tween is not used)
- The horizontal position rest_x is
Option<f64>. (original null = parent center) The options object is the UIToastOptions struct.
UIToastOptionsstruct traits Clone, Copy, Debug, PartialEq, Default
토스트 설정. (원본 options = { width = 400, height = 48, rest_y = 560, rest_x = null, hold_seconds = 1.8, font_size = 15, background_color?, text_color? })
Toast settings. (original options = { width = 400, height = 48, rest_y = 560, rest_x = null, hold_seconds = 1.8, font_size = 15, background_color?, text_color? })
use vanilla::{NodeTree, UIToast, UIToastOptions, Vector2};
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let options = UIToastOptions {
width: 320.0,
rest_y: 80.0,
hold_seconds: 3.0,
..UIToastOptions::default()
};
let toast_id = UIToast::create(&mut node_tree, root_id, options);
assert_eq!(node_tree[toast_id].get_content_size(), Vector2::create(320.0, 48.0));
assert!(!node_tree[toast_id].is_visible());알약 세로. (기본 48, 둥근 정도는 그 반)
Pill height. (default 48, the rounding is half of it)
반환Returnsf64
머무는 자리의 가운데 세로 좌표.
Vertical coordinate of the center of the resting position.
반환Returnsf64
머무는 자리의 가운데 가로 좌표. (None 이면 부모 가로 가운데)
Horizontal coordinate of the center of the resting position. (None for the parent's horizontal center)
반환ReturnsOption<f64>
UIToaststruct traits Default, Component, UIDocumentNode
토스트.
Toast.
use vanilla::{Engine, EngineConfiguration, NodeTree, UILabel, UIToast, UIToastOptions, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
node_tree[root_id].set_content_size(Vector2::create(800.0, 600.0));
let toast_id = UIToast::create(&mut node_tree, root_id, UIToastOptions::default());
node_tree[toast_id].get_component_mut::<UIToast>().expect("toast").show("Saved.");
node_tree.tick(&engine, 0.24);
assert!(node_tree[toast_id].is_visible());
assert_eq!(node_tree[toast_id].get_component::<UILabel>().expect("label").get_text(), "Saved.");
assert_eq!(node_tree[toast_id].get_local_position(), Vector2::create(400.0, 560.0));생성. (기본 설정)
Constructor. (default settings)
반환ReturnsUIToast 붙기 전의 토스트. (UIToastOptions::default)Toast before being attached. (UIToastOptions::default)
짝Counterpart: vanilla.js UIToast.constructor
설정으로 생성. (노드에는 node_tree.add_component 로 붙인다)
Creates with settings. (attach to a node with node_tree.add_component)
- optionsUIToastOptions
- 토스트 설정.Toast settings.
반환ReturnsUIToast 붙기 전의 토스트.Toast before being attached.
pub fn create(node_tree: &mut NodeTree, parent_id: NodeId, options: UIToastOptions) -> NodeId#노드 만들기. (parent_id 밑에 "UIToast" 노드를 만들어 붙인다. 원본 new UIToast(options) + add_child)
Creates the node. (creates and attaches a "UIToast" node under parent_id. original new UIToast(options) + add_child)
- node_tree&mut NodeTree
- 노드 트리.Node tree.
- parent_idNodeId
- 부모 노드. (보통 씬 뿌리, 가로 자리를 정하지 않으면 그 가로 가운데에 선다)Parent node. (usually the scene root, stands at its horizontal center if the horizontal position is not set)
- optionsUIToastOptions
- 토스트 설정.Toast settings.
반환ReturnsNodeId 만든 토스트 노드. (보이기 전이라 숨어 있다)The created toast node. (hidden because it has not been shown yet)
토스트 표시. (줄에 넣는다. 보이는 중이면 차례를 기다린다)
Shows a toast. (puts it in the queue. waits its turn if one is showing)
- message_text&str
- 보일 글. (다음 tick 부터 보인다)Text to show. (shown from the next tick)
짝Counterpart: vanilla.js UIToast.show
use vanilla::{Engine, EngineConfiguration, NodeTree, UILabel, UIToast, UIToastOptions};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let toast_id = UIToast::create(&mut node_tree, root_id, UIToastOptions::default());
if let Some(toast) = node_tree[toast_id].get_component_mut::<UIToast>() {
toast.show("First");
toast.show("Second");
}
node_tree.tick(&engine, 0.24);
node_tree.tick(&engine, 1.8);
node_tree.tick(&engine, 0.2);
assert_eq!(node_tree[toast_id].get_component::<UILabel>().expect("label").get_text(), "Second");머무는 자리(가운데 세로 좌표) 설정.
Sets the resting position (vertical coordinate of the center).
- rest_yf64
- 머무는 자리의 가운데 세로 좌표. (부모 로컬 좌표, 등장할 때는 28 아래에서 떠오른다, 다음 자리 셈부터)Vertical coordinate of the center of the resting position. (parent local coordinates, rises from 28 below when appearing, from the next position calculation)
짝Counterpart: vanilla.js UIToast.setRestY
머무는 자리(가운데 가로 좌표) 설정. (None 이면 부모 가로 가운데)
Sets the resting position (horizontal coordinate of the center). (None for the parent's horizontal center)
- rest_xOption<f64>
- 머무는 자리의 가운데 가로 좌표. (부모 로컬 좌표, None 이면 부모 가로 가운데, 부모 크기를 모르면 480)Horizontal coordinate of the center of the resting position. (parent local coordinates, None for the parent's horizontal center, 480 if the parent size is unknown)
짝Counterpart: vanilla.js UIToast.setRestX
머무는 시간 설정. (초)
Sets the stay time. (seconds)
- hold_secondsf64
- 다 떠오른 뒤 머무는 시간. (초, 기본 1.8)Stay time after fully rising. (seconds, default 1.8)
짝Counterpart: vanilla.js UIToast.setHoldSeconds
보이는 중인지. (줄에 남은 메시지가 있어도 참)
Whether it is showing. (true even if messages remain in the queue)
반환Returnsbool 등장, 머묾, 퇴장 중이거나 줄에 기다리는 메시지가 있으면 true.true if appearing, staying, exiting, or there are messages waiting in the queue.
짝Counterpart: vanilla.js UIToast.isShowing