Menus#
Menus are a top level element that display a list of items. They are typically used to provide contextual actions, ie. a context or ‘right click’ menu.
Menus function much like boxes, except they can only have
uimenuitem as children.
New menus can be created with the menu() function in the
ui module.
New menu items can be created with the following functions:
Functions#
- ui.menuitem()#
Create a new
uimenuitem.- Return type:
Version History
Version
Notes
0.3.0
Added
- ui.textmenuitem(text, color, font)#
Create a new menu item containing a
uitext.- Parameters:
- Return type:
See also
text,color, andfontare passed directly totext().Version History
Version
Notes
0.3.0
Added
- ui.separatormenuitem(orientation)#
Create a new
uimenuitemwith auiseparator.- Parameters:
orientation (
string)- Return type:
See also
orientationis passed directly toseparator().Version History
Version
Notes
0.3.0
Added
Classes#
- class ui.uimenu#
- pushfront(item)#
Add the given
uimenuitemto the beginning of the menu.- Parameters:
item (
uimenuitem)
Version History
Version
Notes
0.3.0
Added
- pushback(item)#
Add the given
uimenuitemto the end of the menu.- Parameters:
item (
uimenuitem)
Version History
Version
Notes
0.3.0
Added
- popfront()#
Remove the first item from the menu.
Version History
Version
Notes
0.3.0
Added
- popback()#
Remove the last item from the menu.
Version History
Version
Notes
0.3.0
Added
- insertbefore(before, item)#
Insert
itembefore itembefore.If
beforeis not in this menu,itemis not added and this method will returnfalse.trueis returned on success.- Parameters:
before (
uimenuitem)item (
uimenuitem)
- Return type:
Version History
Version
Notes
0.3.0
Added
- insertafter(after, item)#
Insert
itemafter itemafter.If
afteris not in this menu,itemis not added and this method will returnfalse.trueis returned on success.- Parameters:
after (
uimenuitem)item (
uimenuitem)
- Return type:
Version History
Version
Notes
0.3.0
Added
- removeitem(item)#
Remove the given
uimenuitemfrom the menu.- Parameters:
item (
uimenuitem)
Version History
Version
Notes
0.3.0
Added
- show([x, y])#
Show the menu, either at the given location or at the mouse cursor.
Version History
Version
Notes
0.3.0
Added
- hide()#
Hide the menu.
Version History
Version
Notes
0.3.0
Added
Note
The following methods are inherited from
uielement- x([position])#
Set or get the current position X.
Important
It is normally not necessary to manually position an element.
Version History
Version
Notes
0.3.0
Added
- y([position])#
Set or get the current position Y.
Important
It is normally not necessary to manually position an element.
Version History
Version
Notes
0.3.0
Added
- width([value])#
Get or set the element’s width.
Important
It is normally not necessary to manually set an element’s size.
Version History
Version
Notes
0.3.0
Added
- height([value])#
Get or set the element’s height.
Important
It is normally not necessary to manually set an element’s size.
Version History
Version
Notes
0.3.0
Added
- class ui.uimenuitem#
A item within a
uimenu.Menu items are made up of 3 pieces:
+--------+---------+------------+ | (icon) | (child) | (sub-menu) | +--------+---------+------------+
The icon is a text value displayed using the default icon font. This can be used to indicate a status such as on/off or to give additional context or a visual hint to the menu item.
The child is any valid UI element; most commonly the child will be a
uitext.The sub-menu item will only be shown if the item contains a sub-menu. This gives the user an indication that the sub-menu exists and will be shown when the item is hovered.
- enabled(value)#
Set if this menu item is enabled or not.
A disabled menu item does not react or send mouse events.
- Parameters:
value (
boolean)
Version History
Version
Notes
0.3.0
Added
- element(element)#
Set the UI Element to be displayed in this menu item.
- Parameters:
element (
uielement)
Version History
Version
Notes
0.3.0
Added
- icon([codepoint])#
Get or set the icon to be shown on this menu item.
If
codepointis not supplied, the current icon string is returned.See also
iconcodepoint()can be used to lookup an icon codepoint.Version History
Version
Notes
0.3.0
Added
- submenu(menu)#
Set a sub-menu to be shown when this menu item is hovered.
- Parameters:
menu (
uimenu)
Version History
Version
Notes
0.3.0
Added
- addeventhandler(handler[, event1, event2, ...])#
Add an event handler.
If no event types are specified, ‘click-left’ will be used.
Version History
Version
Notes
0.3.0
Added
- removeeventhandler(handlerid)#
Remove an event handler added with
addeventhandler().- Parameters:
handlerid (
integer)
Version History
Version
Notes
0.3.0
Added
- sendevent(event)#
Send an event to event handlers of this menu item.
Note
This is only intended to be used when sub-classing a menu item.
- Parameters:
event (
string)
Version History
Version
Notes
0.3.0
Added
Note
The following methods are inherited from
uielement- x([position])#
Set or get the current position X.
Important
It is normally not necessary to manually position an element.
Version History
Version
Notes
0.3.0
Added
- y([position])#
Set or get the current position Y.
Important
It is normally not necessary to manually position an element.
Version History
Version
Notes
0.3.0
Added
- width([value])#
Get or set the element’s width.
Important
It is normally not necessary to manually set an element’s size.
Version History
Version
Notes
0.3.0
Added
- height([value])#
Get or set the element’s height.
Important
It is normally not necessary to manually set an element’s size.
Version History
Version
Notes
0.3.0
Added