Garry's Mod Wiki

DFrame

Description

The DFrame is the moma of basically all VGUI elements. 98% of the time you will parent your element to this.

View source

Parent

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

Events

DFrame:OnClose()
Called when the DFrame is closed with DFrame:Close. This applies when the close button in the DFrame's control box is clicked. This function does nothing and is safe to override. This is not called when the DFrame is removed with Panel:Remove, see PANEL:OnRemove for that.

Methods

DFrame:Center()
Centers the frame relative to the whole screen and invalidates its layout. This overrides Panel:Center.
DFrame:Close()
Hides or removes the DFrame, and calls DFrame:OnClose. To set whether the frame is hidden or removed, use DFrame:SetDeleteOnClose.
Gets whether the background behind the frame is being blurred.
Determines whether or not the DFrame will be removed when it is closed. This is set with DFrame:SetDeleteOnClose.
Gets whether or not the frame is draggable by the user.
Gets whether or not the frame is part of a derma menu. This is set with DFrame:SetIsMenu.
Gets the minimum height the DFrame can be resized to by the user. You must call DFrame:SetSizable before the user can resize the frame.
Gets the minimum width the DFrame can be resized to by the user. You must call DFrame:SetSizable before the user can resize the frame.
Gets whether or not the shadow effect bordering the DFrame is being drawn.
Gets whether or not the DFrame is restricted to the boundaries of the screen resolution.
Gets whether or not the DFrame can be resized by the user. This is achieved by clicking and dragging in the bottom right corner of the frame.
string DFrame:GetTitle()
Returns the title of the frame.
boolean DFrame:IsActive()
Determines if the frame or one of its children has the screen focus.
DFrame:SetBackgroundBlur( boolean blur )
Indicate that the background elements won't be usable.
DFrame:SetDeleteOnClose( boolean shouldDelete )
Determines whether or not the DFrame is removed when it is closed with DFrame:Close.
DFrame:SetDraggable( boolean draggable )
Sets whether the frame should be draggable by the user. The DFrame can only be dragged from its title bar.
DFrame:SetIcon( string path )
Adds or removes an icon on the left of the DFrame's title.
DFrame:SetIsMenu( boolean isMenu )
Sets whether the frame is part of a derma menu or not. If this is set to true, CloseDermaMenus will not be called when the frame is clicked, and thus any open menus will remain open.
DFrame:SetMinHeight( number minH )
Sets the minimum height the DFrame can be resized to by the user. This only applies to users attempting to resize the frame; Panel:SetTall and similar methods will not be affected. You must call DFrame:SetSizable before the user can resize the frame.
DFrame:SetMinWidth( number minW )
Sets the minimum width the DFrame can be resized to by the user. This only applies to users attempting to resize the frame; Panel:SetWide and similar methods will not be affected. You must call DFrame:SetSizable before the user can resize the frame.
DFrame:SetPaintShadow( boolean shouldPaint )
Sets whether or not the shadow effect bordering the DFrame should be drawn.
DFrame:SetScreenLock( boolean lock )
Sets whether the DFrame is restricted to the boundaries of the screen resolution.
DFrame:SetSizable( boolean sizeable )
Sets whether or not the DFrame can be resized by the user. This is achieved by clicking and dragging in the bottom right corner of the frame. You can set the minimum size using DFrame:SetMinWidth and DFrame:SetMinHeight.
DFrame:SetTitle( string title )
Sets the title of the frame.
DFrame:ShowCloseButton( boolean show )
Determines whether the DFrame's control box (close, minimise and maximise buttons) is displayed.

Example

Creates a basic DFrame.

concommand.Add( "open_frame", function() local DFrame = vgui.Create("DFrame") -- The name of the panel we don't have to parent it. DFrame:SetPos(100, 100) -- Set the position to 100x by 100y. DFrame:SetSize(300, 200) -- Set the size to 300x by 200y. DFrame:SetTitle("Derma Frame") -- Set the title in the top left to "Derma Frame". DFrame:MakePopup() -- Makes your mouse be able to move around. end )
dpanel_example.png

Example

Create an advanced customized DFrame.

-- Then font named "Font" compacted on one line. surface.CreateFont("Font", { font = "Arial", extended = true, size = 20 }) local faded_black = Color(0, 0, 0, 200) -- The color black but with 200 Alpha concommand.Add( "open_frame", function() local DermaPanel = vgui.Create("DFrame") -- The name DermaPanel to store the value DFrame. DermaPanel:SetSize(500, 300) -- Sets the size to 500x by 300y. DermaPanel:Center() -- Centers the panel. DermaPanel:SetTitle("") -- Set the title to nothing. DermaPanel:SetDraggable(false) -- Makes it so you can't drag it. DermaPanel:MakePopup() -- Makes it so you can move your mouse on it. -- Paint function w, h = how wide and tall it is. DermaPanel.Paint = function(self, w, h) -- Draws a rounded box with the color faded_black stored above. draw.RoundedBox(2, 0, 0, w, h, faded_black) -- Draws text in the color white. draw.SimpleText("Derma Frame", "Font", 250, 5, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP) end end )
dframe_paint.png