# core/node/worldnode (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/node/worldnode/

World node.
- Parent/child hierarchy + activation (the original Node)
- Holds components + tick (the original ComponentNode)
- Local TRS + recursive rendering (the original TransformNode)
- pivot / anchor / content_size + touch (the original WorldNode)
- Nodes live in the scene's NodeTree storage, and parents and children are linked by handles (NodeId).
  Changing the tree (attaching children, removing, finding) and iterating the tree (tick, draw, touch) are done by NodeTree.

## NodeTransform (struct) (Clone, Debug, Default)

Node transform. (node state that components read and change on tick / draw)
- local_position is the coordinate of its own pivot point within the parent area. (anchor is for computing anchored_position)
- local_rotation is in degrees. (same as the original)

Example: Place a center-pivot node on a rectangle and check its bounds

```rust
use vanilla::{NodeTransform, Pivot, Rect, Vector2};

let mut transform = NodeTransform::new();
transform.set_pivot(Pivot::MIDDLE_CENTER);
transform.set_rect(10.0, 20.0, 100.0, 50.0);
assert_eq!(transform.get_local_position(), Vector2::create(60.0, 45.0));
assert_eq!(transform.get_local_bounds(), Rect::create(10.0, 20.0, 100.0, 50.0));
transform.set_local_scale(Vector2::create(2.0, 2.0));
assert_eq!(transform.get_local_bounds(), Rect::create(-40.0, -5.0, 200.0, 100.0));
```

- `pub fn new() -> NodeTransform` (constructor, since 0.3.2): Constructor.
  - returns NodeTransform: Position (0, 0), scale 1, rotation 0, opacity 1, content size 0, pivot and anchor at the center, a visible transform.
- `pub fn set_local_position(&mut self, local_position: Vector2)` (method, since 0.3.2): Sets the local position.
  - `local_position` Vector2: Position of the pivot point measured from the top-left of the parent's content area.
