vanilladocs
vanillapunch.com
API / ui/uihitarea

ui/uihitarea

누르는 자리 넓히기. (vanilla.js ui/uihitarea.js 의 UIHitArea)

  • 보이는 단추는 그대로 두고, 단추 바로 뒤 형제로 투명한 누름 자리를 두어 가로세로를 가장 작은 크기 이상으로 넓힌다. (손가락으로 누르기 좋게)
  • 그리는 차례가 늦은 노드가 누름을 받으므로, 단추 위는 단추가 받고 단추 둘레의 넓힌 몫만 누름 자리가 받는다.
  • 누름 자리를 누르면 단추의 클릭 알림(Clicked, Click)을 그대로 부른다. 단추가 꺼지거나 누를 수 없으면 누름 자리도 따른다.
  • 단추의 자리, 크기, 피봇을 프레임마다 따라가므로 화면이 단추를 다시 놓아도 맞는다.
  • 자르는 노드를 정하면 넓힌 몫이 그 노드의 사각형 밖으로 나가지 않게 자른다. (단추 자신의 자리는 그대로, 창 밖이나 스크롤 칸 밖이 눌리지 않게)
  • 사용: UIHitArea::attach(node_tree, button_id, minimum_size) (단추가 부모에 붙은 뒤에 부른다)

Hit area widening. (UIHitArea of vanilla.js ui/uihitarea.js)

  • Leaves the visible button as is and places a transparent hit area as the sibling right behind the button, widening its width and height to at least the minimum size. (easier to press with a finger)
  • The node drawn later receives the press, so the button receives presses over the button and the hit area receives only the widened margin around it.
  • Pressing the hit area fires the button's click notifications (Clicked, Click) as is. If the button is turned off or not pressable, the hit area follows.
  • It follows the button's position, size, and pivot every frame, so it stays aligned even when the screen moves the button.
  • When a clipping node is set, the widened margin is clipped so it does not go outside that node's rectangle. (the button's own area stays as is, so areas outside the window or scroll area are not pressed)
  • Usage: UIHitArea::attach(node_tree, button_id, minimum_size) (call after the button is attached to its parent)

UIHitAreastruct traits Default, Component

짝Counterpart: vanilla.js UIHitArea소스source

누르는 자리 넓히기. (단추 바로 뒤 형제 노드에 붙어 단추를 따라가는 투명한 누름 자리)

Hit area widening. (a transparent hit area attached to the sibling node right behind the button that follows the button)

예제Example작은 닫기 단추의 누르는 자리 넓히기Enlarge the press area of a small close button
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{ComponentContext, Engine, EngineConfiguration, NodeTree, Paint, Pivot, TouchKind, UIButton, UIHitArea, Vector2};

let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let button_id = node_tree.create_child(root_id, "CloseButton");
node_tree[button_id].set_pivot(Pivot::TOP_LEFT);
node_tree[button_id].set_local_position(Vector2::create(300.0, 20.0));
node_tree[button_id].set_content_size(Vector2::create(24.0, 24.0));
node_tree[button_id].add_component(Paint::create_with_color("#d94d4d"));
let click_count = Rc::new(Cell::new(0));
let click_count_for_event = click_count.clone();
let button = node_tree.add_component(button_id, UIButton::new()).expect("button");
button.set_click_event(Box::new(move |_button: &mut UIButton, _context: &mut ComponentContext| {
	click_count_for_event.set(click_count_for_event.get() + 1);
}));

let hit_id = UIHitArea::attach(&mut node_tree, button_id, 48.0).expect("hit area");
node_tree.tick(&engine, 0.016);
assert_eq!(node_tree[hit_id].get_local_position(), Vector2::create(288.0, 8.0));
assert_eq!(node_tree[hit_id].get_content_size(), Vector2::create(48.0, 48.0));
let hit_area = node_tree[hit_id].get_component::<UIHitArea>().expect("hit area");
assert!(hit_area.get_target_button(&node_tree).is_some());

let beside_button = Vector2::create(295.0, 15.0);
node_tree.dispatch_touch(hit_id, &engine, TouchKind::Press, beside_button);
node_tree.dispatch_touch(hit_id, &engine, TouchKind::Release, beside_button);
assert_eq!(click_count.get(), 1);
생성자constructorpub fn new() -> UIHitArea#0.4.0 부터since 0.4.0소스source

생성.

Constructor.

반환ReturnsUIHitArea 대상이 없고 가장 작은 가로세로가 0 인 누름 자리. (단추에 달 때는 attach 를 쓴다)Hit area with no target and a minimum width and height of 0. (use attach to put it on a button)

짝Counterpart: vanilla.js UIHitArea.constructor

정적staticpub fn attach(node_tree: &mut NodeTree, button_id: NodeId, minimum_size: f64) -> Option<NodeId>#0.4.0 부터since 0.4.0소스source

단추에 넓힌 누름 자리 달기. (단추의 바로 뒤 형제로 끼우고 누름 자리 노드를 돌려준다, 부모가 없거나 UIButton 이 없으면 None)

  • 누름 자리 노드는 부모의 자식 목록에서 단추 바로 앞에 끼워 단추보다 먼저 그려진다. 피봇은 왼쪽 위다.
  • 누름 자리 노드에도 UIButton 을 붙이고, 그 클릭이 단추의 fire_click_events 를 부른다.

