ui/uispinner
회전 로딩 표시. (원본 ui/uispinner.js 의 UISpinner)
- 원 둘레에 점 여러 개를 놓고, 밝기가 꼬리처럼 돌아가는 표준 스피너. (점 투명도 0.15 ~ 1)
- 원본은 WorldNode 를 상속한 노드다. 러스트 판은 노드(호스트)에 붙는 컴포넌트이고, 붙을 때 원본 생성자처럼 호스트를 꾸미고(가운데 피봇, 크기 = (반지름 + 점 반지름) x 2) 점 노드(둥근 Paint)를 자식으로 만든다. UISpinner::create(node_tree, parent_id, options) 가 원본 new UISpinner(options) + add_child 자리다.
- 사용:
let spinner_id = UISpinner::create(node_tree, panel_id, UISpinnerOptions { radius: 9.0, dot_count: 10, ..UISpinnerOptions::default() });
node_tree[spinner_id].set_local_position(Vector2::create(x, y));- 원본과 다른 것:
- set_dot_color 는 색을 정해 두고 다음 tick 에 점 노드에 건다. (점 노드는 씬 코드가 이 위젯을 쥔 동안 닿을 수 없다)
- 위상(phase)은 0 ~ 1 로 접어 둔다. 꼬리 계산이 1 주기라 보이는 결과는 같고, 오래 돌아도 정밀도가 떨어지지 않는다.
- 점 노드 이름은 원본처럼 "SpinnerDot{번호}" 다. options 객체는 UISpinnerOptions 구조체다.
Spinning loading indicator. (UISpinner of the original ui/uispinner.js)
- A standard spinner that places several dots around a circle with brightness rotating like a tail. (dot opacity 0.15 ~ 1)
- The original is a node that inherits WorldNode. 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 = (radius + dot radius) x 2) and creates dot nodes (rounded Paint) as children. UISpinner::create(node_tree, parent_id, options) takes the place of the original new UISpinner(options) + add_child.
- Usage:
let spinner_id = UISpinner::create(node_tree, panel_id, UISpinnerOptions { radius: 9.0, dot_count: 10, ..UISpinnerOptions::default() });
node_tree[spinner_id].set_local_position(Vector2::create(x, y));- Differences from the original:
- set_dot_color sets the color and applies it to the dot nodes on the next tick. (the dot nodes cannot be reached while scene code holds this widget)
- The phase is wrapped to 0 ~ 1. The tail calculation has a period of 1, so the visible result is the same, and precision does not degrade even after spinning a long time.
- Dot node names are "SpinnerDot{index}" as in the original. The options object is the UISpinnerOptions struct.
UISpinnerOptionsstruct traits Clone, Copy, Debug, PartialEq, Default
스피너 설정. (원본 options = { radius = 9, dot_count = 10, dot_radius = 2, color?, rotation_speed = 1 })
Spinner settings. (original options = { radius = 9, dot_count = 10, dot_radius = 2, color?, rotation_speed = 1 })
use vanilla::{NodeTree, UISpinner, UISpinnerOptions, Vector2};
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let options = UISpinnerOptions {
dot_count: 4,
..UISpinnerOptions::default()
};
let spinner_id = UISpinner::create(&mut node_tree, root_id, options);
assert_eq!(node_tree[spinner_id].get_content_size(), Vector2::create(22.0, 22.0));
assert_eq!(node_tree[spinner_id].get_component::<UISpinner>().expect("spinner").get_dot_nodes().len(), 4);UISpinnerstruct traits Default, Component, UIDocumentNode
회전 로딩 표시.
Spinning loading indicator.
use vanilla::{Engine, EngineConfiguration, NodeTree, UISpinner, UISpinnerOptions, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let panel_id = node_tree.create_child(root_id, "Panel");
let spinner_id = UISpinner::create(&mut node_tree, panel_id, UISpinnerOptions { radius: 9.0, dot_count: 10, ..UISpinnerOptions::default() });
node_tree[spinner_id].set_local_position(Vector2::create(120.0, 80.0));
node_tree[spinner_id].get_component_mut::<UISpinner>().expect("spinner").set_dot_color("#ffcc00");
node_tree.tick(&engine, 0.1);
let dot_ids = node_tree[spinner_id].get_component::<UISpinner>().expect("spinner").get_dot_nodes().to_vec();
assert!((node_tree[dot_ids[1]].get_local_opacity() - 1.0).abs() < 0.0001);생성. (기본 설정)
Constructor. (default settings)
반환ReturnsUISpinner 붙기 전의 스피너. (UISpinnerOptions::default)Spinner before being attached. (UISpinnerOptions::default)
짝Counterpart: vanilla.js UISpinner.constructor
설정으로 생성. (노드에는 node_tree.add_component 로 붙인다)
Creates with settings. (attach to a node with node_tree.add_component)
- optionsUISpinnerOptions
- 스피너 설정.Spinner settings.
반환ReturnsUISpinner 붙기 전의 스피너.Spinner before being attached.
pub fn create(node_tree: &mut NodeTree, parent_id: NodeId, options: UISpinnerOptions) -> NodeId#노드 만들기. (parent_id 밑에 "UISpinner" 노드를 만들어 붙인다. 원본 new UISpinner(options) + add_child)
Creates the node. (creates and attaches a "UISpinner" node under parent_id. original new UISpinner(options) + add_child)
- node_tree&mut NodeTree
- 노드 트리.Node tree.
- parent_idNodeId
- 부모 노드.Parent node.
- optionsUISpinnerOptions
- 스피너 설정.Spinner settings.
반환ReturnsNodeId 만든 스피너 노드. (가운데 피봇, 크기는 (반지름 + 점 반지름) x 2)The created spinner node. (center pivot, size is (radius + dot radius) x 2)
점 투명도 계산. (점 순서 비율에서 위상을 뺀 꼬리 비율이 작을수록 밝다)
- 점이 없으면(dot_count 0) 순서 비율을 0 으로 본다.
Computes a dot's opacity. (the smaller the tail ratio, the dot order ratio minus the phase, the brighter)
- If there are no dots (dot_count 0), the order ratio is treated as 0.
- dot_indexusize
- 점 번호. (0 부터, 0 번은 원의 오른쪽이고 번호가 늘수록 시계 방향)Dot index. (from 0, index 0 is on the right of the circle and higher indices go clockwise)
반환Returnsf64 점 투명도. (0.15 ~ 1)Dot opacity. (0.15 ~ 1)
짝Counterpart: vanilla.js UISpinner.calculateDotOpacity
use vanilla::UISpinner;
let spinner = UISpinner::new();
assert!((spinner.calculate_dot_opacity(0) - 1.0).abs() < 0.0001);
assert!((spinner.calculate_dot_opacity(5) - 0.575).abs() < 0.0001);점 색 설정. (다음 tick 에 점 노드에 건다)
Sets the dot color. (applied to the dot nodes on the next tick)
- dot_colorimpl Into<Color>
- 점 색. (
"#ff0000"같은 글이나 Color)Dot color. (text like"#ff0000"or a Color)
짝Counterpart: vanilla.js UISpinner.setDotColor
점 색 반환.
Returns the dot color.
반환ReturnsColor 점 색. (처음은 설정의 color)Dot color. (initially the color from the settings)
짝Counterpart: vanilla.js UISpinner.getDotColor
회전 속도 설정. (초당 바퀴 수)
Sets the rotation speed. (turns per second)
- rotation_speedf64
- 초당 바퀴 수. (음수면 반대로 돈다)Turns per second. (spins the other way if negative)
짝Counterpart: vanilla.js UISpinner.setRotationSpeed
회전 속도 반환.
Returns the rotation speed.
반환Returnsf64 초당 바퀴 수. (처음은 설정의 rotation_speed, 기본 1)Turns per second. (initially rotation_speed from the settings, default 1)
짝Counterpart: vanilla.js UISpinner.getRotationSpeed
점 노드 핸들 목록.
List of dot node handles.
반환Returns&[NodeId] 점 노드. (번호 차례, 트리에 붙기 전이면 빈 목록)Dot nodes. (in index order, an empty list before being attached to a tree)
짝Counterpart: vanilla.js UISpinner.getDotNodes