NativeMenu

package
v0.0.0-...-c858641 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

graphics.gd/classdb/NativeMenu handles low-level access to the OS native global menu bar and popup menus.

Note: This is low-level API, consider using graphics.gd/classdb/MenuBar with graphics.gd/classdb/MenuBar.Instance.PreferGlobalMenu set to true, and graphics.gd/classdb/PopupMenu with graphics.gd/classdb/PopupMenu.Instance.PreferNativeMenu set to true.

To create a menu, use CreateMenu, add menu items using add_*_item methods. To remove a menu, use FreeMenu.

package main

import (
	"graphics.gd/classdb/DisplayServer"
	"graphics.gd/classdb/NativeMenu"
	"graphics.gd/variant/RID"
)

var menu RID.NativeMenu

func MenuCallback(item_id any) {
	switch item_id {
	case "ITEM_CUT":
	case "ITEM_COPY":
	case "ITEM_PASTE":
	}
}

func EnterTree() {
	menu = NativeMenu.CreateMenu()
	NativeMenu.AddItem(menu, "Cut", MenuCallback, nil, "ITEM_CUT", 0)
	NativeMenu.AddItem(menu, "Copy", MenuCallback, nil, "ITEM_COPY", 0)
	NativeMenu.AddSeparator(menu)
	NativeMenu.AddItem(menu, "Paste", MenuCallback, nil, "ITEM_PASTE", 0)
}

func OnButtonPressed() {
	NativeMenu.Popup(menu, DisplayServer.MouseGetPosition())
}

