Skip to Content

Context Menu

Nested context menus with icons, metadata, progress bars, and submenu navigation.

Client Exports

registerContext

Register one or more context menus. Menus must be registered before they can be shown.

exports['trinity-ui']:registerContext(context)

Parameters:

PropertyTypeRequiredDescription
idstringYesUnique menu identifier
titlestringYesMenu title
menustringParent menu ID (enables back navigation)
canClosebooleanWhether the menu can be closed (default true)
onExitfunctionCalled when the menu is closed
onBackfunctionCalled when the back button is pressed
optionstable[]YesArray of menu items (see below)

Option Properties:

PropertyTypeDescription
titlestringItem label (required)
descriptionstringSecondary text
iconstringIconify icon name
iconColorstringIcon color (hex)
imagestringImage URL
progressnumberProgress bar percentage (0-100)
menustringSubmenu ID to navigate to
arrowbooleanShow submenu arrow indicator
onSelectfunctionCallback when selected
eventstringClient event to trigger
serverEventstringServer event to trigger
argsanyData passed to callback/event
metadatastring | table | table[]Metadata displayed on the item
disabledbooleanGrey out the item
readOnlybooleanNon-interactive item
expandablebooleanExpandable details section
closeOnClickbooleanClose menu on click (default true)

showContext

Open a previously registered context menu by its ID.

exports['trinity-ui']:showContext(id)

hideContext

Close the currently open context menu.

exports['trinity-ui']:hideContext()

getOpenContextMenu

Returns the ID of the currently open context menu, or nil.

local id = exports['trinity-ui']:getOpenContextMenu()

Example

-- Register menus exports['trinity-ui']:registerContext({ { id = 'main_menu', title = 'Main Menu', options = { { title = 'Vehicle Options', icon = 'fa6-solid:car', description = 'Manage your vehicle', menu = 'vehicle_menu', arrow = true }, { title = 'Player Info', icon = 'fa6-solid:user', metadata = { { label = 'Job', value = 'Police Officer' }, { label = 'Rank', value = 'Sergeant' } } }, { title = 'Heal Player', icon = 'fa6-solid:heart', iconColor = '#ff0000', progress = 75, onSelect = function() print('Healing!') end } } }, { id = 'vehicle_menu', title = 'Vehicle Options', menu = 'main_menu', -- enables back button options = { { title = 'Lock Vehicle', icon = 'fa6-solid:lock', onSelect = function() print('Vehicle locked') end }, { title = 'Engine Toggle', icon = 'fa6-solid:power-off', event = 'vehicle:toggleEngine' } } } }) -- Open the menu exports['trinity-ui']:showContext('main_menu')
Last updated on