From GMod Wiki
| This element will function like DMultiChoice once the GMod Beta 13 update becomes public |
Derma Control: DComboBox |
Parent Class: | DPanelList |
Subclasses: | |
Description: |
A list of options that a user can select from. |
Examples
Description | Creates a list of options you can add to it then work with them later. |
Used on | |
Code |
local TestingComboBox = vgui.Create( "DComboBox", FrameParent )
TestingComboBox:SetPos( 10, 35 )
TestingComboBox:SetSize( 100, 185 )
TestingComboBox:SetMultiple( false )
TestingComboBox:AddItem( "Add" ) -- Add our options
TestingComboBox:AddItem( "Some" )
TestingComboBox:AddItem( "Options" )
TestingComboBox:AddItem( "Here" )
--We create a panel so we can draw on; if we use the frame, it comes up transparent for some reason.
local MainMenuSheet = vgui.Create( "DPanel", FrameParent )
MainMenuSheet:SetPos( 125, 50 )
MainMenuSheet:SetSize( DermaFrame:GetWide() - 25, DermaFrame:GetTall() - 25 )
MainMenuSheet.Paint = function()
--Make sure something is selected if not we get uber spam of errors.
if TestingComboBox:GetSelectedItems() and TestingComboBox:GetSelectedItems()[1] then
-- This was a pain in the ass to figure out; this gets the name of the option chosen.
local myString = "Your selection is: "..TestingComboBox:GetSelectedItems()[1]:GetValue().."!"
surface.SetFont( "default" )
surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos( 50, 50 )
surface.DrawText( myString ) -- Draws the text
end
end
|
Output | |
Additional Notes
- The current implementation of a combo box makes it almost the same as a drop down menu. If you use SetMultiple to true the player can select multiples ONLY by dragging their mouse down on the options. This means options have to be sequential for the player to select them.
Alternative Usage
Description | By inserting this after the TestingComboBox the player can select each option on or off individually. Do not use with SetMultiple to true. |
Used on | |
Code |
--Author:Lap
function TestingComboBox:SelectItem( item, onlyme )
if ( !onlyme && item:GetSelected() ) then return end
self.m_pSelected = item
if item:GetSelected() == true then
item:SetSelected( false )
for k, v in pairs (self.SelectedItems) do
if v == item then
table.remove(self.SelectedItems, k)
end
end
else
item:SetSelected( true )
table.insert( self.SelectedItems, item )
end
end
|
Output | N/A |
Methods
DComboBox.Clear
DComboBox.Paint
DComboBox.GetSelected
DComboBox.Init
DComboBox.SelectByName
DComboBox.GetMultiple
DComboBox.AddItem
DComboBox.GenerateExample
DComboBox.Rebuild
DComboBox.SetMultiple
DComboBox.SetSelectedItems
DComboBox.SelectItem
DComboBox.SetSelected
DComboBox.GetSelectedItems
DPanelList.SizeToContents
DPanelList.SetDrawBackground
DPanelList.EnableHorizontal
DPanelList.OnMouseWheeled
DPanelList.GetItems
DPanelList.GetAutoSize
DPanelList.SetPadding
DPanelList.OnVScroll
DPanelList.SortByMember
DPanelList.GetSpacing
DPanelList.GetDrawBackground
DPanelList.PerformLayout
DPanelList.GetCanvas
DPanelList.SetSpacing
DPanelList.EnableVerticalScrollbar
DPanelList.GetPadding
DPanelList.RemoveItem
DPanelList.OnMousePressed
DPanelList.SetAutoSize