Contents

What is Derma?

Derma was created by Garry and TAD2020 and is the easiest way to create on-screen menus for your gamemode or addon.

Derma differs from vgui in that its code only needs to be run once, therefore you should NEVER put Derma code inside
GM:HUDPaint or similar function, as these are called each frame. To make your life easier, you should wrap your Derma code in a function and then call it whenever you need to create a menu and always use local variables. If you must use a global pointer, make it specific or a table member. DLabel = vgui.Create( "DLabel" ) is bad coding practice and will likely override something.

Derma is clientside and if you would like to like to call it from the server, you will have to use the net library.

Because of the age of Derma, some elements are broken or deprecated in Garry's Mod 13 like the DLabelURL and DPanelList. The majority of the Derma pages on this wiki lead to functional panels.

Starting off

The very first thing you should do is create a DFrame as this will be your canvas, so to speak, for placing Derma on.

Output

Painting Derma

What is it?

As useful as Derma is for the Lua coder, its ugly as sin and sometimes you want a really nice looking menu. You can solve this by overriding the panel's Paint function which you can do on every single Derma element. Overriding the function means that the panel will be invisible until you draw something on it; if you would like to draw on the current panel you might try the PANEL:PaintOver function.

Output

User Inputs

Your Derma menus might not be of much use if you don't know how to grab data from them; whether it would be user-typed text, a button click, or a checkbox.

Let's create a DTextEntry so the player can input their name and when they press enter! We can then assign the entered value to a variable to reference later or even use the net library and send their name to the server for saving.

Output

Scaling

What is it?

Not everyone who plays Garry's Mod has the same resolution or monitor size as you and as such you should create your Derma to work on nearly everyone's monitors. You can accomplish this by using the ScrH and ScrW functions which return their respective dimensions as integers. This is not necessarily something you have to worry about when you start your project as working with constant sizes is quicker, but this is very important if your Derma is quite large.

How do I do it?

The first thing you need to do is figure out your monitor resolution, mine is 1920 x 1080 and I'll use that for this tutorial. The easiest way to find your resolution is just to use print and the screen size functions.

Now assume we created this frame and we want it to be in the center of the player's screen and be sized accordingly

MyFrame:SetSize( 400, 300 )

To do this in an efficient way, we can simply put a math into the Panel:SetSize method dividing the size we want by our screen resolution and using the ScrW and ScrH functions:

MyFrame:SetSize( ScrW() * 400/1920, ScrH() * 300/1080 )

Now this DFrame will be 400x300 on your resolution and it will size on any other resolution. You could then scale a DButton on this frame by dividing its size by the frame's size and it will scale according to it's parent.

It is recommended to replace static calculations later with the calculated values to reduce unnecessary operations in rendering code:

MyFrame:SetSize( ScrW() * 0.208, ScrH() * 0.277 )

Resources

Unfortunately, due to the large amount of functions in Derma not all of them are documented yet, but you can search through the source code yourself and figure out how those functions work!
You can find an online repository here: https://github.com/garrynewman/garrysmod/tree/master/garrysmod/lua/vgui or look in garrysmod\lua\vgui in your local Garry's Mod directory.