ui/uihitarea
누르는 자리 넓히기.
Expands the press area.
UIHitAreaextends Component
누르는 자리 넓히기.
- 보이는 단추는 그대로 두고, 단추 바로 뒤 형제로 투명한 누름 자리를 두어 가로세로를 가장 작은 크기 이상으로 넓힌다. (손가락으로 누르기 좋게)
- 그리는 차례가 늦은 노드가 누름을 받으므로, 단추 위는 단추가 받고 단추 둘레의 넓힌 몫만 누름 자리가 받는다.
- 누름 자리를 누르면 단추의 클릭 알림을 그대로 부른다. 단추가 꺼지거나 누를 수 없으면 누름 자리도 따른다.
- 단추의 자리, 크기, 피봇을 프레임마다 따라가므로 화면이 단추를 다시 놓아도 맞는다.
- 자르는 노드를 정하면 넓힌 몫이 그 노드의 화면 사각형 밖으로 나가지 않게 자른다. (단추 자신의 자리는 그대로, 창 밖이나 스크롤 칸 밖이 눌리지 않게) 자르기는 부모가 돌지 않을 때 맞는다.
- 사용: UIHitArea.attach(buttonNode, minimumSize) (단추가 부모에 붙은 뒤에 부른다)
Expands the press area.
- Keeps the visible button as is, and places a transparent press area as the sibling right behind the button to widen its width and height to at least the minimum size. (easier to press with a finger)
- The node later in draw order receives the press, so presses on the button are received by the button and only the widened part around the button is received by the press area.
- Pressing the press area calls the button's click notification as is. If the button is turned off or cannot be pressed, the press area follows.
- Follows the button's position, size and pivot every frame, so it stays matched even when the screen re-places the button.
- If a clipping node is set, clips the widened part so it does not go outside that node's screen rectangle. (the button's own area stays as is, so that areas outside the window or the scroll box are not pressed) Clipping is correct when the parent does not rotate.
- Usage: UIHitArea.attach(buttonNode, minimumSize) (call after the button is attached to its parent)
import { Engine, EngineConfiguration, UIScene, UIButton, UIHitArea, Paint, WorldNode, Pivot, Vector2, Color } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
}
initialize(engine) {
super.initialize(engine);
const buttonNode = new WorldNode();
buttonNode.setName("CloseButton");
buttonNode.setPivot(Pivot.topLeft);
buttonNode.setAnchor(Pivot.topLeft);
buttonNode.setLocalPosition(Vector2.create(300, 20));
buttonNode.setContentSize(Vector2.create(24, 24));
const paint = buttonNode.addComponent(Paint);
paint.setColor(new Color(0.85, 0.3, 0.3, 1));
const button = buttonNode.addComponent(UIButton);
button.setClickedEvent(() => {
console.log("close");
});
const root = this.getRoot();
root.addChild(buttonNode);
const hitNode = UIHitArea.attach(buttonNode, 48);
const hitArea = hitNode.getComponent(UIHitArea);
hitArea.setClipNode(root);
console.log(hitNode.getName(), hitArea.getMinimumSize());
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());단추에 넓힌 누름 자리 달기. (단추가 부모에 붙은 뒤에 부른다, 단추의 바로 뒤 형제로 끼우고 누름 자리 노드를 돌려준다)
Attaches a widened press area to the button. (Call after the button is attached to its parent, inserts it as the button's next sibling and returns the press area node)
- buttonNodeWorldNode
- UIButton 이 붙은 노드.Node with UIButton attached.
- minimumSizenumber
- 누르는 자리의 가장 작은 가로세로. (부모 안의 단위)Minimum width and height of the press area. (units within the parent)
반환ReturnsWorldNode | null 만든 누름 자리 노드. (단추 노드에 부모가 없거나 UIButton 이 없으면 null)The created press area node. (null if the button node has no parent or no UIButton)
짝Counterpart: vanilla-engine UIHitArea.attach
단추 따라가기. (가운데를 맞추고 모자란 쪽만 넓힌다, 단추가 꺼져 있으면 함께 끈다)
Follows the button. (Aligns the center and widens only the short side, turns off together when the button is off)
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
넓혀 줄 단추 설정.
Sets the button to widen.
- targetNodeWorldNode
- 넓혀 줄 단추의 노드.Node of the button to enlarge.
- targetButtonUIButton
- 그 노드에 붙은 단추.The button attached to that node.
짝Counterpart: vanilla-engine UIHitArea.set_target
넓혀 줄 단추의 노드 반환.
Returns the node of the button to widen.
반환ReturnsWorldNode | null 넓혀 줄 단추의 노드. (정하지 않았으면 null)Node of the button to enlarge. (null if not set)
넓혀 줄 단추 반환.
Returns the button to widen.
반환ReturnsUIButton | null 넓혀 줄 단추. (정하지 않았으면 null)The button to enlarge. (null if not set)
짝Counterpart: vanilla-engine UIHitArea.get_target_button
누르는 자리의 가장 작은 가로세로 설정.
Sets the minimum width and height of the press area.
- minimumSizenumber
- 누르는 자리의 가장 작은 가로세로. (부모 안의 단위, 단추가 이보다 큰 축은 넓히지 않는다)Minimum width and height of the press area. (units within the parent, axes where the button is larger are not enlarged)
짝Counterpart: vanilla-engine UIHitArea.set_minimum_size
누르는 자리의 가장 작은 가로세로 반환.
Returns the minimum width and height of the press area.
반환Returnsnumber 누르는 자리의 가장 작은 가로세로. (기본 0)Minimum width and height of the press area. (default 0)
짝Counterpart: vanilla-engine UIHitArea.get_minimum_size
넓힌 몫을 자르는 노드 설정. (null 이면 자르지 않는다)
Sets the node that clips the widened portion. (null means no clipping)
- clipNodeWorldNode | null
- 넓힌 몫을 자르는 노드. (null 이면 자르지 않는다)Node that clips the enlarged part. (no clipping if null)
짝Counterpart: vanilla-engine UIHitArea.set_clip_node
넓힌 몫을 자르는 노드 반환.
Returns the node that clips the widened portion.
반환ReturnsWorldNode | null 넓힌 몫을 자르는 노드. (없으면 null)Node that clips the enlarged part. (null if none)
짝Counterpart: vanilla-engine UIHitArea.get_clip_node