func ExitTree() {
	NativeMenu.FreeMenu(menu)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCheckItem

func AddCheckItem(rid RID.NativeMenu, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key) int

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 [KeyModifierMask]s and [Key]s 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.

func AddCheckItemOptions

func AddCheckItemOptions(rid RID.NativeMenu, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key, index int) int

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 [KeyModifierMask]s and [Key]s 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.

func AddIconCheckItem

func AddIconCheckItem(rid RID.NativeMenu, icon Texture2D.Instance, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key) int

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 [KeyModifierMask]s and [Key]s 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.

func AddIconCheckItemOptions

func AddIconCheckItemOptions(rid RID.NativeMenu, icon Texture2D.Instance, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key, index int) int

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 [KeyModifierMask]s and [Key]s 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.

func AddIconItem

func AddIconItem(rid RID.NativeMenu, icon Texture2D.Instance, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key) int

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 [KeyModifierMask]s and [Key]s 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.

func AddIconItemOptions

func AddIconItemOptions(rid RID.NativeMenu, icon Texture2D.Instance, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key, index int) int

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 [KeyModifierMask]s and [Key]s 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.

func AddIconRadioCheckItem

func AddIconRadioCheckItem(rid RID.NativeMenu, icon Texture2D.Instance, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key) int

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 [KeyModifierMask]s and [Key]s 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 SetItemChecked 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.

func AddIconRadioCheckItemOptions

func AddIconRadioCheckItemOptions(rid RID.NativeMenu, icon Texture2D.Instance, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key, index int) int

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 [KeyModifierMask]s and [Key]s 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 SetItemChecked 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.

func AddItem

func AddItem(rid RID.NativeMenu, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key) int

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 [KeyModifierMask]s and [Key]s 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.

func AddItemOptions

func AddItemOptions(rid RID.NativeMenu, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key, index int) int

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 [KeyModifierMask]s and [Key]s 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.

func AddMultistateItem

func AddMultistateItem(rid RID.NativeMenu, label string, max_states int, default_state int, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key) int

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 [KeyModifierMask]s and [Key]s 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.

func AddMultistateItemOptions

func AddMultistateItemOptions(rid RID.NativeMenu, label string, max_states int, default_state int, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key, index int) int

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 [KeyModifierMask]s and [Key]s 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.

func AddRadioCheckItem

func AddRadioCheckItem(rid RID.NativeMenu, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key) int

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 [KeyModifierMask]s and [Key]s 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 SetItemChecked 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.

func AddRadioCheckItemOptions

func AddRadioCheckItemOptions(rid RID.NativeMenu, label string, callback func(tag any), key_callback func(tag any), tag any, accelerator Input.Key, index int) int

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 [KeyModifierMask]s and [Key]s 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 SetItemChecked 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.

func AddSeparator

func AddSeparator(rid RID.NativeMenu) int

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.

func AddSeparatorOptions

func AddSeparatorOptions(rid RID.NativeMenu, index int) int

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.

func AddSubmenuItem

func AddSubmenuItem(rid RID.NativeMenu, label string, submenu_rid RID.NativeMenu, tag any) int

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.

func AddSubmenuItemOptions

func AddSubmenuItemOptions(rid RID.NativeMenu, label string, submenu_rid RID.NativeMenu, tag any, index int) int

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.

func Advanced

func Advanced() class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

func Clear

func Clear(rid RID.NativeMenu)

Removes all items from the global menu 'rid'.

Note: This method is implemented on macOS and Windows.

func CreateMenu

func CreateMenu() RID.NativeMenu

Creates a new global menu object.

Note: This method is implemented on macOS and Windows.

func FindItemIndexWithSubmenu

func FindItemIndexWithSubmenu(rid RID.NativeMenu, submenu_rid RID.NativeMenu) int

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.

func FindItemIndexWithTag

func FindItemIndexWithTag(rid RID.NativeMenu, tag any) int

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.

func FindItemIndexWithText

func FindItemIndexWithText(rid RID.NativeMenu, text string) int

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.

func FreeMenu

func FreeMenu(rid RID.NativeMenu)

Frees a global menu object created by this graphics.gd/classdb/NativeMenu.

Note: This method is implemented on macOS and Windows.

func GetItemAccelerator

func GetItemAccelerator(rid RID.NativeMenu, idx int) Input.Key

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.

func GetItemCallback

func GetItemCallback(rid RID.NativeMenu, idx int) Callable.Function

Returns the callback of the item at index 'idx'.

Note: This method is implemented on macOS and Windows.

func GetItemCount

func GetItemCount(rid RID.NativeMenu) int

Returns number of items in the global menu 'rid'.

Note: This method is implemented on macOS and Windows.

func GetItemIcon

func GetItemIcon(rid RID.NativeMenu, idx int) Texture2D.Instance

Returns the icon of the item at index 'idx'.

Note: This method is implemented on macOS and Windows.

func GetItemIndentationLevel

func GetItemIndentationLevel(rid RID.NativeMenu, idx int) int

Returns the horizontal offset of the item at the given 'idx'.

Note: This method is implemented only on macOS.

func GetItemKeyCallback

func GetItemKeyCallback(rid RID.NativeMenu, idx int) Callable.Function

Returns the callback of the item accelerator at index 'idx'.

Note: This method is implemented only on macOS.

func GetItemMaxStates

func GetItemMaxStates(rid RID.NativeMenu, idx int) int

Returns number of states of a multistate item. See AddMultistateItem for details.

Note: This method is implemented on macOS and Windows.

func GetItemState

func GetItemState(rid RID.NativeMenu, idx int) int

Returns the state of a multistate item. See AddMultistateItem for details.

Note: This method is implemented on macOS and Windows.

func GetItemSubmenu

func GetItemSubmenu(rid RID.NativeMenu, idx int) RID.NativeMenu

Returns the submenu ID of the item at index 'idx'. See AddSubmenuItem for more info on how to add a submenu.

Note: This method is implemented on macOS and Windows.

func GetItemTag

func GetItemTag(rid RID.NativeMenu, idx int) any

Returns the metadata of the specified item, which might be of any type. You can set it with SetItemTag, which provides a simple way of assigning context data to items.

Note: This method is implemented on macOS and Windows.

func GetItemText

func GetItemText(rid RID.NativeMenu, idx int) string

Returns the text of the item at index 'idx'.

Note: This method is implemented on macOS and Windows.

func GetItemTooltip

func GetItemTooltip(rid RID.NativeMenu, idx int) string

Returns the tooltip associated with the specified index 'idx'.

Note: This method is implemented only on macOS.

func GetMinimumWidth

func GetMinimumWidth(rid RID.NativeMenu) Float.X

Returns global menu minimum width.

Note: This method is implemented only on macOS.

func GetPopupCloseCallback

func GetPopupCloseCallback(rid RID.NativeMenu) Callable.Function

Returns global menu close callback.

Note: This method is implemented on macOS and Windows.

func GetPopupOpenCallback

func GetPopupOpenCallback(rid RID.NativeMenu) Callable.Function

Returns global menu open callback.

b]Note:[/b] This method is implemented only on macOS.

