-
-
Notifications
You must be signed in to change notification settings - Fork 29
Menus
This section describes the usage of the main menu bar. The main menu bar is rendered at the top of the window with menu items being added from left to right. When a menu item is clicked, a context menu is opened below the selected item. Creating the main menu bar can open anywhere in the code after the Slab.Update call. These functions should not be called within a BeginWindow/EndWindow call.
if Slab.BeginMainMenuBar() then
if Slab.BeginMenu("File") then
if Slab.BeginMenu("New") then
if Slab.MenuItem("File") then
-- Create a new file.
end
if Slab.MenuItem("Project") then
-- Create a new project.
end
Slab.EndMenu()
end
Slab.MenuItem("Open")
Slab.MenuItem("Save")
Slab.MenuItem("Save As")
Slab.Separator()
if Slab.MenuItem("Quit") then
love.event.quit()
end
Slab.EndMenu()
end
end
These are menus which are rendered above all other controls to allow the user to make a selection out of a list of items. These can be opened up through the menu bar, or through a right-click action from the user on a given window or control. Menus and menu items make up the context menu and menus can be nested to allow a tree options to be displayed.
-- This is placed outside of a BeginWindow/EndWindow call for context menus in the void space.
if Slab.BeginContextMenuWindow() then
Slab.MenuItem("Global Item 1")
Slab.MenuItem("Global Item 2")
if Slab.BeginMenu("Global Item 3") then
Slab.MenuItem("Sub Item 1")
Slab.MenuItem("Sub Item 2")
Slab.EndMenu()
end
Slab.EndContextMenu()
end
Below is an example of creating context menus for different controls of a window.
Slab.Button("My Button 1")
if Slab.BeginContextMenuItem() then
Slab.MenuItem("My Button 1 Item 1")
Slab.MenuItem("My Button 1 Item 2")
Slab.EndContextMenu()
end
Slab.Button("My Button 2")
if Slab.BeginContextMenuItem() then
Slab.MenuItem("My Button 2 Item 1")
Slab.MenuItem("My Button 2 Item 2")
Slab.EndContextMenu()
end
Below is an example of a context menu specific for a window.
Slab.BeginWindow('MyFirstWindow', {Title = "My First Window"})
Slab.Button("My Button")
if Slab.BeginContextMenuWindow() then
Slab.MenuItem("My Window Item 1")
Slab.MenuItem("My Window Item 2")
Slab.EndContextMenu()
end
Slab.EndWindow()
Menu items make up the contents of a context menu. When a menu item is clicked, the function will return true. There are currently two types of menu items supported. They are the standard menu items and a checked menu item.
