core/component
컴포넌트.
- 노드에 붙는 기능 단위. 원본은 Component 클래스를 상속하고, 여기서는 Component 트레이트를 구현한다.
- 원본의 컴포넌트는 get_node() 로 자기 노드를 찾는다. 러스트 판은 tick / 터치 때 ComponentContext 를 넘겨 준다. 문맥에서 자기 노드(트랜스폼), 트리 전체(다른 노드 찾기, 만들기, 지우기), 엔진(입력, 시간, 뷰)을 꺼낸다.
- draw 는 노드 트랜스폼이 걸린 상태에서 자기 트랜스폼만 받는다. (그리는 동안에는 트리를 바꾸지 않는다)
- push_transform, pop_transform 은 노드를 그리는 앞뒤(자기 컴포넌트와 자식, 기즈모를 감싸서)에 불린다. 원본 노드가 pushTransform, popTransform 을 덮어써 자손까지 그리는 상태(블렌드 같은 것)를 바꾸던 자리다. (TouchEffect 의 더하기 블렌드)
- enable / gizmo 같은 공통 상태는 ComponentBase 에 두고, 구현체는 그것을 돌려주기만 한다.
- 의존 컴포넌트(원본 require): 원본은 클래스 목록을 돌려준다. 러스트 판은 RequiredComponent(타입과 기본값으로 만드는 함수) 목록을 돌려주고, WorldNode::add_component 가 붙이기 전에 그 타입이 없으면 만들어 붙인다. 떼어질 때는 원본처럼 detach 를 부른다.
- 원본 setNode, getNode, setComponentType 은 옮기지 않았다. 러스트 판은 노드를 문맥으로 넘기고(전역 객체 참조가 없다) 이름은 타입이 정한다.
- 반사(원본이 실행 중에 프로토타입을 훑어 get, is, set 함수를 찾는 것): impl 블록과 impl Component 블록에
#[vanilla::reflect]를 붙이면 매크로가 컴파일 때 그 목록과 부르는 코드를 짓는다. (core/reflection.rs, 언리얼 UHT 와 같은 꼴) Reflect 가 Component 의 상위 트레이트라 매크로를 빠뜨린 컴포넌트는 컴파일되지 않는다. 그래서 원본처럼 모든 컴포넌트가 반사된다. 반사를 쓰는 쪽은&dyn Component를&dyn Reflect로 올려 부른다. (트레이트 업캐스팅) 구체 타입으로 꺼내기(C++ RTTI 의 dynamic_cast 자리)는 AsAny 다.
Component.
- A unit of functionality attached to a node. In the original it inherits the Component class, here it implements the Component trait.
- Components in the original find their own node with get_node(). The Rust version passes a ComponentContext on tick / touch. From the context it takes its own node (transform), the whole tree (finding, creating, removing other nodes) and the engine (input, time, view).
- draw receives only its own transform, with the node transform applied. (the tree is not changed while drawing)
- push_transform and pop_transform are called before and after drawing the node (wrapping its own components, children and gizmos). This is where an original node overrode pushTransform and popTransform to change drawing state for its descendants too (such as blending). (TouchEffect's additive blend)
- Common state such as enable / gizmo lives in ComponentBase, and implementors only return it.
- Dependent components (the original require): the original returns a list of classes. The Rust version returns a list of RequiredComponent (a type and a function that creates it with default values), and WorldNode::add_component creates and attaches that type before attaching if it is missing. When detached, detach is called as in the original.
- The original setNode, getNode and setComponentType were not ported. The Rust version passes the node through the context (there are no global object references) and the type decides the name.
- Reflection (the original scans the prototype at runtime to find get, is, set functions): attach
#[vanilla::reflect]to the impl block and the impl Component block, and the macro builds that list and the code that calls it at compile time. (core/reflection.rs, the same approach as Unreal's UHT) Reflect is a supertrait of Component, so a component without the macro does not compile. So like the original, every component is reflected. The side that uses reflection upcasts&dyn Componentto&dyn Reflectand calls it. (trait upcasting) Getting the concrete type out (in place of C++ RTTI's dynamic_cast) is done with AsAny.
RequiredComponentstruct
의존 컴포넌트 하나. (그 타입과 없을 때 만드는 함수, 원본 require 가 돌려주는 클래스 자리)
- Component::require 가 돌려주는 목록의 한 칸이다. 보통 RequiredComponent::of 로 만든다.
One dependent component. (its type and the function that creates it when missing, in place of the class returned by the original require)
- One entry of the list returned by Component::require. Usually created with RequiredComponent::of.
use vanilla::core::component::RequiredComponent;
use vanilla::{Component, ComponentBase, WorldNode};
#[derive(Default)]
struct Body {
component_base: ComponentBase,
}
#[vanilla::reflect]
impl Body {}
#[vanilla::reflect]
impl Component for Body {
fn get_component_base(&self) -> &ComponentBase {
&self.component_base
}
fn get_component_base_mut(&mut self) -> &mut ComponentBase {
&mut self.component_base
}
fn get_component_type(&self) -> &'static str {
"Body"
}
}
#[derive(Default)]
struct Walker {
component_base: ComponentBase,
}
#[vanilla::reflect]
impl Walker {}
#[vanilla::reflect]
impl Component for Walker {
fn get_component_base(&self) -> &ComponentBase {
&self.component_base
}
fn get_component_base_mut(&mut self) -> &mut ComponentBase {
&mut self.component_base
}
fn get_component_type(&self) -> &'static str {
"Walker"
}
fn require(&self) -> Vec<RequiredComponent> {
vec![RequiredComponent::of::<Body>()]
}
}
let mut node = WorldNode::new("walker");
node.add_component(Walker::default());
assert!(node.has_component::<Body>());
node.add_component(Walker::default());
assert_eq!(node.get_components::<Body>().len(), 1);그 타입의 기본값으로 만드는 의존 컴포넌트.
Dependent component created with the type's default value.
반환ReturnsRequiredComponent T 의 타입과 T::default() 로 만드는 함수를 든 의존 컴포넌트.Dependent component holding T's type and a function that creates it with T::default().
의존 컴포넌트의 타입. (같은 노드에 이 타입이 이미 있으면 만들지 않는다)
Type of the dependent component. (not created if the same node already has this type)
반환ReturnsTypeId
그 타입이 없을 때 새로 만드는 함수.
Function that creates a new one when the type is missing.
반환Returnsfn() -> Box<dyn Component>
AsAnytrait
구체 타입으로 꺼내기 위한 도움 트레이트. (get_component::<Sprite>() 같은 곳)
- Component 를 구현한 'static 타입이면 저절로 구현된다. (직접 구현하지 않는다)
dyn Component에서 부를 때는 이 트레이트를 use 로 들여온다.
Helper trait for getting the concrete type out. (in places such as get_component::<Sprite>())
- Implemented automatically for any 'static type that implements Component. (do not implement it yourself)
- To call it on a
dyn Component, bring this trait in with use.
use vanilla::core::component::AsAny;
use vanilla::{Component, Paint, Text};
let component: Box<dyn Component> = Box::new(Paint::new());
let component_reference: &dyn Component = component.as_ref();
assert!(component_reference.as_any().is::<Paint>());
assert!(component_reference.as_any().downcast_ref::<Text>().is_none());&dyn Any 로 보기. (downcast_ref 로 구체 타입을 꺼낸다)
View as &dyn Any. (get the concrete type out with downcast_ref)
반환Returns&dyn Any 자기 자신을 가리키는 &dyn Any.&dyn Any pointing to itself.
&mut dyn Any 로 보기. (downcast_mut 로 구체 타입을 꺼낸다)
View as &mut dyn Any. (get the concrete type out with downcast_mut)
반환Returns&mut dyn Any 자기 자신을 가리키는 &mut dyn Any.&mut dyn Any pointing to itself.
ComponentBasestruct traits Clone, Debug, Default
컴포넌트 공통 상태.
- 켜짐(기본 true)과 기즈모 표시(기본 false)를 든다. 구현체가 필드로 들고 get_component_base 로 돌려준다.
Common component state.
- Holds enabled (default true) and gizmo display (default false). Implementors hold it as a field and return it from get_component_base.
use vanilla::ComponentBase;
let mut component_base = ComponentBase::new();
assert!(component_base.is_enable());
assert!(!component_base.is_gizmo_visible());
component_base.set_enable(false);
component_base.set_gizmo_visible(true);
assert!(!component_base.is_enable());
assert!(component_base.is_gizmo_visible());생성.
Constructor.
반환ReturnsComponentBase 켜져 있고 기즈모는 꺼진 공통 상태.Common state that is enabled with gizmos off.
짝Counterpart: vanilla.js Component.constructor
모든 컴포넌트의 그리는 사각형이 바뀌었음을 알린다. (원본 Component.markAllDrawnRectsDirty, 글꼴을 새로 읽어 글 너비가 바뀔 때 같은)
- 세대를 하나 올려 모든 노드가 다음에 경계를 읽을 때 다시 셈하게 한다.
Tells that the drawn rects of all components changed. (original Component.markAllDrawnRectsDirty, e.g. when a newly loaded font changes text widths)
- Raises the generation by one so every node recomputes its bounds the next time they are read.
짝Counterpart: vanilla.js Component.markAllDrawnRectsDirty
use vanilla::ComponentBase;
let generation = ComponentBase::get_drawn_rect_generation();
ComponentBase::mark_all_drawn_rects_dirty();
assert!(ComponentBase::get_drawn_rect_generation() > generation);컴포넌트 그리는 사각형 세대. (원본 Component.getDrawnRectGeneration, mark_all_drawn_rects_dirty 마다 하나 오른다)
Component drawn rect generation. (original Component.getDrawnRectGeneration, goes up by one on every mark_all_drawn_rects_dirty)
반환Returnsu64 지금 세대. (1 부터)Current generation. (from 1)
짝Counterpart: vanilla.js Component.getDrawnRectGeneration
활성화 설정.
Sets active.
- is_enablebool
- 켤지. (false 면 tick, 그리기, 터치, 휠에서 빠진다)Whether to enable. (if false, it is skipped in tick, drawing, touch and wheel)
짝Counterpart: vanilla.js Component.setEnable
활성화 여부.
Whether enabled.
반환Returnsbool 켜져 있으면 true.true if enabled.
짝Counterpart: vanilla.js Component.isEnable
기즈모 표시 설정.
Sets gizmo drawing.
- is_gizmo_visiblebool
- 노드의 기즈모를 그릴 때 이 컴포넌트의 draw_gizmos 도 부를지.Whether to also call this component's draw_gizmos when drawing the node's gizmos.
짝Counterpart: vanilla.js Component.setGizmoVisible
기즈모 표시 여부.
Whether gizmos are drawn.
반환Returnsbool 기즈모를 그리면 true.true if gizmos are drawn.
짝Counterpart: vanilla.js Component.isGizmoVisible
그리는 사각형(Component::calculate_drawn_rect)이 바뀌었음을 노드에 알린다. (원본 Component.markDrawnRectDirty)
- 붙은 노드와 조상이 다음 그리기 전에 하위 트리 그리기 경계를 다시 셈한다. 노드에 붙지 않았으면 할 일이 없다.
- 그리는 사각형을 바꾸는 세터마다 부른다. (부르지 않으면 넓어진 그림이 화면에 들어와도 하위 트리째 건너뛰어 안 그려질 수 있다)
Tells the node that the drawn rect (Component::calculate_drawn_rect) changed. (original Component.markDrawnRectDirty)
- The attached node and its ancestors recompute their subtree draw bounds before the next draw. Does nothing if not attached to a node.
- Call it from every setter that changes the drawn rect. (Without it, a drawing that grew into the screen may still be skipped with its subtree and not drawn)
짝Counterpart: vanilla.js Component.markDrawnRectDirty
use vanilla::ComponentBase;
let component_base = ComponentBase::new();
component_base.mark_drawn_rect_dirty();Componenttrait traits AsAny, Reflect
컴포넌트 트레이트.
- 원본은 모든 객체가 반사된다. 러스트 판은 반사(Reflect)를 상위 트레이트로 두어 반사 없는 컴포넌트가 생길 수 없다. 컴포넌트를 만드는 길은
#[vanilla::reflect]하나다. 타입의 impl 블록과 이 트레이트의 impl 블록 둘 다에 붙인다. 게터가 없는 타입은 빈 블록#[vanilla::reflect] impl 타입 {}에 붙인다. 빠뜨리면 컴파일 에러가 붙일 자리를 알려 준다. - UI 문서 저장과 DevTools 인스펙터는
&dyn Component를&dyn Reflect로 올려(트레이트 업캐스팅) 원본처럼 모든 컴포넌트의 속성을 다룬다.
Component trait.
- In the original every object is reflected. The Rust edition makes reflection (Reflect) a supertrait, so a component without reflection cannot exist. The one way to make a component is
#[vanilla::reflect]. Put it on both the type's impl block and the impl block of this trait. A type without getters takes it on an empty block,#[vanilla::reflect] impl Type {}. If it is left out, a compile error points at where to add it. - UI document saving and the DevTools inspector upcast
&dyn Componentto&dyn Reflect(trait upcasting) and handle the properties of every component like the original.
use vanilla::{reflect, Component, ComponentBase, ComponentContext, Engine, EngineConfiguration, NodeTree};
struct Spin {
component_base: ComponentBase,
degrees_per_second: f64,
}
#[reflect]
impl Spin {
pub fn get_degrees_per_second(&self) -> f64 {
self.degrees_per_second
}
pub fn set_degrees_per_second(&mut self, degrees_per_second: f64) {
self.degrees_per_second = degrees_per_second;
}
}
#[reflect]
impl Component for Spin {
fn get_component_base(&self) -> &ComponentBase {
&self.component_base
}
fn get_component_base_mut(&mut self) -> &mut ComponentBase {
&mut self.component_base
}
fn get_component_type(&self) -> &'static str {
"Spin"
}
fn tick(&mut self, context: &mut ComponentContext, time_delta: f64) {
let transform = context.get_transform_mut();
let local_rotation = transform.get_local_rotation();
transform.set_local_rotation(local_rotation + self.degrees_per_second * time_delta);
}
}
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let node_id = node_tree.create_child(root_id, "spinner");
node_tree[node_id].add_component(Spin {
component_base: ComponentBase::new(),
degrees_per_second: 90.0,
});
node_tree.tick(&engine, 0.5);
assert_eq!(node_tree[node_id].get_local_rotation(), 45.0);공통 상태 반환.
Returns the common state.
반환Returns&ComponentBase 구현체가 든 ComponentBase.The ComponentBase held by the implementor.
공통 상태 반환. (변경용)
Returns the common state. (mutable)
반환Returns&mut ComponentBase 구현체가 든 ComponentBase. (변경용)The ComponentBase held by the implementor. (mutable)
컴포넌트 이름. (원본 getComponentType)
Component name. (the original getComponentType)
반환Returns&'static str 종류 이름. (보통 구조체 이름 그대로, 반사의 ComponentType 값)Type name. (usually the struct name as is, the ComponentType value in reflection)
짝Counterpart: vanilla.js Component.getComponentType
노드에 붙을 때. (WorldNode::add_component 와 NodeTree::add_component 둘 다 부른다)
When attached to a node. (called by both WorldNode::add_component and NodeTree::add_component)
- _transform&mut NodeTransform
- 붙는 노드의 트랜스폼. (여기서 바꿔도 된다)Transform of the node it attaches to. (may be changed here)
짝Counterpart: vanilla.js Component.attach
노드에서 떨어질 때. (WorldNode::remove_component 가 부른다)
When detached from a node. (called by WorldNode::remove_component)
- _transform&mut NodeTransform
- 떨어지는 노드의 트랜스폼.Transform of the node it detaches from.
짝Counterpart: vanilla.js Component.detach
의존 컴포넌트 목록. (붙기 전에 같은 노드에 없으면 만들어 붙인다, 원본 Unity RequireComponent 사상)
List of dependent components. (created and attached before attaching if the same node lacks them, the original's Unity RequireComponent idea)
반환ReturnsVec<RequiredComponent> 의존 컴포넌트 목록. (기본은 빈 목록)List of dependent components. (empty list by default)
짝Counterpart: vanilla.js Component.require
트리 안의 노드에 붙을 때. (NodeTree::add_component 만 부른다. 자식 노드를 만드는 컴포넌트는 여기서 만든다)
- 원본 UIView.attach 가 content 노드를 만들어 붙이는 자리. 이런 컴포넌트는 node_tree.add_component 로 붙인다.
When attached to a node inside the tree. (called only by NodeTree::add_component. Components that create child nodes create them here)
- Where the original UIView.attach creates and attaches the content node. Such components are attached with node_tree.add_component.
- _node_tree&mut NodeTree
- 노드가 든 트리. (이 컴포넌트는 그동안 노드에서 빠져 있고 자리표가 대신 든다)The tree holding the node. (meanwhile this component is taken out of the node and a placeholder holds its place)
- _node_idNodeId
- 이 컴포넌트가 붙는 노드.The node this component attaches to.
use vanilla::{Component, ComponentBase, NodeId, NodeTree};
struct Badge {
component_base: ComponentBase,
label_id: Option<NodeId>,
}
#[vanilla::reflect]
impl Badge {}
#[vanilla::reflect]
impl Component for Badge {
fn get_component_base(&self) -> &ComponentBase {
&self.component_base
}
fn get_component_base_mut(&mut self) -> &mut ComponentBase {
&mut self.component_base
}
fn get_component_type(&self) -> &'static str {
"Badge"
}
fn attach_to_tree(&mut self, node_tree: &mut NodeTree, node_id: NodeId) {
self.label_id = Some(node_tree.create_child(node_id, "label"));
}
}
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let node_id = node_tree.create_child(root_id, "badge");
let badge = node_tree.add_component(node_id, Badge {
component_base: ComponentBase::new(),
label_id: None,
}).expect("badge");
let label_id = badge.label_id.expect("label");
assert_eq!(node_tree.get_parent_id(label_id), Some(node_id));주기적 갱신.
- 노드와 조상이 모두 활성이고 이 컴포넌트가 켜져 있고 is_tick_needed 가 true 일 때 NodeTree::tick 이 부른다.
Periodic update.
- Called by NodeTree::tick when the node and all its ancestors are active, this component is enabled, and is_tick_needed is true.
- _context&mut ComponentContext
- 자기 노드, 트리 전체, 엔진을 꺼내는 문맥.Context to take out its own node, the whole tree and the engine.
- _time_deltaf64
- 지난 tick 뒤로 흐른 시간. (초)Time elapsed since the last tick. (seconds)
짝Counterpart: vanilla.js Component.tick
tick 이 할 일이 있는지. (false 면 노드를 돌 때 이 컴포넌트를 부르지 않는다. 기본 true)
- 그리기만 하는 Paint, Sprite, Text, Mask 는 false. 컴포넌트가 이것만 붙은 노드는 tick 때 꺼내지 않는다.
Whether tick has work to do. (if false, this component is not called when visiting nodes. Default true)
- false for Paint, Sprite, Text and Mask, which only draw. A node with only such components is not taken out on tick.
반환Returnsbool tick 을 불러야 하면 true.true if tick needs to be called.
짝Counterpart: vanilla.js Component.isTickNeeded
노드 출력 상태 시작. (노드 트랜스폼을 건 바로 뒤, 이 노드의 컴포넌트와 자식을 그리기 전. 원본 노드의 pushTransform 을 덮어쓰던 자리)
- 여기서 바꾼 Graphic 상태는 이 노드와 자손 모두에 걸린다. pop_transform 에서 되돌린다. 켜진 컴포넌트만, 붙인 차례로 부른다.
Begins the node drawing state. (right after the node transform is applied, before drawing this node's components and children. Where the original overrode the node's pushTransform)
- Graphic state changed here applies to this node and all its descendants. It is restored in pop_transform. Called only for enabled components, in attach order.
- _transform&NodeTransform
- 이 노드의 트랜스폼.This node's transform.
- _graphic&mut Graphic
- 그리는 Graphic. (노드 트랜스폼과 불투명도가 걸려 있다)The Graphic being drawn to. (the node transform and opacity are applied)
use vanilla::{Component, ComponentBase, Graphic, NodeTransform};
struct HalfFade {
component_base: ComponentBase,
saved_alpha: f64,
}
#[vanilla::reflect]
impl HalfFade {}
#[vanilla::reflect]
impl Component for HalfFade {
fn get_component_base(&self) -> &ComponentBase {
&self.component_base
}
fn get_component_base_mut(&mut self) -> &mut ComponentBase {
&mut self.component_base
}
fn get_component_type(&self) -> &'static str {
"HalfFade"
}
fn push_transform(&mut self, _transform: &NodeTransform, graphic: &mut Graphic) {
self.saved_alpha = graphic.get_global_alpha();
graphic.multiply_global_alpha(0.5);
}
fn pop_transform(&mut self, _transform: &NodeTransform, graphic: &mut Graphic) {
graphic.set_global_alpha(self.saved_alpha);
}
}노드 출력 상태 끝. (자식과 기즈모를 다 그린 뒤, 노드 트랜스폼을 풀기 전. 원본 노드의 popTransform 을 덮어쓰던 자리, 붙인 차례의 거꾸로 부른다)
Ends the node drawing state. (after drawing all children and gizmos, before releasing the node transform. Where the original overrode the node's popTransform, called in reverse attach order)
- _transform&NodeTransform
- 이 노드의 트랜스폼.This node's transform.
- _graphic&mut Graphic
- 그리는 Graphic. (push_transform 에서 바꾼 상태를 여기서 되돌린다)The Graphic being drawn to. (the state changed in push_transform is restored here)
출력. (노드 트랜스폼이 걸린 상태에서 불린다. 원점은 노드 content_size 영역의 왼쪽 위)
Draw. (called with the node transform applied. The origin is the top left of the node's content_size area)
- _transform&NodeTransform
- 이 노드의 트랜스폼. (content_size 로 그릴 크기를 정한다)This node's transform. (content_size decides the size to draw)
- _graphic&mut Graphic
- 그릴 Graphic.Graphic to draw to.
짝Counterpart: vanilla.js Component.draw
fn write_geometry_key(&self, _transform: &NodeTransform, _geometry_key: &mut GeometryKey) -> bool#그리기 입력을 기하 캐시 열쇠에 적기. (Graphic::draw_component 가 draw 앞에 부른다, 원본 writeGeometryKey)
- true 를 돌려주는 컴포넌트만 Graphic 이 그린 정점을 캐시해, 적은 입력과 변환이 그대로면 draw 를 부르지 않는다.
- draw 가 읽는 값(색, 크기, 글, 그림 등)을 모두 적어야 한다. 하나라도 빠지면 바뀐 것을 놓친다. (기본 false, 캐시하지 않음)
Writes the drawing inputs into the geometry cache key. (Graphic::draw_component calls it before draw, original writeGeometryKey)
- Only a component that returns true has the vertices Graphic drew cached; if the written inputs and the transform are unchanged, draw is not called.
- Every value draw reads (color, size, text, image and so on) must be written. If one is missing, a change is missed. (Default false, not cached)
- _transform&NodeTransform
- 이 노드의 트랜스폼. (content_size 를 읽는다)The transform of this node. (content_size is read)
- _geometry_key&mut GeometryKey
- 적을 열쇠.The key to write into.
반환Returnsbool 입력을 다 적었으면 true.true if all inputs were written.
짝Counterpart: vanilla.js Component.writeGeometryKey
use vanilla::{Color, Component, ComponentBase, GeometryKey, Graphic, NodeTransform, Rect};
#[derive(Default)]
struct Box2D {
component_base: ComponentBase,
color: Color,
}
#[vanilla::reflect]
impl Box2D {}
#[vanilla::reflect]
impl Component for Box2D {
fn get_component_base(&self) -> &ComponentBase {
&self.component_base
}
fn get_component_base_mut(&mut self) -> &mut ComponentBase {
&mut self.component_base
}
fn get_component_type(&self) -> &'static str {
"Box2D"
}
fn write_geometry_key(&self, transform: &NodeTransform, geometry_key: &mut GeometryKey) -> bool {
geometry_key.add(self.color);
geometry_key.add(transform.get_content_size());
true
}
fn draw(&mut self, transform: &NodeTransform, graphic: &mut Graphic) {
let content_size = transform.get_content_size();
graphic.set_fill_color(self.color);
graphic.draw_rect(Rect::create(0.0, 0.0, content_size.x, content_size.y));
}
}
let box_2d = Box2D::default();
let mut geometry_key = GeometryKey::new();
geometry_key.begin();
println!("{} {}", box_2d.write_geometry_key(&NodeTransform::default(), &mut geometry_key), geometry_key.end());기즈모 출력.
- 노드의 기즈모를 그리는 때(노드의 기즈모 표시나 Graphic 의 기즈모 강제 표시)에 이 컴포넌트의 기즈모 표시가 켜져 있으면 불린다.
Draws gizmos.
- Called when the node's gizmos are drawn (the node's gizmo display or the Graphic's forced gizmo display) and this component's gizmo display is on.
- _transform&NodeTransform
- 이 노드의 트랜스폼.This node's transform.
- _graphic&mut Graphic
- 그릴 Graphic. (노드 트랜스폼이 걸려 있다)Graphic to draw to. (the node transform is applied)
짝Counterpart: vanilla.js Component.drawGizmos
자식 출력을 이 영역으로 자를지. (Mask 만 Some(둥근 크기) 를 돌려준다)
Whether to clip child drawing to this area. (only Mask returns Some(round size))
반환ReturnsOption<f64> 자를 영역의 귀퉁이 둥근 크기. (노드 좌표, 0 이면 곧은 사각형) 자르지 않으면 None.Corner round size of the clip area. (node coordinates, 0 is a sharp rectangle) None if not clipping.
노드 content_size 영역 안에만 그리는지. (true 면 영역이 화면 밖일 때 엔진이 draw 를 건너뛴다)
- Paint, Sprite, Mask 는 true. 글자, 파티클처럼 영역 밖으로 나가는 것은 false. (기본 false)
Whether it draws only inside the node's content_size area. (if true, the engine skips draw when the area is off screen)
- true for Paint, Sprite and Mask. false for things that go outside the area, such as text and particles. (default false)
반환Returnsbool content_size 영역 안에만 그리면 true.true if it draws only inside the content_size area.
짝Counterpart: vanilla.js Component.isDrawnInsideContent
draw 를 덮어썼는지. (원본은 component.draw 가 Component.prototype.draw 와 다른지로 본다)
- false 면 아무것도 그리지 않는 컴포넌트라 화면 밖 거르기와 하위 트리 그리기 경계에서 빠진다. (ButtonMotion, UINode 같은)
- #[reflect] 를 붙인 impl Component 블록에 fn draw 가 없으면 매크로가 false 를 돌려주게 짓는다. 매크로 없이 쓰면 기본 true. (어디에 그리는지 모르는 것으로 본다)
Whether draw is overridden. (the original checks whether component.draw differs from Component.prototype.draw)
- false means a component that draws nothing, so it is left out of off-screen culling and subtree draw bounds. (like ButtonMotion, UINode)
- When an impl Component block with #[reflect] has no fn draw, the macro generates a version that returns false. Without the macro the default is true. (treated as drawing somewhere unknown)
반환Returnsbool draw 를 덮어썼으면 true.true if draw is overridden.
그리는 사각형(calculate_drawn_rect)이 바뀌었음을 노드에 알린다. (원본 Component.markDrawnRectDirty, ComponentBase::mark_drawn_rect_dirty)
Tells the node that the drawn rect (calculate_drawn_rect) changed. (original Component.markDrawnRectDirty, ComponentBase::mark_drawn_rect_dirty)
짝Counterpart: vanilla.js Component.markDrawnRectDirty
fn calculate_drawn_rect(&mut self, transform: &NodeTransform, _graphic: &mut Graphic) -> Option<Rect>#화면 밖 거르기에 쓰는, 실제로 그리는 사각형. (노드의 content 좌표, draw 와 같은 Graphic 변환이 걸린 때 부른다)
- None 이면 모른다는 뜻이라 노드를 거르지 않는다. 노드의 켜진 컴포넌트가 모두 사각형을 주면 그 합이 화면 밖일 때 거른다.
- 기본은 is_drawn_inside_content 가 true 이고 content_size 가 있으면 content 영역, 아니면 None.
- 글자처럼 정렬, 넘침, 줄바꿈으로 content 밖에도 그리는 컴포넌트는 그리는 사각형을 넉넉히 셈해 돌려준다.
The rectangle actually drawn, used for off-screen culling. (the node's content coordinates, called with the same Graphic transform as draw)
- None means unknown, so the node is not culled. If all of the node's enabled components give a rectangle, the node is culled when their union is off screen.
- By default, the content area if is_drawn_inside_content is true and there is a content_size, otherwise None.
- Components that also draw outside content due to alignment, overflow or wrapping, such as text, compute and return a generous drawn rectangle.
- transform&NodeTransform
- 이 노드의 트랜스폼.This node's transform.
- _graphic&mut Graphic
- 그리는 Graphic. (draw 와 같은 변환이 걸려 있다, Text 는 글 크기를 잴 때 쓴다)Graphic used for drawing. (has the same transform applied as draw, Text uses it to measure text size)
반환ReturnsOption<Rect> 그리는 사각형. (노드의 content 좌표, 왼쪽 위가 원점) 모르면 None.The drawn rectangle. (the node's content coordinates, top left is the origin) None if unknown.
짝Counterpart: vanilla.js Component.calculateDrawnRect
터치 눌림. (노드가 interactable 이고 맨 위에 있을 때)
Touch press. (when the node is interactable and on top)
- _context&mut ComponentContext
- 자기 노드, 트리 전체, 엔진을 꺼내는 문맥.Context to take out its own node, the whole tree and the engine.
- _view_input_positionVector2
- 터치 자리. (뷰 좌표)Touch position. (view coordinates)
터치 이동. (눌린 노드에)
Touch move. (to the pressed node)
- _context&mut ComponentContext
- 자기 노드, 트리 전체, 엔진을 꺼내는 문맥.Context to take out its own node, the whole tree and the engine.
- _view_input_positionVector2
- 터치 자리. (뷰 좌표)Touch position. (view coordinates)
fn touch_release(&mut self, _context: &mut ComponentContext, _view_input_position: Vector2)#터치 뗌. (눌린 노드에)
Touch release. (to the pressed node)
- _context&mut ComponentContext
- 자기 노드, 트리 전체, 엔진을 꺼내는 문맥.Context to take out its own node, the whole tree and the engine.
- _view_input_positionVector2
- 터치 자리. (뷰 좌표)Touch position. (view coordinates)
fn touch_cancel(&mut self, _context: &mut ComponentContext, _view_input_position: Vector2)#터치 취소. (눌린 노드에)
Touch cancel. (to the pressed node)
- _context&mut ComponentContext
- 자기 노드, 트리 전체, 엔진을 꺼내는 문맥.Context to take out its own node, the whole tree and the engine.
- _view_input_positionVector2
- 터치 자리. (뷰 좌표)Touch position. (view coordinates)
마우스 휠. (터치 아래 노드부터 부모 쪽으로 올라가며 묻는다. 받아 썼으면 true, 원본 UIScrollView.wheel)
Mouse wheel. (asked from the node under the touch up toward its parents. true if consumed, the original UIScrollView.wheel)
- _context&mut ComponentContext
- 자기 노드, 트리 전체, 엔진을 꺼내는 문맥.Context to take out its own node, the whole tree and the engine.
- _wheel_deltaVector2
- 이번 프레임의 휠 이동량. (픽셀, 내용을 아래로 넘기면 y 가 양수)Wheel movement this frame. (pixels, y is positive when scrolling the content down)
반환Returnsbool 받아 썼으면 true. (부모 쪽으로 더 묻지 않는다)true if consumed. (stops asking further up the parents)
휠을 받는 칸인지. (스크롤 칸이 true. 그 자리를 덮는 것 가운데 가장 앞이 이 컴포넌트의 노드면 누를 수 없는 것 위의 휠도 받는다, NodeTree::dispatch_wheel_at)
Whether it is a view that receives the wheel. (true for scroll views. If the frontmost of the things covering that position is this component's node, it also receives the wheel over non-pressable things, NodeTree::dispatch_wheel_at)
반환Returnsbool 휠을 받는 칸이면 true.true if it is a view that receives the wheel.
자연 크기. (UIKit 의 intrinsicContentSize, UINode 가 모은다. 축마다 -1 이면 선호 없음, 기본은 둘 다 -1)
- 원본은 이 함수가 있는 컴포넌트(Text, RichText)만 UINode 가 읽는다. 러스트 판은 기본값 -1 이 "없음" 자리다.
Intrinsic size. (UIKit's intrinsicContentSize, gathered by UINode. -1 on an axis means no preference, both -1 by default)
- In the original, UINode reads it only from components that have this function (Text, RichText). In the Rust version the default -1 stands for "none".
반환ReturnsVector2 자연 크기. (축마다 -1 이면 그 축은 선호 없음)Intrinsic size. (-1 on an axis means no preference on that axis)
품은 기반 컴포넌트. (원본 상위 클래스 자리, ShaderSprite 의 Sprite 나 UIButton 의 UIControl 처럼)
- get_component, get_components, has_component, remove_component 가 이 사슬을 따라 원본 instanceof 처럼 기반 타입으로도 찾는다.
- 다른 컴포넌트를 품어 원본 상속을 옮긴 컴포넌트만 덮어쓴다.
The embedded base component. (in place of the original superclass, like the Sprite of ShaderSprite or the UIControl of UIButton)
- get_component, get_components, has_component and remove_component follow this chain and also find base types, like the original instanceof.
- Only components that embed another component to port the original inheritance override it.
반환ReturnsOption<&dyn Component> 품은 기반 컴포넌트. 기반이 없으면 None. (기본)The embedded base component. None if there is no base. (default)
품은 기반 컴포넌트. (변경용)
The embedded base component. (mutable)
반환ReturnsOption<&mut dyn Component> 품은 기반 컴포넌트. (변경용) 기반이 없으면 None. (기본)The embedded base component. (mutable) None if there is no base. (default)
활성화 여부.
Whether enabled.
반환Returnsbool 켜져 있으면 true. (ComponentBase 의 값)true if enabled. (the ComponentBase value)
짝Counterpart: vanilla.js Component.isEnable
활성화 설정.
Sets active.
- is_enablebool
- 켤지. (false 면 tick, 그리기, 터치, 휠에서 빠진다)Whether to enable. (if false, it is skipped in tick, drawing, touch and wheel)
짝Counterpart: vanilla.js Component.setEnable
기즈모 표시 여부.
Whether gizmos are drawn.
반환Returnsbool 기즈모를 그리면 true. (ComponentBase 의 값)true if gizmos are drawn. (the ComponentBase value)
짝Counterpart: vanilla.js Component.isGizmoVisible
기즈모 표시 설정.
Sets gizmo drawing.
- is_gizmo_visiblebool
- 노드의 기즈모를 그릴 때 이 컴포넌트의 draw_gizmos 도 부를지.Whether to also call this component's draw_gizmos when drawing the node's gizmos.
짝Counterpart: vanilla.js Component.setGizmoVisible