Garry's Mod Wiki

DNotify

Description

A panel that fades its contents in and out once, like a notification.

View source

Parent

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

Methods

DNotify:AddItem( Panel pnl, number lifeLength = nil )
Adds a panel to the notification
Returns the current alignment of this notification panel. Set by DNotify:SetAlignment.
table DNotify:GetItems()
Returns all the items added with DNotify:AddItem.
number DNotify:GetLife()
Returns the display time in seconds of the DNotify. This is set with DNotify:SetLife.
number DNotify:GetSpacing()
Returns the spacing between items set by DNotify:SetSpacing.
DNotify:SetAlignment( number alignment )
Sets the alignment of the child panels in the notification
DNotify:SetLife( number time )
Sets the display time in seconds for the DNotify.
DNotify:SetSpacing( number spacing )
Sets the spacing between child elements of the notification panel.
DNotify:Shuffle()
This is used internally - although you're able to use it you probably shouldn't. Used internally to position and fade in/out its DNotify:GetItems.

Example

Creates a notification panel with a text label inside.

--Notification panel local NotifyPanel = vgui.Create("DNotify") NotifyPanel:SetPos(10, 5) NotifyPanel:SetSize(200, 40) -- Text label local lbl = vgui.Create("DLabel", NotifyPanel) lbl:Dock(FILL) lbl:SetText("This is a notification.") lbl:SetFont("GModNotify") lbl:SetDark(true) -- Add the label to the notification and begin fading NotifyPanel:AddItem(lbl)

Example

Creates a notification panel of Dr. Kleiner reminding the player to wear their HEV suit.

-- Notification panel local NotifyPanel = vgui.Create("DNotify") NotifyPanel:SetPos(15, 15) NotifyPanel:SetSize(150, 210) -- Gray background panel local bg = vgui.Create("DPanel", NotifyPanel) bg:Dock(FILL) bg:SetBackgroundColor(Color(64, 64, 64)) -- Image of Dr. Kleiner (parented to background panel) local img = vgui.Create("DImage", bg) img:SetPos(11, 11) img:SetSize(128, 128) img:SetImage("entities/npc_kleiner.png") -- A yellow label message (parented to background panel) local lbl = vgui.Create("DLabel", bg) lbl:SetPos(11, 136) lbl:SetSize(128, 72) lbl:SetText("Remember to wear your HEV suit!") lbl:SetTextColor(Color(255, 200, 0)) lbl:SetFont("GModNotify") lbl:SetWrap(true) -- Add the background panel to the notification NotifyPanel:AddItem(bg)
Output: