A server interface for OS native menus. [NativeMenu] handles low-level access to the OS native global menu bar and popup menus. [b]Note:[/b] This is low-level API, consider using [MenuBar] with [member MenuBar.prefer_global_menu] set to [code]true[/code], and [PopupMenu] with [member PopupMenu.prefer_native_menu] set to [code]true[/code]. To create a menu, use [method create_menu], add menu items using [code]add_*_item[/code] methods. To remove a menu, use [method free_menu]. [codeblock] var menu func _menu_callback(item_id): if item_id == "ITEM_CUT": cut() elif item_id == "ITEM_COPY": copy() elif item_id == "ITEM_PASTE": paste() func _enter_tree(): # Create new menu and add items: menu = NativeMenu.create_menu() NativeMenu.add_item(menu, "Cut", _menu_callback, Callable(), "ITEM_CUT") NativeMenu.add_item(menu, "Copy", _menu_callback, Callable(), "ITEM_COPY") NativeMenu.add_separator(menu) NativeMenu.add_item(menu, "Paste", _menu_callback, Callable(), "ITEM_PASTE") func _on_button_pressed(): # Show popup menu at mouse position: NativeMenu.popup(menu, DisplayServer.mouse_get_position()) func _exit_tree(): # Remove menu when it's no longer needed: NativeMenu.free_menu(menu) [/codeblock] Adds a new checkable item with text [param label] to the global menu [param rid]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. An [param accelerator] can optionally be defined, which is a keyboard shortcut that can be pressed to trigger the menu button even if it's not currently open. The [param accelerator] is generally a combination of [enum KeyModifierMask]s and [enum Key]s using bitwise OR such as [code]KEY_MASK_CTRL | KEY_A[/code] ([kbd]Ctrl + A[/kbd]). [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS and Windows. [b]Note:[/b] On Windows, [param accelerator] and [param key_callback] are ignored. Adds a new checkable item with text [param label] and icon [param icon] to the global menu [param rid]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. An [param accelerator] can optionally be defined, which is a keyboard shortcut that can be pressed to trigger the menu button even if it's not currently open. The [param accelerator] is generally a combination of [enum KeyModifierMask]s and [enum Key]s using bitwise OR such as [code]KEY_MASK_CTRL | KEY_A[/code] ([kbd]Ctrl + A[/kbd]). [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS and Windows. [b]Note:[/b] On Windows, [param accelerator] and [param key_callback] are ignored. Adds a new item with text [param label] and icon [param icon] to the global menu [param rid]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. An [param accelerator] can optionally be defined, which is a keyboard shortcut that can be pressed to trigger the menu button even if it's not currently open. The [param accelerator] is generally a combination of [enum KeyModifierMask]s and [enum Key]s using bitwise OR such as [code]KEY_MASK_CTRL | KEY_A[/code] ([kbd]Ctrl + A[/kbd]). [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS and Windows. [b]Note:[/b] On Windows, [param accelerator] and [param key_callback] are ignored. Adds a new radio-checkable item with text [param label] and icon [param icon] to the global menu [param rid]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. An [param accelerator] can optionally be defined, which is a keyboard shortcut that can be pressed to trigger the menu button even if it's not currently open. The [param accelerator] is generally a combination of [enum KeyModifierMask]s and [enum Key]s using bitwise OR such as [code]KEY_MASK_CTRL | KEY_A[/code] ([kbd]Ctrl + A[/kbd]). [b]Note:[/b] Radio-checkable items just display a checkmark, but don't have any built-in checking behavior and must be checked/unchecked manually. See [method set_item_checked] for more info on how to control it. [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS and Windows. [b]Note:[/b] On Windows, [param accelerator] and [param key_callback] are ignored. Adds a new item with text [param label] to the global menu [param rid]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. An [param accelerator] can optionally be defined, which is a keyboard shortcut that can be pressed to trigger the menu button even if it's not currently open. The [param accelerator] is generally a combination of [enum KeyModifierMask]s and [enum Key]s using bitwise OR such as [code]KEY_MASK_CTRL | KEY_A[/code] ([kbd]Ctrl + A[/kbd]). [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS and Windows. [b]Note:[/b] On Windows, [param accelerator] and [param key_callback] are ignored. Adds a new item with text [param label] to the global menu [param rid]. Contrarily to normal binary items, multistate items can have more than two states, as defined by [param max_states]. Each press or activate of the item will increase the state by one. The default value is defined by [param default_state]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. An [param accelerator] can optionally be defined, which is a keyboard shortcut that can be pressed to trigger the menu button even if it's not currently open. The [param accelerator] is generally a combination of [enum KeyModifierMask]s and [enum Key]s using bitwise OR such as [code]KEY_MASK_CTRL | KEY_A[/code] ([kbd]Ctrl + A[/kbd]). [b]Note:[/b] By default, there's no indication of the current item state, it should be changed manually. [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS and Windows. [b]Note:[/b] On Windows, [param accelerator] and [param key_callback] are ignored. Adds a new radio-checkable item with text [param label] to the global menu [param rid]. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. An [param accelerator] can optionally be defined, which is a keyboard shortcut that can be pressed to trigger the menu button even if it's not currently open. The [param accelerator] is generally a combination of [enum KeyModifierMask]s and [enum Key]s using bitwise OR such as [code]KEY_MASK_CTRL | KEY_A[/code] ([kbd]Ctrl + A[/kbd]). [b]Note:[/b] Radio-checkable items just display a checkmark, but don't have any built-in checking behavior and must be checked/unchecked manually. See [method set_item_checked] for more info on how to control it. [b]Note:[/b] The [param callback] and [param key_callback] Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to [param tag]. [b]Note:[/b] This method is implemented on macOS and Windows. [b]Note:[/b] On Windows, [param accelerator] and [param key_callback] are ignored. Adds a separator between items to the global menu [param rid]. Separators also occupy an index. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. [b]Note:[/b] This method is implemented on macOS and Windows. Adds an item that will act as a submenu of the global menu [param rid]. The [param submenu_rid] argument is the RID of the global menu that will be shown when the item is clicked. Returns index of the inserted item, it's not guaranteed to be the same as [param index] value. [b]Note:[/b] This method is implemented on macOS and Windows. Removes all items from the global menu [param rid]. [b]Note:[/b] This method is implemented on macOS and Windows. Creates a new global menu object. [b]Note:[/b] This method is implemented on macOS and Windows. Returns the index of the item with the specified [param tag]. Index is automatically assigned to each item by the engine. Index can not be set manually. [b]Note:[/b] This method is implemented on macOS and Windows. Returns the index of the item with the specified [param text]. Index is automatically assigned to each item by the engine. Index can not be set manually. [b]Note:[/b] This method is implemented on macOS and Windows. Frees a global menu object created by this [NativeMenu]. [b]Note:[/b] This method is implemented on macOS and Windows. Returns the accelerator of the item at index [param idx]. Accelerators are special combinations of keys that activate the item, no matter which control is focused. [b]Note:[/b] This method is implemented only on macOS. Returns the callback of the item at index [param idx]. [b]Note:[/b] This method is implemented on macOS and Windows. Returns number of items in the global menu [param rid]. [b]Note:[/b] This method is implemented on macOS and Windows. Returns the icon of the item at index [param idx]. [b]Note:[/b] This method is implemented on macOS and Windows. Returns the horizontal offset of the item at the given [param idx]. [b]Note:[/b] This method is implemented only on macOS. Returns the callback of the item accelerator at index [param idx]. [b]Note:[/b] This method is implemented only on macOS. Returns number of states of a multistate item. See [method add_multistate_item] for details. [b]Note:[/b] This method is implemented on macOS and Windows. Returns the state of a multistate item. See [method add_multistate_item] for details. [b]Note:[/b] This method is implemented on macOS and Windows. Returns the submenu ID of the item at index [param idx]. See [method add_submenu_item] for more info on how to add a submenu. [b]Note:[/b] This method is implemented on macOS and Windows. Returns the metadata of the specified item, which might be of any type. You can set it with [method set_item_tag], which provides a simple way of assigning context data to items. [b]Note:[/b] This method is implemented on macOS and Windows. Returns the text of the item at index [param idx]. [b]Note:[/b] This method is implemented on macOS and Windows. Returns the tooltip associated with the specified index [param idx]. [b]Note:[/b] This method is implemented only on macOS. Returns global menu minimum width. [b]Note:[/b] This method is implemented only on macOS. Returns global menu close callback. b]Note:[/b] This method is implemented only on macOS. Returns global menu open callback. b]Note:[/b] This method is implemented only on macOS. Returns global menu size. [b]Note:[/b] This method is implemented on macOS and Windows. Returns RID of a special system menu. [b]Note:[/b] This method is implemented only on macOS. Returns readable name of a special system menu. [b]Note:[/b] This method is implemented only on macOS. Returns [code]true[/code] if the specified [param feature] is supported by the current [NativeMenu], [code]false[/code] otherwise. [b]Note:[/b] This method is implemented on macOS and Windows. Returns [code]true[/code] if [param rid] is valid global menu. [b]Note:[/b] This method is implemented on macOS and Windows. Returns [code]true[/code] if a special system menu is supported. [b]Note:[/b] This method is implemented only on macOS. Returns [code]true[/code] if the item at index [param idx] is checkable in some way, i.e. if it has a checkbox or radio button. [b]Note:[/b] This method is implemented on macOS and Windows. Returns [code]true[/code] if the item at index [param idx] is checked. [b]Note:[/b] This method is implemented on macOS and Windows. Returns [code]true[/code] if the item at index [param idx] is disabled. When it is disabled it can't be selected, or its action invoked. See [method set_item_disabled] for more info on how to disable an item. [b]Note:[/b] This method is implemented on macOS and Windows. Returns [code]true[/code] if the item at index [param idx] is hidden. See [method set_item_hidden] for more info on how to hide an item. [b]Note:[/b] This method is implemented only on macOS. Returns [code]true[/code] if the item at index [param idx] has radio button-style checkability. [b]Note:[/b] This is purely cosmetic; you must add the logic for checking/unchecking items in radio groups. [b]Note:[/b] This method is implemented on macOS and Windows. Return [code]true[/code] is global menu is a special system menu. [b]Note:[/b] This method is implemented only on macOS. Shows the global menu at [param position] in the screen coordinates. [b]Note:[/b] This method is implemented on macOS and Windows. Removes the item at index [param idx] from the global menu [param rid]. [b]Note:[/b] The indices of items after the removed item will be shifted by one. [b]Note:[/b] This method is implemented on macOS and Windows. Sets the menu text layout direction from right-to-left if [param is_rtl] is [code]true[/code]. [b]Note:[/b] This method is implemented on macOS and Windows. Sets the accelerator of the item at index [param idx]. [param keycode] can be a single [enum Key], or a combination of [enum KeyModifierMask]s and [enum Key]s using bitwise OR such as [code]KEY_MASK_CTRL | KEY_A[/code] ([kbd]Ctrl + A[/kbd]). [b]Note:[/b] This method is implemented only on macOS. Sets the callback of the item at index [param idx]. Callback is emitted when an item is pressed. [b]Note:[/b] The [param callback] Callable needs to accept exactly one Variant parameter, the parameter passed to the Callable will be the value passed to the [code]tag[/code] parameter when the menu item was created. [b]Note:[/b] This method is implemented on macOS and Windows. Sets whether the item at index [param idx] has a checkbox. If [code]false[/code], sets the type of the item to plain text. [b]Note:[/b] This method is implemented on macOS and Windows. Sets the checkstate status of the item at index [param idx]. [b]Note:[/b] This method is implemented on macOS and Windows. Enables/disables the item at index [param idx]. When it is disabled, it can't be selected and its action can't be invoked. [b]Note:[/b] This method is implemented on macOS and Windows. Hides/shows the item at index [param idx]. When it is hidden, an item does not appear in a menu and its action cannot be invoked. [b]Note:[/b] This method is implemented only on macOS. Sets the callback of the item at index [param idx]. The callback is emitted when an item is hovered. [b]Note:[/b] The [param callback] Callable needs to accept exactly one Variant parameter, the parameter passed to the Callable will be the value passed to the [code]tag[/code] parameter when the menu item was created. [b]Note:[/b] This method is implemented only on macOS. Replaces the [Texture2D] icon of the specified [param idx]. [b]Note:[/b] This method is implemented on macOS and Windows. [b]Note:[/b] This method is not supported by macOS Dock menu items. Sets the horizontal offset of the item at the given [param idx]. [b]Note:[/b] This method is implemented only on macOS. Sets the callback of the item at index [param idx]. Callback is emitted when its accelerator is activated. [b]Note:[/b] The [param key_callback] Callable needs to accept exactly one Variant parameter, the parameter passed to the Callable will be the value passed to the [code]tag[/code] parameter when the menu item was created. [b]Note:[/b] This method is implemented only on macOS. Sets number of state of a multistate item. See [method add_multistate_item] for details. [b]Note:[/b] This method is implemented on macOS and Windows. Sets the type of the item at the specified index [param idx] to radio button. If [code]false[/code], sets the type of the item to plain text. [b]Note:[/b] This is purely cosmetic; you must add the logic for checking/unchecking items in radio groups. [b]Note:[/b] This method is implemented on macOS and Windows. Sets the state of a multistate item. See [method add_multistate_item] for details. [b]Note:[/b] This method is implemented on macOS and Windows. Sets the submenu RID of the item at index [param idx]. The submenu is a global menu that would be shown when the item is clicked. [b]Note:[/b] This method is implemented on macOS and Windows. Sets the metadata of an item, which may be of any type. You can later get it with [method get_item_tag], which provides a simple way of assigning context data to items. [b]Note:[/b] This method is implemented on macOS and Windows. Sets the text of the item at index [param idx]. [b]Note:[/b] This method is implemented on macOS and Windows. Sets the [String] tooltip of the item at the specified index [param idx]. [b]Note:[/b] This method is implemented only on macOS. Sets the minimum width of the global menu. [b]Note:[/b] This method is implemented only on macOS. Registers callable to emit when the menu is about to show. [b]Note:[/b] This method is implemented only on macOS. Registers callable to emit when the menu is about to closed. [b]Note:[/b] This method is implemented only on macOS. [NativeMenu] supports native global main menu. [NativeMenu] supports native popup menus. [NativeMenu] supports menu open and close callbacks. [NativeMenu] supports menu item hover callback. [NativeMenu] supports menu item accelerator/key callback. Invalid special system menu ID. Global main menu ID. Application (first menu after "Apple" menu on macOS) menu ID. "Window" menu ID (on macOS this menu includes standard window control items and a list of open windows). "Help" menu ID (on macOS this menu includes help search bar). Dock icon right-click menu ID (on macOS this menu include standard application control items and a list of open windows).