DComboBox

From GMod Wiki

Jump to: navigation, search
Warning 64 severe.pngThis 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

DescriptionCreates a list of options you can add to it then work with them later.
Used onNewerClient.png
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
 
OutputDComboBox.PNG


Additional Notes

Alternative Usage

DescriptionBy inserting this after the TestingComboBox the player can select each option on or off individually. Do not use with SetMultiple to true.
Used onNewerClient.png
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 
 
OutputN/A


Methods

NewerClient.png DComboBox.Clear
NewerClient.png DComboBox.Paint
NewerClient.png DComboBox.GetSelected
NewerClient.png DComboBox.Init
NewerClient.png DComboBox.SelectByName
NewerClient.png DComboBox.GetMultiple
NewerClient.png DComboBox.AddItem
NewerClient.png DComboBox.GenerateExample
NewerClient.png DComboBox.Rebuild
NewerClient.png DComboBox.SetMultiple
NewerClient.png DComboBox.SetSelectedItems
NewerClient.png DComboBox.SelectItem
NewerClient.png DComboBox.SetSelected
NewerClient.png DComboBox.GetSelectedItems

Inherited from DPanelList

NewerClient.png DPanelList.SizeToContents
NewerClient.png DPanelList.SetDrawBackground
NewerClient.png DPanelList.EnableHorizontal
NewerClient.png DPanelList.OnMouseWheeled
NewerClient.png DPanelList.GetItems
NewerClient.png DPanelList.GetAutoSize
NewerClient.png DPanelList.SetPadding
NewerClient.png DPanelList.OnVScroll
NewerClient.png DPanelList.SortByMember
NewerClient.png DPanelList.GetSpacing
NewerClient.png DPanelList.GetDrawBackground
NewerClient.png DPanelList.PerformLayout
NewerClient.png DPanelList.GetCanvas
NewerClient.png DPanelList.SetSpacing
NewerClient.png DPanelList.EnableVerticalScrollbar
NewerClient.png DPanelList.GetPadding
NewerClient.png DPanelList.RemoveItem
NewerClient.png DPanelList.OnMousePressed
NewerClient.png DPanelList.SetAutoSize

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox