# ui/uicontextmenu (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/ui/uicontextmenu/

컨텍스트 메뉴. (우클릭 / 길게 누름 메뉴)

## UIContextMenu extends WorldNode

컨텍스트 메뉴. (우클릭 / 길게 누름 메뉴)
- show(position, itemList) 로 항목 목록을 그 자리에 띄운다.
  바깥을 누르면 닫히고, 항목을 누르면 처리기를 부르고 닫힌다.
- 씬 뿌리의 맨 위(마지막 자식)에 addChild 해 두고 쓴다.
- 사용:
    const contextMenu = new UIContextMenu();
    scene.getRoot().addChild(contextMenu);
    contextMenu.show(viewPosition, [
        { text: "복사", handler: () => {} },
        { text: "삭제", handler: () => {} },
    ]);

예제: 뿌리 맨 위에 붙여 메뉴 띄우기

```js
import { Engine, EngineConfiguration, UIScene, UIContextMenu, Color, Vector2 } from "./build/vanilla.js";

class ContextMenuScene extends UIScene {
	create() {
		super.create();
		const contextMenu = new UIContextMenu({ menuWidth: 180, fontSize: 13, panelColor: new Color(0.1, 0.12, 0.18, 1) });
		const root = this.getRoot();
		root.addChild(contextMenu);
		contextMenu.show(Vector2.create(200, 120), [
			{ text: "Copy", handler: () => {
				console.log("copy");
			} },
			{ text: "Paste", isDisabled: true },
			{ text: "Delete", handler: () => {
				console.log("delete");
			} },
		]);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new ContextMenuScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);
```

- `constructor(options = {})` (constructor, since 0.3.0): 생성.
  - `options` object: { menuWidth = 168, itemHeight = 28, fontSize = 12, panelColor?, textColor? }
- `show(position, itemList)` (method, since 0.3.0): 메뉴 열기.
  - itemList: [{ text, handler?, isDisabled? }]
  - `position` Vector2: 뷰 좌표. (메뉴 좌상단)
  - `itemList` object[]: 항목 목록. ({ text, handler?, isDisabled? }, 막은 항목은 흐린 글로 보이고 눌리지 않는다)
- `close()` (method, since 0.3.0): 닫기.
- `isShowing()` (method, since 0.3.0): 표시 중 여부.
  - returns boolean: 떠 있으면 참.
