Garry's Mod Wiki

DMenu

Description

A simple menu with sub menu, icon and convar support.

View source

Parent

Derives methods, etc not listed on this page from DScrollPanel.

Methods

Panel DMenu:AddCVar( string strText, string convar, string on, string off, function funcFunction = nil )
Creates a DMenuOptionCVar and adds it as an option into the menu. Checking and unchecking the option will alter the given console variable's value.
Panel DMenu:AddOption( string name, function func = nil )
Add an option to the DMenu
DMenu:AddPanel( Panel pnl )
Adds a panel to the DMenu as if it were an option. This invokes DScrollPanel:AddItem and will not create a new panel if a class name is passed, unlike Panel:Add.
DMenu:AddSpacer()
Adds a horizontal line spacer.
Panel, Panel DMenu:AddSubMenu( string Name, function func = nil )
Add a sub menu to the DMenu
Returns the number of child elements of DMenu's DScrollPanel:GetCanvas.
We advise against using this. It may be changed or removed in a future update. Clears all highlights made by DMenu:HighlightItem. Doesn't appear to be used or do anything.
DMenu:CloseSubMenu( Panel menu )
This is used internally - although you're able to use it you probably shouldn't. Used internally by DMenu:OpenSubMenu.
DMenu:GetChild( number childIndex )
Gets a child by its index.
We advise against using this. It may be changed or removed in a future update. Set by DMenu:SetDeleteSelf
We advise against using this. It may be changed or removed in a future update. Returns the value set by DMenu:SetDrawBorder.
Returns whether the DMenu should draw the icon column with a different color or not. See DMenu:SetDrawColumn
Returns the maximum height of the DMenu.
Returns the minimum width of the DMenu in pixels
This is used internally - although you're able to use it you probably shouldn't. Returns the currently opened submenu. Used internally to store the open submenu by DMenu:Hide, DMenu:OpenSubMenu.
DMenu:Hide()
Used to safely hide (not remove) the menu. This will also hide any opened submenues recursively.
DMenu:HighlightItem( Panel item )
We advise against using this. It may be changed or removed in a future update. Highlights selected item in the DMenu by setting the item's key "Highlight" to true. Doesn't appear to be working or used.
DMenu:Open( number x = gui.MouseX(), number y = gui.MouseY(), any skipanimation = nil, Panel ownerpanel = nil )
Opens the DMenu at the current mouse position
DMenu:OpenSubMenu( Panel item, Panel menu = nil )
Closes any active sub menus, and opens a new one.
DMenu:OptionSelected( Panel option, string optionText )
Called when a option has been selected
DMenu:OptionSelectedInternal( Panel option )
This is used internally - although you're able to use it you probably shouldn't. Called by DMenuOption. Calls DMenu:OptionSelected.
DMenu:SetDeleteSelf( boolean newState )
Set to true by default. IF set to true, the menu will be deleted when it is closed, not simply hidden. This is used by DMenuBar
DMenu:SetDrawBorder( boolean bool )
We advise against using this. It may be changed or removed in a future update. Does nothing.
DMenu:SetDrawColumn( boolean draw )
Sets whether the DMenu should draw the icon column with a different color.
DMenu:SetMaxHeight( number maxHeight )
Sets the maximum height the DMenu can have. If the height of all menu items exceed this value, a scroll bar will be automatically added.
DMenu:SetMinimumWidth( number minWidth )
Sets the minimum width of the DMenu. The menu will be stretched to match the given value.
DMenu:SetOpenSubMenu( Panel item )
This is used internally - although you're able to use it you probably shouldn't. Used internally to store the open submenu by DMenu:Hide, DMenu:OpenSubMenu, DMenu:CloseSubMenu

Example

Creates a DMenu with a submenu.

local Menu = DermaMenu() -- Add a simple option. Menu:AddOption( "Simple option" ) -- Simple option, but we're going to add an icon local btnWithIcon = Menu:AddOption( "Option with icon" ) btnWithIcon:SetIcon( "icon16/bug.png" ) -- Icons are in materials/icon16 folder -- Adds a simple line spacer Menu:AddSpacer() -- Add a submenu local SubMenu = Menu:AddSubMenu( "A Sub Menu" ) SubMenu:AddOption( "Sub Option #1" ):SetIcon( "icon16/group.png" ) -- Add a submenu with icon local Child, Parent = Menu:AddSubMenu( "A Sub Menu with Icon" ) Parent:SetIcon( "icon16/arrow_refresh.png" ) Child:AddOption( "Sub Option #2" ):SetIcon( "icon16/group.png" ) -- Open the menu Menu:Open()
gmod_GRSjcD2QhQ.png