Attaches a widened hit area to a button. (inserts it as the sibling right behind the button and returns the hit area node, None if there is no parent or no UIButton)

  • The hit area node is inserted right before the button in the parent's child list, so it is drawn before the button. The pivot is the top left.
  • A UIButton is also attached to the hit area node, and its click calls the button's fire_click_events.
node_tree&mut NodeTree
단추가 든 노드 트리.Node tree that holds the button.
button_idNodeId
넓힐 단추 노드. (UIButton 이 붙어 있고 부모에 붙어 있어야 한다)Button node to widen. (must have a UIButton and be attached to a parent)
minimum_sizef64
누르는 자리의 가장 작은 가로세로. (단추의 content_size 와 같은 단위)Minimum width and height of the hit area. (same units as the button's content_size)

반환ReturnsOption<NodeId> 만든 누름 자리 노드. (이름은 단추 이름 뒤에 "HitArea") 단추에 부모가 없거나 UIButton 이 없으면 None 이고 노드를 만들지 않는다.The created hit area node. (named the button's name followed by "HitArea") None if the button has no parent or no UIButton, and no node is created.

짝Counterpart: vanilla.js UIHitArea.attach

예제Example단추가 아니면 달지 않고, 단추면 바로 앞에 끼운다Not attached if it is not a button, inserted right before it if it is
use vanilla::{NodeTree, UIButton, UIHitArea};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let plain_id = node_tree.create_child(root_id, "Plain");
assert!(UIHitArea::attach(&mut node_tree, plain_id, 48.0).is_none());

let button_id = node_tree.create_child(root_id, "Ok");
node_tree.add_component(button_id, UIButton::new());
let hit_id = UIHitArea::attach(&mut node_tree, button_id, 48.0).expect("hit area");
assert_eq!(node_tree.get_child_ids(root_id), &[plain_id, hit_id, button_id]);
assert_eq!(node_tree[hit_id].get_name(), "OkHitArea");
메서드methodpub fn set_target(&mut self, target_id: NodeId)#0.4.0 부터since 0.4.0소스source

넓혀 줄 단추의 노드 설정.

Sets the node of the button to widen.

target_idNodeId
넓혀 줄 단추 노드. (UIButton 이 붙은 노드, tick 이 그 자리와 크기를 따라간다)Button node to widen. (a node with a UIButton, tick follows its position and size)

짝Counterpart: vanilla.js UIHitArea.setTarget

메서드methodpub fn get_target(&self) -> Option<NodeId>#0.4.0 부터since 0.4.0소스source

넓혀 줄 단추의 노드 반환.

Returns the node of the button to widen.

반환ReturnsOption<NodeId> 넓혀 줄 단추 노드. 정하지 않았으면 None.Button node to widen. None if not set.

메서드methodpub fn get_target_button<'a>(&self, node_tree: &'a NodeTree) -> Option<&'a UIButton>#0.4.0 부터since 0.4.0소스source

넓혀 줄 단추. (원본 getTargetButton, 원본은 단추 컴포넌트를 쥐고 러스트 판은 대상 노드에서 꺼내므로 트리를 받는다)

Button to widen. (original getTargetButton, the original holds the button component while the Rust version takes it out of the target node, so it takes the tree)

node_tree&'a NodeTree
대상 노드를 찾을 노드 트리.Node tree to find the target node in.

반환ReturnsOption<&'a UIButton> 대상 노드의 UIButton. 대상을 정하지 않았거나, 대상 노드가 없거나, UIButton 이 없으면 None.UIButton of the target node. None if no target is set, the target node does not exist, or it has no UIButton.

짝Counterpart: vanilla.js UIHitArea.getTargetButton

메서드methodpub fn set_minimum_size(&mut self, minimum_size: f64)#0.4.0 부터since 0.4.0소스source

누르는 자리의 가장 작은 가로세로 설정.

Sets the minimum width and height of the press area.

minimum_sizef64
가장 작은 가로세로. (단추의 content_size 와 같은 단위, 단추가 이보다 크면 그 쪽은 단추 크기)Minimum width and height. (same units as the button's content_size, if the button is larger on a side, that side uses the button size)

짝Counterpart: vanilla.js UIHitArea.setMinimumSize

메서드methodpub fn get_minimum_size(&self) -> f64#0.4.0 부터since 0.4.0소스source

누르는 자리의 가장 작은 가로세로 반환.

Returns the minimum width and height of the press area.

반환Returnsf64 가장 작은 가로세로. (기본 0)Minimum width and height. (default 0)

짝Counterpart: vanilla.js UIHitArea.getMinimumSize

메서드methodpub fn set_clip_node(&mut self, clip_id: Option<NodeId>)#0.4.0 부터since 0.4.0소스source

넓힌 몫을 자르는 노드 설정. (None 이면 자르지 않는다)

Sets the node that clips the widened margin. (None for no clipping)

clip_idOption<NodeId>
넓힌 몫이 그 content_size 사각형 밖으로 나가지 않게 할 노드. (창이나 스크롤 칸, None 이면 자르지 않는다)Node whose content_size rectangle the widened margin must not go outside. (a window or scroll area, None for no clipping)

짝Counterpart: vanilla.js UIHitArea.setClipNode

메서드methodpub fn get_clip_node(&self) -> Option<NodeId>#0.4.0 부터since 0.4.0소스source

넓힌 몫을 자르는 노드 반환.

Returns the node that clips the widened portion.

반환ReturnsOption<NodeId> 자르는 노드. 정하지 않았으면 None.Clipping node. None if not set.

짝Counterpart: vanilla.js UIHitArea.getClipNode