NativeMenu handles low-level access to the OS native global menu bar and popup menus.
To create a menu, use create_menu(), add menu items using add_*_item
methods. To remove a menu, use free_menu().
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).
Adds a new checkable item with text label
to the global menu rid
.
Returns index of the inserted item, it's not guaranteed to be the same as index
value.
An 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 accelerator
is generally a combination of KeyModifierMasks and Keys using bitwise OR such as KEY_MASK_CTRL | KEY_A
(Ctrl + A).
Note: The callback
and key_callback
Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to tag
.
Note: This method is implemented on macOS and Windows.
Note: On Windows, accelerator
and key_callback
are ignored.
Adds a new checkable item with text label
and icon icon
to the global menu rid
.
Returns index of the inserted item, it's not guaranteed to be the same as index
value.
An 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 accelerator
is generally a combination of KeyModifierMasks and Keys using bitwise OR such as KEY_MASK_CTRL | KEY_A
(Ctrl + A).
Note: The callback
and key_callback
Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to tag
.
Note: This method is implemented on macOS and Windows.
Note: On Windows, accelerator
and key_callback
are ignored.
Adds a new item with text label
and icon icon
to the global menu rid
.
Returns index of the inserted item, it's not guaranteed to be the same as index
value.
An 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 accelerator
is generally a combination of KeyModifierMasks and Keys using bitwise OR such as KEY_MASK_CTRL | KEY_A
(Ctrl + A).
Note: The callback
and key_callback
Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to tag
.
Note: This method is implemented on macOS and Windows.
Note: On Windows, accelerator
and key_callback
are ignored.
Adds a new radio-checkable item with text label
and icon icon
to the global menu rid
.
Returns index of the inserted item, it's not guaranteed to be the same as index
value.
An 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 accelerator
is generally a combination of KeyModifierMasks and Keys using bitwise OR such as KEY_MASK_CTRL | KEY_A
(Ctrl + A).
Note: Radio-checkable items just display a checkmark, but don't have any built-in checking behavior and must be checked/unchecked manually. See set_item_checked() for more info on how to control it.
Note: The callback
and key_callback
Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to tag
.
Note: This method is implemented on macOS and Windows.
Note: On Windows, accelerator
and key_callback
are ignored.
Adds a new item with text label
to the global menu rid
.
Returns index of the inserted item, it's not guaranteed to be the same as index
value.
An 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 accelerator
is generally a combination of KeyModifierMasks and Keys using bitwise OR such as KEY_MASK_CTRL | KEY_A
(Ctrl + A).
Note: The callback
and key_callback
Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to tag
.
Note: This method is implemented on macOS and Windows.
Note: On Windows, accelerator
and key_callback
are ignored.
Adds a new item with text label
to the global menu rid
.
Contrarily to normal binary items, multistate items can have more than two states, as defined by max_states
. Each press or activate of the item will increase the state by one. The default value is defined by default_state
.
Returns index of the inserted item, it's not guaranteed to be the same as index
value.
An 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 accelerator
is generally a combination of KeyModifierMasks and Keys using bitwise OR such as KEY_MASK_CTRL | KEY_A
(Ctrl + A).
Note: By default, there's no indication of the current item state, it should be changed manually.
Note: The callback
and key_callback
Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to tag
.
Note: This method is implemented on macOS and Windows.
Note: On Windows, accelerator
and key_callback
are ignored.
Adds a new radio-checkable item with text label
to the global menu rid
.
Returns index of the inserted item, it's not guaranteed to be the same as index
value.
An 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 accelerator
is generally a combination of KeyModifierMasks and Keys using bitwise OR such as KEY_MASK_CTRL | KEY_A
(Ctrl + A).
Note: Radio-checkable items just display a checkmark, but don't have any built-in checking behavior and must be checked/unchecked manually. See set_item_checked() for more info on how to control it.
Note: The callback
and key_callback
Callables need to accept exactly one Variant parameter, the parameter passed to the Callables will be the value passed to tag
.
Note: This method is implemented on macOS and Windows.
Note: On Windows, accelerator
and key_callback
are ignored.
Adds a separator between items to the global menu rid
. Separators also occupy an index.
Returns index of the inserted item, it's not guaranteed to be the same as index
value.
Note: This method is implemented on macOS and Windows.
Adds an item that will act as a submenu of the global menu rid
. The 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 index
value.
Note: This method is implemented on macOS and Windows.
Removes all items from the global menu rid
.
Note: This method is implemented on macOS and Windows.
Creates a new global menu object.
Note: This method is implemented on macOS and Windows.
Returns the index of the item with the submenu specified by submenu_rid
. Indices are automatically assigned to each item by the engine, and cannot be set manually.
Note: This method is implemented on macOS and Windows.
Returns the index of the item with the specified tag
. Indices are automatically assigned to each item by the engine, and cannot be set manually.
Note: This method is implemented on macOS and Windows.
Returns the index of the item with the specified text
. Indices are automatically assigned to each item by the engine, and cannot be set manually.
Note: This method is implemented on macOS and Windows.
Frees a global menu object created by this NativeMenu.
Note: This method is implemented on macOS and Windows.
Returns the accelerator of the item at index idx
. Accelerators are special combinations of keys that activate the item, no matter which control is focused.
Note: This method is implemented only on macOS.
Returns the callback of the item at index idx
.
Note: This method is implemented on macOS and Windows.
Returns number of items in the global menu rid
.
Note: This method is implemented on macOS and Windows.
Returns the icon of the item at index idx
.
Note: This method is implemented on macOS and Windows.
Returns the horizontal offset of the item at the given idx
.
Note: This method is implemented only on macOS.
Returns the callback of the item accelerator at index idx
.
Note: This method is implemented only on macOS.
Returns number of states of a multistate item. See add_multistate_item() for details.
Note: This method is implemented on macOS and Windows.
Returns the state of a multistate item. See add_multistate_item() for details.
Note: This method is implemented on macOS and Windows.
Returns the submenu ID of the item at index idx
. See add_submenu_item() for more info on how to add a submenu.
Note: 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 set_item_tag(), which provides a simple way of assigning context data to items.
Note: This method is implemented on macOS and Windows.
Returns the text of the item at index idx
.
Note: This method is implemented on macOS and Windows.
Returns the tooltip associated with the specified index idx
.
Note: This method is implemented only on macOS.
Returns global menu minimum width.
Note: This method is implemented only on macOS.
Returns global menu close callback.
Note: This method is implemented on macOS and Windows.
Returns global menu open callback.
b]Note:** This method is implemented only on macOS.
Returns global menu size.
Note: This method is implemented on macOS and Windows.
Returns RID of a special system menu.
Note: This method is implemented only on macOS.
Returns readable name of a special system menu.
Note: This method is implemented only on macOS.
Returns true
if the specified feature
is supported by the current NativeMenu, false
otherwise.
Note: This method is implemented on macOS and Windows.
Returns true
if rid
is valid global menu.
Note: This method is implemented on macOS and Windows.
Returns true
if a special system menu is supported.
Note: This method is implemented only on macOS.
Returns true
if the item at index idx
is checkable in some way, i.e. if it has a checkbox or radio button.
Note: This method is implemented on macOS and Windows.
Returns true
if the item at index idx
is checked.
Note: This method is implemented on macOS and Windows.
Returns true
if the item at index idx
is disabled. When it is disabled it can't be selected, or its action invoked.
See set_item_disabled() for more info on how to disable an item.
Note: This method is implemented on macOS and Windows.
Returns true
if the item at index idx
is hidden.
See set_item_hidden() for more info on how to hide an item.
Note: This method is implemented only on macOS.
Returns true
if the item at index idx
has radio button-style checkability.
Note: This is purely cosmetic; you must add the logic for checking/unchecking items in radio groups.
Note: This method is implemented on macOS and Windows.
Returns true
if the menu is currently opened.
Note: This method is implemented only on macOS.
Return true
is global menu is a special system menu.
Note: This method is implemented only on macOS.
Shows the global menu at position
in the screen coordinates.
Note: This method is implemented on macOS and Windows.
Removes the item at index idx
from the global menu rid
.
Note: The indices of items after the removed item will be shifted by one.
Note: This method is implemented on macOS and Windows.
Sets the menu text layout direction from right-to-left if is_rtl
is true
.
Note: This method is implemented on macOS and Windows.
Sets the accelerator of the item at index idx
. keycode
can be a single Key, or a combination of KeyModifierMasks and Keys using bitwise OR such as KEY_MASK_CTRL | KEY_A
(Ctrl + A).
Note: This method is implemented only on macOS.
Sets the callback of the item at index idx
. Callback is emitted when an item is pressed.
Note: The callback
Callable needs to accept exactly one Variant parameter, the parameter passed to the Callable will be the value passed to the tag
parameter when the menu item was created.
Note: This method is implemented on macOS and Windows.
Sets whether the item at index idx
has a checkbox. If false
, sets the type of the item to plain text.
Note: This method is implemented on macOS and Windows.
Sets the checkstate status of the item at index idx
.
Note: This method is implemented on macOS and Windows.
Enables/disables the item at index idx
. When it is disabled, it can't be selected and its action can't be invoked.
Note: This method is implemented on macOS and Windows.
Hides/shows the item at index idx
. When it is hidden, an item does not appear in a menu and its action cannot be invoked.
Note: This method is implemented only on macOS.
Sets the callback of the item at index idx
. The callback is emitted when an item is hovered.
Note: The callback
Callable needs to accept exactly one Variant parameter, the parameter passed to the Callable will be the value passed to the tag
parameter when the menu item was created.
Note: This method is implemented only on macOS.
Replaces the Texture2D icon of the specified idx
.
Note: This method is implemented on macOS and Windows.
Note: This method is not supported by macOS Dock menu items.
Sets the horizontal offset of the item at the given idx
.
Note: This method is implemented only on macOS.
Sets the callback of the item at index idx
. Callback is emitted when its accelerator is activated.
Note: The key_callback
Callable needs to accept exactly one Variant parameter, the parameter passed to the Callable will be the value passed to the tag
parameter when the menu item was created.
Note: This method is implemented only on macOS.
Sets number of state of a multistate item. See add_multistate_item() for details.
Note: This method is implemented on macOS and Windows.
Sets the type of the item at the specified index idx
to radio button. If false
, sets the type of the item to plain text.
Note: This is purely cosmetic; you must add the logic for checking/unchecking items in radio groups.
Note: This method is implemented on macOS and Windows.
Sets the state of a multistate item. See add_multistate_item() for details.
Note: This method is implemented on macOS and Windows.
Sets the submenu RID of the item at index idx
. The submenu is a global menu that would be shown when the item is clicked.
Note: 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 get_item_tag(), which provides a simple way of assigning context data to items.
Note: This method is implemented on macOS and Windows.
Sets the text of the item at index idx
.
Note: This method is implemented on macOS and Windows.
Sets the String tooltip of the item at the specified index idx
.
Note: This method is implemented only on macOS.
Sets the minimum width of the global menu.
Note: This method is implemented only on macOS.
Registers callable to emit when the menu is about to show.
Note: The OS can simulate menu opening to track menu item changes and global shortcuts, in which case the corresponding close callback is not triggered. Use is_opened() to check if the menu is currently opened.
Note: This method is implemented on macOS and Windows.
Registers callable to emit after the menu is closed.
Note: This method is implemented only on macOS.