CCKit2
    Preparing search index...

    Class CCMenu

    Holds information about a single menu in the menu bar or context menu, either as a top-level menu or a submenu.
    Example image

    TypeScript
    let menu = new CCMenu();
    menu.addItem("New", () => this.newItem(), {key: CCKey.N, ctrl: true});
    menu.addItem("Open", () => this.openItem(), {key: CCKey.O, ctrl: true});
    menu.addSpacer();
    menu.addItem("Auto Save", state => this.setAutosave(state), undefined, false);
    let submenu = new CCMenu();
    submenu.addItem("Top", () => this.setPosition("top"), undefined, "position");
    submenu.addItem("Center", () => this.setPosition("center"), undefined, "position");
    submenu.addItem("Bottom", () => this.setPosition("bottom"), undefined, "position");
    menu.addItem("Position", submenu);
    Lua
    local menu = LuaWrappers.new(CCMenu)
    menu:addItem("New", function() self:newItem() end, {key = CCKey.N, ctrl = true})
    menu:addItem("Open", function() self:openItem() end, {key = CCKey.O, ctrl = true})
    menu:addSpacer()
    menu:addItem("Auto Save", function(state) self:setAutosave(state) end, nil, false)
    local submenu = LuaWrappers.new(CCMenu)
    submenu:addItem("Top", function() self:setPosition("top") end, nil, "position")
    submenu:addItem("Center", function() self:setPosition("center") end, nil, "position")
    submenu:addItem("Bottom", function() self:setPosition("bottom") end, nil, "position")
    menu:addItem("Position", submenu)
    Index

    Constructors

    Properties

    supermenu?: CCMenu

    The menu that contains this menu.

    Accessors

    • get length(): number

      The number of items in the menu.

      Returns number

    Methods

    • Adds an item to the end of the menu.

      Parameters

      Returns void

    • Constructs and adds a new item with an action.

      Parameters

      • title: string

        The title of the item

      • action: () => void

        The function to call when the item is clicked

      • OptionalkeyEquivalent: CCKeyCombo

        A key combo to trigger the action with

      Returns void

    • Constructs and adds a new menu item for a radio action.

      Parameters

      • title: string

        The title for the action

      • action: () => void

        The function to call when the action is triggered

      • keyCombo: CCKeyCombo | undefined

        A key combo that will trigger the action, if desired

      • radioGroup: string

        The ID of the group the item is in

      Returns void

    • Constructs and adds a new menu item for a checkbox action.

      Parameters

      • title: string

        The title for the action

      • action: (checked?: boolean) => void

        The function to call when the action is triggered

      • keyCombo: CCKeyCombo | undefined

        A key combo that will trigger the action, if desired

      • checked: boolean

        Whether the checkbox is initially checked

      Returns void

    • Constructs and adds a new menu item for a submenu.

      Parameters

      • title: string

        The title for the submenu

      • menu: CCMenu

        The menu to display under this item

      Returns void

    • Adds an empty spacer item.

      Returns void

    • Returns the index of the specified menu item.

      Parameters

      Returns number | undefined

      The item's index, or undefined if not found

    • Returns the index of the first menu item with the specified submenu.

      Parameters

      • menu: CCMenu

        The menu to look for

      Returns number | undefined

      The found item's index, or undefined if not found

    • Returns the index of the first menu item with the specified title.

      Parameters

      • title: string

        The title to look for

      Returns number | undefined

      The found item's index, or undefined if not found

    • Inserts an item at the specified index.

      Parameters

      • item: CCMenuItem

        The item to add

      • index: number

        The index to add at

      Returns void

    • Returns the menu item at the specified index.

      Parameters

      • index: number

        The index of the item

      Returns CCMenuItem | undefined

      The found item, or undefined if not found

    • Returns the first menu item with the specified title.

      Parameters

      • title: string

        The title to look for

      Returns CCMenuItem | undefined

      The found item, or undefined if not found

    • Removes an item at the specified index from the menu.

      Parameters

      • index: number

        The index of the item to remove

      Returns void

    • Triggers an incoming action on a nested subitem.

      Parameters

      • key: string

        The key of the item that was triggered

      Returns boolean

      Whether an item triggered an action