API / ui/uicontextmenu
ui/uicontextmenu
컨텍스트 메뉴. (우클릭 / 길게 누름 메뉴)
Context menu. (right-click / long-press menu)
UIContextMenuextends WorldNode
컨텍스트 메뉴. (우클릭 / 길게 누름 메뉴)
- show(position, itemList) 로 항목 목록을 그 자리에 띄운다. 바깥을 누르면 닫히고, 항목을 누르면 처리기를 부르고 닫힌다.
- 씬 뿌리의 맨 위(마지막 자식)에 addChild 해 두고 쓴다.
- 사용:
const contextMenu = new UIContextMenu();
scene.getRoot().addChild(contextMenu);
contextMenu.show(viewPosition, [
{ text: "복사", handler: () => {} },
{ text: "삭제", handler: () => {} },
]);Context menu. (right-click / long-press menu)
- show(position, itemList) pops up the item list at that position. Pressing outside closes it, and pressing an item calls its handler and closes it.
- addChild it at the top (last child) of the scene root before use.
- Usage:
const contextMenu = new UIContextMenu();
scene.getRoot().addChild(contextMenu);
contextMenu.show(viewPosition, [
{ text: "Copy", handler: () => {} },
{ text: "Delete", handler: () => {} },
]);예제Example뿌리 맨 위에 붙여 메뉴 띄우기Showing a menu attached on top of the root
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.
- optionsobject
- { menuWidth = 168, itemHeight = 28, fontSize = 12, panelColor?, textColor? }
짝Counterpart: vanilla-engine UIContextMenu.new
메뉴 열기.
- itemList: [{ text, handler?, isDisabled? }]
Opens the menu.
- itemList: [{ text, handler?, isDisabled? }]
- positionVector2
- 뷰 좌표. (메뉴 좌상단)View coordinates. (top-left of the menu)
- itemListobject[]
- 항목 목록. ({ text, handler?, isDisabled? }, 막은 항목은 흐린 글로 보이고 눌리지 않는다)Item list. ({ text, handler?, isDisabled? }, disabled items show dim text and cannot be pressed)
짝Counterpart: vanilla-engine UIContextMenu.show
표시 중 여부.
Whether it is showing.
반환Returnsboolean 떠 있으면 참.True if shown.
짝Counterpart: vanilla-engine UIContextMenu.is_showing