A menu is a list of options or actions presented to the user as a popup.
Here are the available methods for Menu Component.
Examples
Example - Basic menu click to expand contents
class Main extends App
{
onStart()
{
// Creates a fullscreen layout with objects vertically centered.
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
// Adds a button control to the layout
this.btn = ui.addButton(this.main, "Show Menu", "Primary")
this.btn.setOnTouch( this.onTouch )
// Menu items to display in the popup
var items = ["Item 1", "Item 2", "Item 3"]
// Adds a menu passing the button control as anchor
this.menu = ui.addMenu(this.btn, items)
// Add a callback handler when a menu is touched
this.menu.setOnTouch( this.menuTouch )
}
onTouch()
{
// show the menu
this.menu.show()
}
menuTouch( item )
{
ui.showPopup( item )
}
}
{
onStart()
{
// Creates a fullscreen layout with objects vertically centered.
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
// Adds a button control to the layout
this.btn = ui.addButton(this.main, "Show Menu", "Primary")
this.btn.setOnTouch( this.onTouch )
// Menu items to display in the popup
var items = ["Item 1", "Item 2", "Item 3"]
// Adds a menu passing the button control as anchor
this.menu = ui.addMenu(this.btn, items)
// Add a callback handler when a menu is touched
this.menu.setOnTouch( this.menuTouch )
}
onTouch()
{
// show the menu
this.menu.show()
}
menuTouch( item )
{
ui.showPopup( item )
}
}
from hybrid import ui
def OnStart():
global menu
# Creates a fullscreen layout with objects vertically centered.
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
# Adds a button control to the layout
btn = ui.addButton(main, "Show Menu", "Primary")
btn.setOnTouch(onTouch)
# Menu items to display in the popup
items = ["Item 1", "Item 2", "Item 3"]
# Adds a menu passing the button control as anchor
menu = ui.addMenu(btn, items)
# Add a callback handler when a menu is touched
menu.setOnTouch(menuTouch)
def onTouch(event):
# show the menu
menu.show()
def menuTouch(item, icon, index):
ui.showPopup(item)
def OnStart():
global menu
# Creates a fullscreen layout with objects vertically centered.
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
# Adds a button control to the layout
btn = ui.addButton(main, "Show Menu", "Primary")
btn.setOnTouch(onTouch)
# Menu items to display in the popup
items = ["Item 1", "Item 2", "Item 3"]
# Adds a menu passing the button control as anchor
menu = ui.addMenu(btn, items)
# Add a callback handler when a menu is touched
menu.setOnTouch(menuTouch)
def onTouch(event):
# show the menu
menu.show()
def menuTouch(item, icon, index):
ui.showPopup(item)
Example - Changing anchor component click to expand contents
class Main extends App
{
onStart()
{
// Creates a fullscreen layout with objects vertically centered
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.main.childSpacing = "Even";
// Add a first button control to the layout
this.btn1 = ui.addButton(this.main, "Button 1", "Primary")
this.btn1.setOnTouch( this.onTouch1 )
// Add a second button control to the layout
this.btn2 = ui.addButton(this.main, "Button 2", "Secondary")
this.btn2.setOnTouch( this.onTouch2 )
// Menu items to display the menu popup
var items = ["Item 1", "Item 2", "Item 3"]
// Adds a menu without anchor component
this.menu = ui.addMenu(null, items)
// Add a callback handler when a menu is touched
this.menu.setOnTouch( this.menuTouch )
}
onTouch1()
{
// Show the menu on button 1
this.menu.show( this.btn1 )
}
onTouch2()
{
// Show the menu on button 2
this.menu.show( this.btn2 )
}
menuTouch( item )
{
ui.showPopup( item )
}
}
{
onStart()
{
// Creates a fullscreen layout with objects vertically centered
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.main.childSpacing = "Even";
// Add a first button control to the layout
this.btn1 = ui.addButton(this.main, "Button 1", "Primary")
this.btn1.setOnTouch( this.onTouch1 )
// Add a second button control to the layout
this.btn2 = ui.addButton(this.main, "Button 2", "Secondary")
this.btn2.setOnTouch( this.onTouch2 )
// Menu items to display the menu popup
var items = ["Item 1", "Item 2", "Item 3"]
// Adds a menu without anchor component
this.menu = ui.addMenu(null, items)
// Add a callback handler when a menu is touched
this.menu.setOnTouch( this.menuTouch )
}
onTouch1()
{
// Show the menu on button 1
this.menu.show( this.btn1 )
}
onTouch2()
{
// Show the menu on button 2
this.menu.show( this.btn2 )
}
menuTouch( item )
{
ui.showPopup( item )
}
}
from hybrid import ui
def OnStart():
global btn1, menu, btn2
# Creates a fullscreen layout with objects vertically centered
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
main.setChildSpacing("Evenly")
# Add a first button control to the layout
btn1 = ui.addButton(main, "Button 1", "Primary")
btn1.setOnTouch(onTouch1)
# Add a second button control to the layout
btn2 = ui.addButton(main, "Button 2", "Secondary")
btn2.setOnTouch(onTouch2)
# Menu items to display the menu popup
items = ["Item 1", "Item 2", "Item 3"]
# Adds a menu without anchor component
menu = ui.addMenu(None, items)
# Add a callback handler when a menu is touched
menu.setOnTouch(menuTouch)
def onTouch1(event):
# Show the menu on button 1
menu.show(btn1)
def onTouch2(event):
# Show the menu on button 2
menu.show(btn2)
def menuTouch(item, icon, index):
ui.showPopup(item)
def OnStart():
global btn1, menu, btn2
# Creates a fullscreen layout with objects vertically centered
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
main.setChildSpacing("Evenly")
# Add a first button control to the layout
btn1 = ui.addButton(main, "Button 1", "Primary")
btn1.setOnTouch(onTouch1)
# Add a second button control to the layout
btn2 = ui.addButton(main, "Button 2", "Secondary")
btn2.setOnTouch(onTouch2)
# Menu items to display the menu popup
items = ["Item 1", "Item 2", "Item 3"]
# Adds a menu without anchor component
menu = ui.addMenu(None, items)
# Add a callback handler when a menu is touched
menu.setOnTouch(menuTouch)
def onTouch1(event):
# Show the menu on button 1
menu.show(btn1)
def onTouch2(event):
# Show the menu on button 2
menu.show(btn2)
def menuTouch(item, icon, index):
ui.showPopup(item)
Example - With icons and disabled items click to expand contents
class Main extends App
{
onStart()
{
// Creates a fullscreen layout with objects vertically centered
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
// Add a button control to the main layout
this.btn = ui.addButton(this.main, "Show Menu", "Primary")
this.btn.setOnTouch( this.onTouch )
// List items with icons
var items = ["person:Item 1", "delete:Item 2", "favorite:Item 3"]
// Add a menu passing the btn as anchor component
this.menu = ui.addMenu(this.btn, items, "Icons,Primary,Dense")
// Disable the second menu item
this.menu.setEnabled(1, false)
// Add a callback handler when a menu is touched
this.menu.setOnTouch( this.menuTouch )
}
onTouch()
{
// show the menu
this.menu.show()
}
menuTouch( item )
{
// display the selected item
ui.showPopup( item )
}
}
{
onStart()
{
// Creates a fullscreen layout with objects vertically centered
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
// Add a button control to the main layout
this.btn = ui.addButton(this.main, "Show Menu", "Primary")
this.btn.setOnTouch( this.onTouch )
// List items with icons
var items = ["person:Item 1", "delete:Item 2", "favorite:Item 3"]
// Add a menu passing the btn as anchor component
this.menu = ui.addMenu(this.btn, items, "Icons,Primary,Dense")
// Disable the second menu item
this.menu.setEnabled(1, false)
// Add a callback handler when a menu is touched
this.menu.setOnTouch( this.menuTouch )
}
onTouch()
{
// show the menu
this.menu.show()
}
menuTouch( item )
{
// display the selected item
ui.showPopup( item )
}
}
from hybrid import ui
def OnStart():
global menu
# Creates a fullscreen layout with objects vertically centered
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
# Add a button control to the main layout
btn = ui.addButton(main, "Show Menu", "Primary")
btn.setOnTouch(onTouch)
# List items with icons
items = ["person:Item 1", "delete:Item 2", "favorite:Item 3"]
# Add a menu passing the btn as anchor component
menu = ui.addMenu(btn, items, "Icons,Primary,Dense")
# Disable the second menu item
menu.setEnabled(1, False)
# Add a callback handler when a menu is touched
menu.setOnTouch(menuTouch)
def onTouch(event):
# show the menu
menu.show()
def menuTouch(item, icon, index):
# display the selected item
ui.showPopup(item)
def OnStart():
global menu
# Creates a fullscreen layout with objects vertically centered
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
# Add a button control to the main layout
btn = ui.addButton(main, "Show Menu", "Primary")
btn.setOnTouch(onTouch)
# List items with icons
items = ["person:Item 1", "delete:Item 2", "favorite:Item 3"]
# Add a menu passing the btn as anchor component
menu = ui.addMenu(btn, items, "Icons,Primary,Dense")
# Disable the second menu item
menu.setEnabled(1, False)
# Add a callback handler when a menu is touched
menu.setOnTouch(menuTouch)
def onTouch(event):
# show the menu
menu.show()
def menuTouch(item, icon, index):
# display the selected item
ui.showPopup(item)
Example - Anchor position on mouse / touch click to expand contents
class Main extends App
{
onStart()
{
// Creates a fullscreen layout with objects vertically centered
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.main.setOnContextMenu( this.onMenu )
// Add a text control to the layout
this.txt = ui.addText(this.main, "Right click anywhere on the screen.\n(Long press if your on mobile phone)", "Multiline")
// List items with icons
var items = ["person:Item 1", "delete:Item 2", "favorite:Item 3"]
// Add menu passing the btn as anchor component
this.menu = ui.addMenu(null, items, "Icons,Dense")
// Add a callback handler when a menu is touched
this.menu.setOnTouch( this.menuTouch )
}
onMenu( pos )
{
// show the menu on the position of the mouse
this.menu.show(pos.x, pos.y)
}
menuTouch( item )
{
// display the selected item
ui.showPopup( item )
}
}
{
onStart()
{
// Creates a fullscreen layout with objects vertically centered
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.main.setOnContextMenu( this.onMenu )
// Add a text control to the layout
this.txt = ui.addText(this.main, "Right click anywhere on the screen.\n(Long press if your on mobile phone)", "Multiline")
// List items with icons
var items = ["person:Item 1", "delete:Item 2", "favorite:Item 3"]
// Add menu passing the btn as anchor component
this.menu = ui.addMenu(null, items, "Icons,Dense")
// Add a callback handler when a menu is touched
this.menu.setOnTouch( this.menuTouch )
}
onMenu( pos )
{
// show the menu on the position of the mouse
this.menu.show(pos.x, pos.y)
}
menuTouch( item )
{
// display the selected item
ui.showPopup( item )
}
}
class Main extends App
onStart()
# Creates a fullscreen layout with objects vertically centered
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.main.setOnContextMenu( this.onMenu )
# Add a text control to the layout
this.txt = ui.addText(this.main, "Right click anywhere on the screen.\n(Long press if your on mobile phone)", "Multiline")
# List items with icons
items = ["person:Item 1", "delete:Item 2", "favorite:Item 3"]
# Add menu passing the btn as anchor component
this.menu = ui.addMenu(null, items, "Icons,Dense")
# Add a callback handler when a menu is touched
this.menu.setOnTouch( this.menuTouch )
onMenu( pos )
# show the menu on the position of the mouse
this.menu.show(pos.x, pos.y)
menuTouch( item )
# display the selected item
ui.showPopup( item )
onStart()
# Creates a fullscreen layout with objects vertically centered
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.main.setOnContextMenu( this.onMenu )
# Add a text control to the layout
this.txt = ui.addText(this.main, "Right click anywhere on the screen.\n(Long press if your on mobile phone)", "Multiline")
# List items with icons
items = ["person:Item 1", "delete:Item 2", "favorite:Item 3"]
# Add menu passing the btn as anchor component
this.menu = ui.addMenu(null, items, "Icons,Dense")
# Add a callback handler when a menu is touched
this.menu.setOnTouch( this.menuTouch )
onMenu( pos )
# show the menu on the position of the mouse
this.menu.show(pos.x, pos.y)
menuTouch( item )
# display the selected item
ui.showPopup( item )
Properties
The following properties are available on the Menu object:
itemPadding → List
list → List
Methods
The following methods are available on the Menu object:
getEnabled(
index )
→ Boolean
getEnabledByName(
name )
→ Boolean
hide()
popItem()
setAutoFocus(
bool )