Skip to main content

Menus

Overview

Menu allows users to select a single option in the Main Menu.

This control will display the options in the current Menu. Click the control to unfold or fold the options of the Menu. The Menu itself and its counterparts will unfold the drop-down list if it is clicked by the user.

  • Folded State

Menu

  • Unfolded State

Menu1

Properties

PropertyDescription
Left BarWhether to display the icon bar on the left of the menu item.
Item HeightSet the height of the menu item.
Is CenterWhether the text of the menu items is aligned to the center.

Events

addCallBack1

Callback NameCallback Function
on_drag_enterThe callback when selecting a Menu.
on_select_item_changedThe callback when selecting a menu item.

Lua Script Example

function main_form_open(self)
local gui = nx_value("gui")
local main_menu = gui:Create("MainMenu")
main_menu.Left = 0
main_menu.Top = 0
main_menu.Width = 400

local menu_file = main_menu:CreateMenu("File", nx_widestr("File"))
menu_file:CreateItem("create", nx_widestr("Create Project"))
menu_file:CreateItem("open", nx_widestr("Open Project"))
menu_file:CreateItem("rename", nx_widestr("Rename Project"))

local menu_config = main_menu:CreateMenu("Config", nx_widestr("Config"))
local menu_tool = main_menu:CreateMenu("Tool", nx_widestr("Tool"))
local menu_build = main_menu:CreateMenu("Build", nx_widestr("Build"))
self:Add(main_menu)
return 1

end

-- When the mouse selects Menu, the callback function on_drag_enter will be executed.
function Menu_drag_enter(self, drag_x, drag_y)
nx_msgbox("Menu_drag_enter")
end