- `pub fn get_local_position(&self) -> Vector2` (method, since 0.3.2): Returns the local position.
  - returns Vector2: Local position. (position of the pivot point measured from the top-left of the parent's content area)
- `pub fn set_local_scale(&mut self, local_scale: Vector2)` (method, since 0.3.2): Sets the local scale.
  - `local_scale` Vector2: Scale per axis. (1 is the original size, negative draws it flipped on that axis)
- `pub fn get_local_scale(&self) -> Vector2` (method, since 0.3.2): Returns the local scale.
  - returns Vector2: Local scale.
- `pub fn set_local_rotation(&mut self, local_rotation: f64)` (method, since 0.3.2): Sets the local rotation. (degrees)
  - `local_rotation` f64: Rotation. (degrees, positive is clockwise on screen)
- `pub fn get_local_rotation(&self) -> f64` (method, since 0.3.2): Returns the local rotation. (degrees)
  - returns f64: Local rotation. (degrees)
- `pub fn set_local_opacity(&mut self, local_opacity: f64)` (method, since 0.3.2): Sets the local opacity. (multiplied down into the children)
  - `local_opacity` f64: Opacity. (0 ~ 1, values outside are clamped)
- `pub fn get_local_opacity(&self) -> f64` (method, since 0.3.2): Returns the local alpha.
  - returns f64: Local opacity. (0 ~ 1)
- `pub fn set_pivot(&mut self, pivot: Vector2)` (method, since 0.3.2): Sets the pivot. (ratio of the reference point within content_size, default center)
  - `pivot` Vector2: Ratio of the reference point within the content size. ((0, 0) top-left, (1, 1) bottom-right, Pivot constants)
- `pub fn get_pivot(&self) -> Vector2` (method, since 0.3.2): Returns the pivot.
  - returns Vector2: Pivot. (ratio within the content size)
- `pub fn set_content_size(&mut self, content_size: Vector2)` (method, since 0.3.2): Sets the content size.
  - `content_size` Vector2: Content size. (node coordinates, before scale is applied)
- `pub fn get_content_size(&self) -> Vector2` (method, since 0.3.2): Returns the content size.
  - returns Vector2: Content size. (node coordinates, before scale is applied)
- `pub fn set_local_position_xy(&mut self, x: f64, y: f64)` (method, since 0.4.0): Sets the local position. (takes x, y directly, the original setLocalPositionXY)
  - `x` f64: Local position x.
  - `y` f64: Local position y.
- `pub fn set_local_scale_xy(&mut self, x: f64, y: f64)` (method, since 0.4.0): Sets the local scale. (takes x, y directly, the original setLocalScaleXY)
  - `x` f64: Horizontal scale.
  - `y` f64: Vertical scale.
- `pub fn set_content_size_xy(&mut self, width: f64, height: f64)` (method, since 0.4.0): Sets the content size. (takes width, height directly, the original setContentSizeXY)
  - `width` f64: Content width.
  - `height` f64: Content height.
- `pub fn set_rect(&mut self, x: f64, y: f64, width: f64, height: f64)` (method, since 0.4.0): Places it on a rectangle within the parent area. (x, y is this node's top-left, origin at the top-left of the parent's content area, the original setRect)
  - Sets the content size to width, height and sets the local position so the top-left lands on (x, y) wherever the pivot is. (x + width * pivot.x, y + height * pivot.y)
  - Does not change the anchor. The local position is relative to the parent's top-left regardless of the anchor, so it is the same place wherever the anchor is.
  - Ignores the local scale and rotation. (with scale 1 and rotation 0 it is that rectangle on screen too)
  - `x` f64: Top-left x. (relative to the top-left of the parent's content area)
  - `y` f64: Top-left y. (relative to the top-left of the parent's content area)
  - `width` f64: Content width.
  - `height` f64: Content height.
- `pub fn set_anchor(&mut self, anchor: Vector2)` (method, since 0.3.2): Sets the anchor. (ratio within the parent's content_size)
  - `anchor` Vector2: Ratio within the parent's content size. (reference point of anchored_position, Pivot constants)
- `pub fn get_anchor(&self) -> Vector2` (method, since 0.3.2): Returns the anchor.
  - returns Vector2: Anchor. (ratio within the parent's content size)
- `pub fn set_anchored_position(&mut self, anchored_position: Vector2, parent_content_size: Vector2)` (method, since 0.3.2): Sets the anchor-relative position. (needs the parent's content_size)
  - Sets the local position to (parent content size x anchor) + anchored_position.
  - `anchored_position` Vector2: Position measured from the anchor point.
  - `parent_content_size` Vector2: The parent's content size.

  Example: Place it 20 inward from the parent's bottom-right

  ```rust
  use vanilla::{NodeTransform, Pivot, Vector2};
  
  let mut transform = NodeTransform::new();
  transform.set_anchor(Pivot::BOTTOM_RIGHT);
  let parent_content_size = Vector2::create(800.0, 600.0);
  transform.set_anchored_position(Vector2::create(-20.0, -20.0), parent_content_size);
  assert_eq!(transform.get_local_position(), Vector2::create(780.0, 580.0));
  assert_eq!(transform.get_anchored_position(parent_content_size), Vector2::create(-20.0, -20.0));
  ```

- `pub fn get_anchored_position(&self, parent_content_size: Vector2) -> Vector2` (method, since 0.3.2): Returns the anchor-relative position.
  - `parent_content_size` Vector2: The parent's content size.
  - returns Vector2: Local position measured from the anchor point (parent content size x anchor).
- `pub fn set_visible(&mut self, is_visible: bool)` (method, since 0.3.2): Sets visibility. (tick still runs when off. The original isVisible)
  - `is_visible` bool: Whether to draw. (if false, this node and its descendants are not drawn and receive no touches)
- `pub fn is_visible(&self) -> bool` (method, since 0.3.2): Whether visible.
  - returns bool: True if visible.
- `pub fn calculate_local_matrix(&self) -> TransformMatrix` (method, since 0.3.2): Local transform matrix. (same order as push_transform: translate → rotate → scale → pivot correction)
  - returns TransformMatrix: Matrix that maps a point in this node's content coordinates to the parent's content coordinates.
- `pub fn get_local_bounds(&self) -> Rect` (method, since 0.3.2): Bounding rectangle seen from the parent area. (exact when there is no rotation. For collision tests and such)
  - returns Rect: Bounding rectangle in the parent's content coordinates. (scale is applied as an absolute value and rotation is not included)

## WorldNode (struct)

World node.
- Holds the name, active state, touch receiving, transform, component list, and parent and child handles.

Example: Add and find components on a node

```rust
use vanilla::{Color, Paint, Vector2, WorldNode};

let mut node = WorldNode::new("card");
node.set_content_size(Vector2::create(120.0, 80.0));
node.add_component(Paint::create_with_color(Color::white()));
assert_eq!(node.get_name(), "card");
assert!(node.has_component::<Paint>());
assert_eq!(node.get_component::<Paint>().expect("paint").get_color(), Color::white());
assert!(node.is_root());
```

- `pub fn new(name: &str) -> WorldNode` (constructor, since 0.3.2): Creates. (use NodeTree::create_node to put it in a tree)
  - `name` &str: Node name. (used for finding by name)
  - returns WorldNode: A new active node with no parent. (does not receive touches)
- `pub fn get_instance_id(&self) -> u64` (method, since 0.3.2): Instance identifier.
  - returns u64: Number assigned at creation. (from 1, unique per node)
- `pub fn set_name(&mut self, name: &str)` (method, since 0.3.2): Sets the name.
  - `name` &str: New name.
- `pub fn get_name(&self) -> &str` (method, since 0.3.2): Returns the name.
  - returns &str: Node name.
- `pub fn get_parent_id(&self) -> Option<NodeId>` (method, since 0.3.2): Parent handle. (None if it is the root or not attached yet)
  - returns Option<NodeId>: Parent handle. None if it is the root or not attached yet.
- `pub fn get_child_ids(&self) -> &[NodeId]` (method, since 0.3.2): Child handle list. (draw order)
  - returns &[NodeId]: Child handle list. (earlier is drawn first)
- `pub fn get_child_count(&self) -> usize` (method, since 0.3.2): Child count.
  - returns usize: Number of direct children.
- `pub fn is_root(&self) -> bool` (method, since 0.4.0): Whether it has no parent. (the original isRoot, the tree's root and nodes not attached yet)
  - returns bool: True if it has no parent.
- `pub fn is_leaf(&self) -> bool` (method, since 0.4.0): Whether it has no children. (the original isLeaf)
  - returns bool: True if it has no children.
- `pub fn has_parent(&self) -> bool` (method, since 0.4.0): Whether it has a parent. (the original hasParent)
  - returns bool: True if it has a parent.
- `pub fn get_child(&self, child_index: usize) -> Option<NodeId>` (method, since 0.4.0): The child at that position. (None if out of range, the original getChild's null)
  - `child_index` usize: Child position. (from 0, draw order)
  - returns Option<NodeId>: Child handle at that position. None if out of range.
- `pub fn has_child(&self, child_id: NodeId) -> bool` (method, since 0.4.0): Whether that node is a child. (the original hasChild)
  - `child_id` NodeId: Node to find.
  - returns bool: True if it is a direct child.
- `pub fn get_child_index(&self, child_id: NodeId) -> Option<usize>` (method, since 0.4.0): Position of the child. (index in draw order, None if not a child. The original getChildIndex's -1)
  - `child_id` NodeId: Child to find.
  - returns Option<usize>: Index in draw order. (from 0) None if not a direct child.
- `pub fn set_active(&mut self, is_active: bool)` (method, since 0.3.2): Sets active. (when off, neither tick nor draw runs)
  - `is_active` bool: Whether to turn it on. (if false, this node and its descendants are left out of tick, drawing and touch)
- `pub fn is_active(&self) -> bool` (method, since 0.3.2): Whether enabled.
  - returns bool: Own active flag. (use NodeTree::is_active_in_hierarchy to include ancestors)
- `pub fn set_interactable(&mut self, is_interactable: bool)` (method, since 0.3.2): Sets whether to receive touches.
  - `is_interactable` bool: Whether to receive touches. (default false)
- `pub fn is_interactable(&self) -> bool` (method, since 0.3.2): Whether it receives touches.
  - returns bool: True if it receives touches.
- `pub fn set_gizmo_visible(&mut self, is_gizmo_visible: bool)` (method, since 0.3.2): Sets gizmo drawing.
  - `is_gizmo_visible` bool: Whether to draw the gizmo (content border and pivot point).
- `pub fn is_gizmo_visible(&self) -> bool` (method, since 0.3.2): Whether gizmos are drawn.
  - returns bool: true if gizmos are drawn.
- `pub fn set_opacity_layer(&mut self, is_opacity_layer: bool)` (method, since 0.4.0): Sets the opacity layer. (Whether to group the opacity over the node and its descendants and lay it down at once, like CSS opacity)
  - When on and the opacity (multiplied by the parent's) is below 1, NodeTree draws this node and its descendants into a layer and lays it down at once with that opacity. (Graphic::begin_opacity_layer)
    Overlapping children do not show through each other. When off (the default), opacity is multiplied per node and each is laid down separately.
  - `is_opacity_layer` bool: Whether to lay the opacity down as a group.

  Example: A translucent group node (overlapping children do not show through each other)

  ```rust
  use vanilla::NodeTree;
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let group_id = node_tree.create_child(root_id, "group");
  node_tree[group_id].set_local_opacity(0.5);
  node_tree[group_id].set_opacity_layer(true);
  assert!(node_tree[group_id].is_opacity_layer());
  ```

- `pub fn is_opacity_layer(&self) -> bool` (method, since 0.4.0): Whether the node is an opacity layer.
  - returns bool: true if the opacity is grouped over the node and its descendants.
- `pub fn get_transform(&self) -> &NodeTransform` (method, since 0.3.2): Returns the transform.
  - returns &NodeTransform: Node transform.
- `pub fn get_transform_mut(&mut self) -> &mut NodeTransform` (method, since 0.3.2): Returns the transform. (mutable)
  - returns &mut NodeTransform: Node transform. (mutable)
- `pub fn set_local_position(&mut self, local_position: Vector2)` (method, since 0.3.2): Transform shortcuts.
  - Sets the local position. (NodeTransform::set_local_position)
  - `local_position` Vector2: Position of the pivot point measured from the top-left of the parent's content area.
- `pub fn get_local_position(&self) -> Vector2` (method, since 0.3.2): Returns the local position. (NodeTransform::get_local_position)
  - returns Vector2: Local position. (position of the pivot point measured from the top-left of the parent's content area)
- `pub fn set_local_scale(&mut self, local_scale: Vector2)` (method, since 0.3.2): Sets the local scale. (NodeTransform::set_local_scale)
  - `local_scale` Vector2: Scale per axis. (1 is the original size, negative draws it flipped on that axis)
- `pub fn get_local_scale(&self) -> Vector2` (method, since 0.3.2): Returns the local scale. (NodeTransform::get_local_scale)
  - returns Vector2: Local scale.
- `pub fn set_local_rotation(&mut self, local_rotation: f64)` (method, since 0.3.2): Sets the local rotation. (NodeTransform::set_local_rotation)
  - `local_rotation` f64: Rotation. (degrees, positive is clockwise on screen)
- `pub fn get_local_rotation(&self) -> f64` (method, since 0.3.2): Returns the local rotation. (NodeTransform::get_local_rotation)
  - returns f64: Local rotation. (degrees)
- `pub fn set_local_opacity(&mut self, local_opacity: f64)` (method, since 0.3.2): Sets the local opacity. (NodeTransform::set_local_opacity, multiplied down into the children)
  - `local_opacity` f64: Opacity. (0 ~ 1, values outside are clamped)
- `pub fn get_local_opacity(&self) -> f64` (method, since 0.3.2): Returns the local opacity. (NodeTransform::get_local_opacity)
  - returns f64: Local opacity. (0 ~ 1)
- `pub fn set_pivot(&mut self, pivot: Vector2)` (method, since 0.3.2): Sets the pivot. (NodeTransform::set_pivot)
  - `pivot` Vector2: Ratio of the reference point within the content size. ((0, 0) top-left, (1, 1) bottom-right, Pivot constants)
- `pub fn get_pivot(&self) -> Vector2` (method, since 0.3.2): Returns the pivot. (NodeTransform::get_pivot)
  - returns Vector2: Pivot. (ratio within the content size)
- `pub fn set_content_size(&mut self, content_size: Vector2)` (method, since 0.3.2): Sets the content size. (NodeTransform::set_content_size)
  - `content_size` Vector2: Content size. (node coordinates, before scale is applied)
- `pub fn get_content_size(&self) -> Vector2` (method, since 0.3.2): Returns the content size. (NodeTransform::get_content_size)
  - returns Vector2: Content size. (node coordinates, before scale is applied)
- `pub fn copy_content_size_to(&self, target: &mut Vector2)` (method, since 0.4.0): Writes the content size into target. (the original copyContentSizeTo, writes into the given place without making a new value)
  - `target` &mut Vector2: Vector that receives the content size. (node coordinates, before scale)

  Example

  ```rust
  use vanilla::{Vector2, WorldNode};
  
  let mut node = WorldNode::new("panel");
  node.set_content_size(Vector2::create(30.0, 40.0));
  let mut content_size = Vector2::zero();
  node.copy_content_size_to(&mut content_size);
  assert_eq!(content_size, Vector2::create(30.0, 40.0));
  ```

- `pub fn read_content_size(&self, out: &mut Vector2)` (method, since 0.4.0): Writes the content size into out. (original readContentSize, the same value as get_content_size, writes into the given place without creating a new value)
  - `out` &mut Vector2: The place to write into.

  Example

  ```rust
  use vanilla::{Vector2, WorldNode};
  
  let mut node = WorldNode::new("panel");
  node.set_content_size(Vector2::create(30.0, 40.0));
  let mut out = Vector2::zero();
  node.read_content_size(&mut out);
  assert_eq!(out, Vector2::create(30.0, 40.0));
  ```

- `pub fn read_pivot(&self, out: &mut Vector2)` (method, since 0.4.0): Writes the pivot into out. (original readPivot, the same value as get_pivot, writes into the given place without creating a new value)
  - `out` &mut Vector2: The place to write into.

  Example

  ```rust
  use vanilla::{Vector2, WorldNode};
  
  let mut node = WorldNode::new("panel");
  node.set_pivot(Vector2::create(0.5, 1.0));
  let mut out = Vector2::zero();
  node.read_pivot(&mut out);
  assert_eq!(out, Vector2::create(0.5, 1.0));
  ```

- `pub fn read_local_position(&self, out: &mut Vector2)` (method, since 0.4.0): Writes the local position into out. (original readLocalPosition, the same value as get_local_position, writes into the given place without creating a new value)
  - `out` &mut Vector2: The place to write into.

  Example

  ```rust
  use vanilla::{Vector2, WorldNode};
  
  let mut node = WorldNode::new("panel");
  node.set_local_position(Vector2::create(3.0, 4.0));
  let mut out = Vector2::zero();
  node.read_local_position(&mut out);
  assert_eq!(out, Vector2::create(3.0, 4.0));
  ```

- `pub fn read_local_scale(&self, out: &mut Vector2)` (method, since 0.4.0): Writes the local scale into out. (original readLocalScale, the same value as get_local_scale, writes into the given place without creating a new value)
  - `out` &mut Vector2: The place to write into.

  Example

  ```rust
  use vanilla::{Vector2, WorldNode};
  
  let mut node = WorldNode::new("panel");
  node.set_local_scale(Vector2::create(2.0, 0.5));
  let mut out = Vector2::zero();
  node.read_local_scale(&mut out);
  assert_eq!(out, Vector2::create(2.0, 0.5));
  ```

- `pub fn set_local_position_xy(&mut self, x: f64, y: f64)` (method, since 0.4.0): Sets the local position. (takes x, y directly, NodeTransform::set_local_position_xy)
  - `x` f64: Local position x.
  - `y` f64: Local position y.
- `pub fn set_local_scale_xy(&mut self, x: f64, y: f64)` (method, since 0.4.0): Sets the local scale. (takes x, y directly, NodeTransform::set_local_scale_xy)
  - `x` f64: Horizontal scale.
  - `y` f64: Vertical scale.
- `pub fn set_content_size_xy(&mut self, width: f64, height: f64)` (method, since 0.4.0): Sets the content size. (takes width, height directly, NodeTransform::set_content_size_xy)
  - `width` f64: Content width.
  - `height` f64: Content height.
- `pub fn set_rect(&mut self, x: f64, y: f64, width: f64, height: f64)` (method, since 0.4.0): Places it on a rectangle within the parent area. (NodeTransform::set_rect, the top-left lands on (x, y) wherever the pivot is)
  - `x` f64: Top-left x. (relative to the top-left of the parent's content area)
  - `y` f64: Top-left y. (relative to the top-left of the parent's content area)
  - `width` f64: Content width.
  - `height` f64: Content height.
- `pub fn set_last_drawn_maximum_scale(&mut self, last_drawn_maximum_scale: f64, frame_number: u64)` (method, since 0.4.0): Remembers the largest scale of the last draw and its draw frame number. (NodeTree calls it after push_transform, original setLastDrawnMaximumScale)
  - The draw frame number goes up by one on every Graphic::begin_frame_statistics. A node not drawn last frame (skipped with its subtree because it was off screen) is treated as drawn for the first time when drawn next.
  - `last_drawn_maximum_scale` f64: Largest scale of the transform. (0 if unknown)
  - `frame_number` u64: Draw frame number it was drawn in. (0 if unknown)
- `pub fn get_last_drawn_maximum_scale(&self) -> f64` (method, since 0.4.0): Returns the largest scale of the transform at the last draw.
  - returns f64: Largest scale. (not known yet if 0)
- `pub fn get_last_drawn_frame_number(&self) -> u64` (method, since 0.4.0): Draw frame number of the last draw. (original getLastDrawnFrameNumber)
  - returns u64: Frame number remembered with set_last_drawn_maximum_scale. (0 if never drawn)

  Example: Read the remembered scale and frame number

  ```rust
  use vanilla::WorldNode;
  
  let mut node = WorldNode::new("label");
  assert_eq!(node.get_last_drawn_frame_number(), 0);
  node.set_last_drawn_maximum_scale(2.0, 7);
  assert_eq!(node.get_last_drawn_maximum_scale(), 2.0);
  assert_eq!(node.get_last_drawn_frame_number(), 7);
  ```

- `pub fn mark_draw_bounds_dirty(&self)` (method, since 0.4.0): Tells that this node's subtree draw bounds changed. (original TransformNode.markDrawBoundsDirty)
  - The engine calls it by itself for content size, gizmo display and adding or removing components. When a component's drawn rect changes the component calls mark_drawn_rect_dirty.
  - This node and its ancestors recompute the next time the bounds are read (before drawing). Does nothing for a node not in a tree.

  Example: Make the bounds recompute

  ```rust
  use vanilla::{NodeTree, Paint, Pivot};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let node_id = node_tree.create_child(root_id, "panel");
  node_tree[node_id].set_pivot(Pivot::TOP_LEFT);
  node_tree[node_id].set_rect(10.0, 20.0, 100.0, 50.0);
  node_tree[node_id].mark_draw_bounds_dirty();
  node_tree[node_id].mark_parent_draw_bounds_dirty();
  ```

- `pub fn mark_parent_draw_bounds_dirty(&self)` (method, since 0.4.0): Tells that the parent's subtree draw bounds changed. (original TransformNode.markParentDrawBoundsDirty, the engine calls it by itself when this node's transform, active state or visibility changes)
- `pub fn set_anchor(&mut self, anchor: Vector2)` (method, since 0.3.2): Sets the anchor. (NodeTransform::set_anchor)
  - `anchor` Vector2: Ratio within the parent's content size. (reference point of anchored_position, Pivot constants)
- `pub fn get_anchor(&self) -> Vector2` (method, since 0.3.2): Returns the anchor. (NodeTransform::get_anchor)
  - returns Vector2: Anchor. (ratio within the parent's content size)
- `pub fn set_visible(&mut self, is_visible: bool)` (method, since 0.3.2): Sets visibility. (NodeTransform::set_visible, tick still runs when off)
  - `is_visible` bool: Whether to draw. (if false, this node and its descendants are not drawn and receive no touches)
- `pub fn is_visible(&self) -> bool` (method, since 0.3.2): Whether visible. (NodeTransform::is_visible)
  - returns bool: True if visible.
- `pub fn add_component<T: Component + 'static>(&mut self, component: T) -> &mut T` (method, since 0.3.2): Adds a component. (returns the added component)
  - Before attaching, creates and attaches any missing dependency components (Component::require), then calls attach.
  - Does not call attach_to_tree. Components that create child nodes when attached are added with NodeTree::add_component.
  - `component` T: Component to add.
  - returns &mut T: The added component. (mutable)

  Example: Modify the component returned while adding it right away

  ```rust
  use vanilla::{Color, Paint, WorldNode};
  
  let mut node = WorldNode::new("panel");
  let paint = node.add_component(Paint::new());
  paint.set_color(Color::create(1.0, 0.0, 0.0, 1.0));
  assert_eq!(node.get_component::<Paint>().expect("paint").get_color(), Color::create(1.0, 0.0, 0.0, 1.0));
  ```

- `pub fn get_or_add_component<T: Component + Default + 'static>(&mut self) -> &mut T` (method, since 0.4.0): Returns the component. If missing, creates one with default values, attaches it and returns it. (the original getOrAddComponent)
  - returns &mut T: The first component of that type. (mutable) A newly attached default one if there was none.

  Example: Only one is attached even if called twice

  ```rust
  use vanilla::{Paint, WorldNode};
  
  let mut node = WorldNode::new("node");
  node.get_or_add_component::<Paint>().set_round_size(8.0);
  assert_eq!(node.get_or_add_component::<Paint>().get_round_size(), 8.0);
  assert_eq!(node.get_components::<Paint>().len(), 1);
  ```

- `pub fn get_components<T: Component + 'static>(&self) -> Vec<&T>` (method, since 0.4.0): All components of that type. (the original getComponents)
  - returns Vec<&T>: All components of that type. (order added) An empty list if none.
- `pub fn get_component<T: Component + 'static>(&self) -> Option<&T>` (method, since 0.3.2): Returns the component. (the first of that type)
  - returns Option<&T>: The first component of that type. None if none.
- `pub fn get_component_mut<T: Component + 'static>(&mut self) -> Option<&mut T>` (method, since 0.3.2): Returns the component. (mutable, the first of that type)
  - returns Option<&mut T>: The first component of that type. (mutable) None if none.
- `pub fn has_component<T: Component + 'static>(&self) -> bool` (method, since 0.3.2): Whether it has the component.
  - returns bool: True if it has a component of that type.
- `pub fn remove_component<T: Component + 'static>(&mut self) -> usize` (method, since 0.3.2): Removes components. (all of that type, count removed)
  - Calls detach for each removed component.
  - returns usize: Number of components removed. (0 if none)

  Example: Remove all of that type

  ```rust
  use vanilla::{Paint, WorldNode};
  
  let mut node = WorldNode::new("node");
  node.add_component(Paint::new());
  node.add_component(Paint::new());
  assert_eq!(node.remove_component::<Paint>(), 2);
  assert!(!node.has_component::<Paint>());
  assert_eq!(node.remove_component::<Paint>(), 0);
  ```

- `pub fn get_all_components(&self) -> &Vec<Box<dyn Component>>` (method, since 0.3.2): All components.
  - returns &Vec<Box<dyn Component>>: All added components. (order added)
- `pub fn push_transform(&self, graphic: &mut Graphic)` (method, since 0.3.2): Begins the draw state. (translate → rotate → scale → pivot correction → opacity multiply)
  - Pushes one Graphic state, then applies it. Call paired with pop_transform.
  - `graphic` &mut Graphic: Graphic to apply the transform to.
- `pub fn push_component_transforms(&mut self, graphic: &mut Graphic)` (method, since 0.4.0): Begins the components' node draw state. (right after push_transform, enabled components in the order added)
  - `graphic` &mut Graphic: Graphic drawing. (with push_transform applied)
- `pub fn pop_component_transforms(&mut self, graphic: &mut Graphic)` (method, since 0.4.0): Ends the components' node draw state. (right before pop_transform, enabled components in reverse order added)
  - `graphic` &mut Graphic: Graphic drawing.
- `pub fn draw_components(&mut self, graphic: &mut Graphic) -> (Option<f64>, bool)` (method, since 0.3.2): Draws the components. (NodeTree draws the children)
  - Returns: (the corner radius if there is a Mask, whether it was skipped for being off screen)
  - If every enabled component reports the rectangle it draws (calculate_drawn_rect), their union is tested against the screen with the current Graphic transform and not drawn if outside.
    If any one is unknown, nothing is culled. Even when culled, NodeTree judges the children separately.
  - `graphic` &mut Graphic: Graphic to draw with. (with push_transform applied)
  - returns (Option<f64>, bool): (the corner radius of the enabled clipping component (Mask), None if none. True if not drawn for being off screen)
- `pub fn draw_gizmos(&mut self, graphic: &mut Graphic)` (method, since 0.3.2): Draws gizmos. (the content_size border and pivot point after draw_gizmos of components whose gizmo display is on)
  - Sets the global alpha to 1 briefly while drawing and restores it. The border and pivot point are '#00ff00', the border width is 1 and the pivot point radius is 4.
  - `graphic` &mut Graphic: Graphic to draw with. (with push_transform applied)
- `pub fn pop_transform(&self, graphic: &mut Graphic)` (method, since 0.3.2): Ends the draw state.
  - `graphic` &mut Graphic: Graphic to pop the state pushed in push_transform from.
- `pub fn contains_point(&self, world_matrix: &TransformMatrix, view_position: Vector2) -> bool` (method, since 0.3.2): Whether a point is within this node's content_size area. (world_matrix is the matrix accumulated up to this node)
  - `world_matrix` &TransformMatrix: Matrix multiplied from the root to this node. (NodeTree::calculate_world_matrix)
  - `view_position` Vector2: Point to check. (view coordinates)
  - returns bool: True if the point is within the content area (0, 0) ~ content_size. (inclusive of the edges) False if the matrix cannot be inverted.

  Example: Inside and outside the area of a top-left-pivot node

  ```rust
  use vanilla::{NodeTree, Pivot, Vector2};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let node_id = node_tree.create_child(root_id, "button");
  node_tree[node_id].set_pivot(Pivot::TOP_LEFT);
  node_tree[node_id].set_rect(100.0, 100.0, 50.0, 30.0);
  let world_matrix = node_tree.calculate_world_matrix(node_id);
  assert!(node_tree[node_id].contains_point(&world_matrix, Vector2::create(120.0, 110.0)));
  assert!(!node_tree[node_id].contains_point(&world_matrix, Vector2::create(10.0, 10.0)));
  ```

