DMenu.AddSubMenu

From GMod Wiki

Jump to: navigation, search
Function
Syntax DMenu:AddSubMenu( String name )
Description:
Adds a sub menu to a DMenu.
Returns: Panel DMenu
Realm: NewerClient.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=DMenu.AddSubMenu]DMenu.AddSubMenu [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionCreates a menu with a submenu which has options to print each players name.
Used onNewerClient.png
Code
 
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 200, 250 )
DermaPanel:SetTitle( "Testing Derma Stuff" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
 
local MenuButton = vgui.Create("DButton")
MenuButton:SetParent( DermaPanel )
MenuButton:SetText( "Menu >" )
MenuButton:SetPos(25, 50)
MenuButton:SetSize( 150, 175 )
function MenuButton:DoClick()
    local Menu = DermaMenu()
    local SubMenu = Menu:AddSubMenu("Players")
    for _,ply in pairs(player.GetAll()) do
        SubMenu:AddOption(ply:Name(),function() print(ply:Name()) end)
    end
    MenuButtonOptions:Open() -- Open the menu AFTER adding your options
end
 
OutputN/A
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox