Could someone link me to a example of a custom combobox that possibly uses mouse positioning or a reskinned button or default combobox. Also if anyone knows how to use a custom font WITHIN the combobox menu options then that would be great
[B]About how to change the font for the ComboBox:[/B]
Well, the code for the default combobox is [URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/dcombobox.lua"]here[/URL], and if you look at the OpenMenu function it uses, [URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/dcombobox.lua#L161"]you can see it creates a derma menu and uses that[/URL], and if you do a bit more backtracking you will find that a derma menu is actually just a DMenu.
After a bit more backtracking you'll find that the DMenu uses a [URL="https://github.com/garrynewman/garrysmod/blob/4497d57a7f792a4a683b37a641dee1313bfe0452/garrysmod/lua/vgui/dmenuoption.lua"]DMenuOption[/URL] for it's text, which I think can have the font changed on it. I'll try to make an example since all this is very confusing
EDIT: Here's how you can change the font- annoyingly I had to copy the entire Open function of the menu just to get it to work:
[CODE]
local f = vgui.Create('DFrame') -- A frame just for example
f:SetSize(500,500)
f:Center()
f:MakePopup()
local ctrl = vgui.Create( 'DComboBox', f ) -- The box
ctrl:AddChoice( "Some Choice" )
ctrl:AddChoice( "Another Choice" )
ctrl:Dock(TOP)
ctrl:SetFont( 'DermaLarge' ) -- Change this to whatever font you want
function ctrl:OpenMenu( pControlOpener )
if ( pControlOpener && pControlOpener == self.TextEntry ) then
return
end
if ( #self.Choices == 0 ) then return end
if ( IsValid( self.Menu ) ) then
self.Menu:Remove()
self.Menu = nil
end
self.Menu = DermaMenu( false, self )
local sorted = {}
for k, v in pairs( self.Choices ) do table.insert( sorted, { id = k, data = v } ) end
for k, v in SortedPairsByMemberValue( sorted, "data" ) do
local p = self.Menu:AddOption( v.data, function() self:ChooseOption( v.data, v.id ) end )
p:SetFont( self:GetFont() ) -- THIS IS ALL I NEEDED TO ADD
end
local x, y = self:LocalToScreen( 0, self:GetTall() )
self.Menu:SetMinimumWidth( self:GetWide() )
self.Menu:Open( x, y, false, self )
end
[/CODE]
[B]About the custom combobox:[/B]
I don't know what you mean about mouse positioning, the default combobox already does that- if you mean create a combobox at the mouse position. Also, to reskin the buttons I think you need to [URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/skins/default.lua"]make a custom derma skin[/URL] or just override some of the functions in the old one since that's what the combox uses to draw... really, it'd be much simpler to just copy the old combobox file which I mentioned before and just change whatever about it you want, such as the paint function to not use the skin file
Sorry, you need to Log In to post a reply to this thread.