func GetSize

func GetSize(rid RID.NativeMenu) Vector2.XY

Returns global menu size.

Note: This method is implemented on macOS and Windows.

func GetSystemMenu

func GetSystemMenu(menu_id SystemMenus) RID.NativeMenu

Returns RID of a special system menu.

Note: This method is implemented only on macOS.

func GetSystemMenuName

func GetSystemMenuName(menu_id SystemMenus) string

Returns readable name of a special system menu.

Note: This method is implemented only on macOS.

func HasFeature

func HasFeature(feature Feature) bool

Returns true if the specified 'feature' is supported by the current graphics.gd/classdb/NativeMenu, false otherwise.

Note: This method is implemented on macOS and Windows.

func HasMenu

func HasMenu(rid RID.NativeMenu) bool

Returns true if 'rid' is valid global menu.

Note: This method is implemented on macOS and Windows.

func HasSystemMenu

func HasSystemMenu(menu_id SystemMenus) bool

Returns true if a special system menu is supported.

Note: This method is implemented only on macOS.

func IsItemCheckable

func IsItemCheckable(rid RID.NativeMenu, idx int) bool

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.

func IsItemChecked

func IsItemChecked(rid RID.NativeMenu, idx int) bool

Returns true if the item at index 'idx' is checked.

Note: This method is implemented on macOS and Windows.

func IsItemDisabled

func IsItemDisabled(rid RID.NativeMenu, idx int) bool

Returns true if the item at index 'idx' is disabled. When it is disabled it can't be selected, or its action invoked.

See SetItemDisabled for more info on how to disable an item.

Note: This method is implemented on macOS and Windows.

func IsItemHidden

func IsItemHidden(rid RID.NativeMenu, idx int) bool

Returns true if the item at index 'idx' is hidden.

See SetItemHidden for more info on how to hide an item.

Note: This method is implemented only on macOS.

func IsItemRadioCheckable

func IsItemRadioCheckable(rid RID.NativeMenu, idx int) bool

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.

func IsOpened

func IsOpened(rid RID.NativeMenu) bool

Returns true if the menu is currently opened.

Note: This method is implemented only on macOS.

func IsSystemMenu

func IsSystemMenu(rid RID.NativeMenu) bool

Return true is global menu is a special system menu.

Note: This method is implemented only on macOS.

func Popup(rid RID.NativeMenu, position Vector2i.XY)

Shows the global menu at 'position' in the screen coordinates.

Note: This method is implemented on macOS and Windows.

func RemoveItem

func RemoveItem(rid RID.NativeMenu, idx int)

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.

func SetInterfaceDirection

func SetInterfaceDirection(rid RID.NativeMenu, is_rtl bool)

Sets the menu text layout direction from right-to-left if 'is_rtl' is true.

Note: This method is implemented on macOS and Windows.

func SetItemAccelerator

func SetItemAccelerator(rid RID.NativeMenu, idx int, keycode Input.Key)

Sets the accelerator of the item at index 'idx'. 'keycode' can be a single [Key], or a combination of [KeyModifierMask]s and [Key]s using bitwise OR such as KEY_MASK_CTRL | KEY_A (Ctrl + A).

Note: This method is implemented only on macOS.

func SetItemCallback

func SetItemCallback(rid RID.NativeMenu, idx int, callback func(tag any))

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.

func SetItemCheckable

func SetItemCheckable(rid RID.NativeMenu, idx int, checkable bool)

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.

func SetItemChecked

func SetItemChecked(rid RID.NativeMenu, idx int, checked bool)

Sets the checkstate status of the item at index 'idx'.

Note: This method is implemented on macOS and Windows.

func SetItemDisabled

func SetItemDisabled(rid RID.NativeMenu, idx int, disabled bool)

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.

func SetItemHidden

func SetItemHidden(rid RID.NativeMenu, idx int, hidden bool)

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.

func SetItemHoverCallbacks

func SetItemHoverCallbacks(rid RID.NativeMenu, idx int, callback func(tag any))

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.

func SetItemIcon

func SetItemIcon(rid RID.NativeMenu, idx int, icon Texture2D.Instance)

Replaces the graphics.gd/classdb/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.

func SetItemIndentationLevel

func SetItemIndentationLevel(rid RID.NativeMenu, idx int, level int)

Sets the horizontal offset of the item at the given 'idx'.

Note: This method is implemented only on macOS.

func SetItemKeyCallback

func SetItemKeyCallback(rid RID.NativeMenu, idx int, key_callback func(tag any))

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.

func SetItemMaxStates

func SetItemMaxStates(rid RID.NativeMenu, idx int, max_states int)

Sets number of state of a multistate item. See AddMultistateItem for details.

Note: This method is implemented on macOS and Windows.

func SetItemRadioCheckable

func SetItemRadioCheckable(rid RID.NativeMenu, idx int, checkable bool)

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.

func SetItemState

func SetItemState(rid RID.NativeMenu, idx int, state int)

Sets the state of a multistate item. See AddMultistateItem for details.

Note: This method is implemented on macOS and Windows.

func SetItemSubmenu

func SetItemSubmenu(rid RID.NativeMenu, idx int, submenu_rid RID.NativeMenu)

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.

func SetItemTag

func SetItemTag(rid RID.NativeMenu, idx int, tag any)

Sets the metadata of an item, which may be of any type. You can later get it with GetItemTag, which provides a simple way of assigning context data to items.

Note: This method is implemented on macOS and Windows.

func SetItemText

func SetItemText(rid RID.NativeMenu, idx int, text string)

Sets the text of the item at index 'idx'.

Note: This method is implemented on macOS and Windows.

func SetItemTooltip

func SetItemTooltip(rid RID.NativeMenu, idx int, tooltip string)

Sets the string tooltip of the item at the specified index 'idx'.

Note: This method is implemented only on macOS.

func SetMinimumWidth

func SetMinimumWidth(rid RID.NativeMenu, width Float.X)

Sets the minimum width of the global menu.

Note: This method is implemented only on macOS.

func SetPopupCloseCallback

func SetPopupCloseCallback(rid RID.NativeMenu, callback func())

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 IsOpened to check if the menu is currently opened.

Note: This method is implemented on macOS and Windows.

func SetPopupOpenCallback

func SetPopupOpenCallback(rid RID.NativeMenu, callback func())

Registers callable to emit after the menu is closed.

Note: This method is implemented only on macOS.

Types

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type Feature

type Feature int //gd:NativeMenu.Feature
const (
	// [graphics.gd/classdb/NativeMenu] supports native global main menu.
	FeatureGlobalMenu Feature = 0
	// [graphics.gd/classdb/NativeMenu] supports native popup menus.
	FeaturePopupMenu Feature = 1
	// [graphics.gd/classdb/NativeMenu] supports menu open and close callbacks.
	FeatureOpenCloseCallback Feature = 2
	// [graphics.gd/classdb/NativeMenu] supports menu item hover callback.
	FeatureHoverCallback Feature = 3
	// [graphics.gd/classdb/NativeMenu] supports menu item accelerator/key callback.
	FeatureKeyCallback Feature = 4
)

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.NativeMenu

Instance of the class with convieniently typed arguments and results.

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type SystemMenus

type SystemMenus int //gd:NativeMenu.SystemMenus
const (
	// Invalid special system menu ID.
	InvalidMenuId SystemMenus = 0
	// Global main menu ID.
	MainMenuId SystemMenus = 1
	// Application (first menu after "Apple" menu on macOS) menu ID.
	ApplicationMenuId SystemMenus = 2
	// "Window" menu ID (on macOS this menu includes standard window control items and a list of open windows).
	WindowMenuId SystemMenus = 3
	// "Help" menu ID (on macOS this menu includes help search bar).
	HelpMenuId SystemMenus = 4
	// Dock icon right-click menu ID (on macOS this menu include standard application control items and a list of open windows).
	DockMenuId SystemMenus = 5
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL