Index | Collapse All Expand All

ContextMenu Class
Members Examples See Also

Beta Documentation - Subject to change.
Defines a menu that can be displayed to the user.

# Remarks

Context menus are popup menus that can be displayed anywhere on the screen. They contain a collection of menu items that represents choices the user can make.Only one context menu can be displayed at a time and any user input outside of the context menu will cause the menu to be closed.

# Examples

This example will display a context menu at the current mouse position. A message will be display in the chat window displaying which option was clicked.

Context Menu Example | Copy Code
--- | ---
           contextMenu = Turbine.UI.ContextMenu();

           -- Populate the menu with some items.
           menuItems = contextMenu:GetItems();
           menuItems:Add( Turbine.UI.MenuItem( "Red" ) );
           menuItems:Add( Turbine.UI.MenuItem( "Orange" ) );
           menuItems:Add( Turbine.UI.MenuItem( "Yellow" ) );
           menuItems:Add( Turbine.UI.MenuItem( "Green" ) );
           menuItems:Add( Turbine.UI.MenuItem( "Blue" ) );
           menuItems:Add( Turbine.UI.MenuItem( "Purple" ) );

           -- Register event handlers with all the menu items.
           local i;

           -- Register an event handler to display what menu item was clicked
           -- in the chat window.
           for i = 1, menuItems:GetCount() do
             local menuItem = menuItems:Get( i );

             menuItem.Click = function( sender, args )
               Turbine.Shell.WriteLine( "You have selected " .. sender:GetText() .. "." );
             end
           end

           -- Display the menu at the current mouse location.
           contextMenu:ShowMenu();

# Inheritance Hierarchy

Turbine.Object
Turbine.UI.ContextMenu

# See Also

- Turbine.UI