Garry's Mod Wiki

MatSelect

Description

The panel used by Material & Lamp Sandbox tools for texture selection. Despite being only used in Sandbox, it is not exclusive to that gamemode.

See also PropSelect for the prop selecting alternative.

View source

Parent

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

Implements

Implements or overrides the following hooks/methods. If you want to override these, you probably want to call the original function too.

Events

MatSelect:OnRightClick( Panel pnl )
Called when the player right clicks a material. By default, this opens a menu that lets the player copy the material path.
MatSelect:OnSelect( string material, Panel pnl )
Called when the player selects a material.
Defines a paint over function for a DImageButton when it is selected. self in the context of this function is the DImageButton!

Methods

MatSelect:AddMaterial( string label, string path )
Adds a new material to the selection list.
MatSelect:AddMaterialEx( string label, string path, any value, table convars )
Adds a new material to the selection list, with some extra options.
MatSelect:FindAndSelectMaterial( string mat )
Find a material and selects it, if it exists in this panel.
Find a DImageButton panel based on the input material path.
Returns whether the panel would set its own height to fit all materials within its height.
MatSelect:SelectMaterial( DImageButton mat )
This is used internally - although you're able to use it you probably shouldn't. Use MatSelect:FindAndSelectMaterial instead. Selects a given material panel.
MatSelect:SetAutoHeight( boolean autoSize )
Sets whether the panel should set its own height to fit all materials within its height.
MatSelect:SetItemHeight( number height )
Sets the height of a single material in pixels.
MatSelect:SetItemWidth( number width )
Sets the width of a single material in pixels.
MatSelect:SetNumRows( number rows )
Sets the target height of the panel, in number of rows.

Example

Example usage of the panel.

local frame = vgui.Create( "DFrame" ) frame:SetSize( 500, 500 ) frame:Center() frame:MakePopup() local MatSelect = vgui.Create( "MatSelect", frame ) MatSelect:Dock( TOP ) Derma_Hook( MatSelect.List, "Paint", "Paint", "Panel" ) -- MatSelect:SetConVar( "my_convar_name" ) MatSelect:SetAutoHeight( true ) MatSelect:SetItemWidth( 64 ) MatSelect:SetItemHeight( 64 ) local items = { "effects/flashlight001", "effects/flashlight/slit", "effects/flashlight/circles" } for k, material in pairs( items ) do MatSelect:AddMaterial( "Item #" .. k, material ) end function MatSelect:OnSelect( mat, pnl ) print( "Selected material: ", mat ) end
Output:
image.png