cLib.DTooltip
Custom tooltips for panels.
Quick Function
cLib.SetTooltip(panel, text, delay)local button = vgui.Create("cLib.DButton", parent)
button:SetText("Save")
-- Add tooltip (0.5 second delay)
cLib.SetTooltip(button, "Save your changes", 0.5)Multi-line Tooltip
cLib.SetTooltip(button, "Line 1\nLine 2\nLine 3")Styled Tooltip
local tooltip = vgui.Create("cLib.DTooltip")
tooltip:SetText("This is a tooltip")
tooltip:SetBackgroundColor(Color(30, 30, 35, 240))
tooltip:SetTextColor(Color(220, 220, 220))
tooltip:SetFont("cLib.Tooltip")
tooltip:PositionNear(targetPanel)Button with Tooltip
function CreateIconButton(parent, icon, tooltip, onClick)
local btn = vgui.Create("cLib.DIconButton", parent)
btn:SetIcon(icon)
btn.DoClick = onClick
cLib.SetTooltip(btn, tooltip, 0.3)
return btn
end
-- Usage
local saveBtn = CreateIconButton(toolbar, "icon16/disk.png", "Save (Ctrl+S)", function()
Save()
end)
local undoBtn = CreateIconButton(toolbar, "icon16/arrow_undo.png", "Undo (Ctrl+Z)", function()
Undo()
end)Tooltips on List Items
local list = vgui.Create("cLib.DListView", parent)
list:AddColumn("Item")
list:AddColumn("Status")
for _, item in ipairs(items) do
local line = list:AddLine(item.name, item.status)
-- Add tooltip to row
cLib.SetTooltip(line, item.description, 0.5)
endRich Tooltip
-- Create custom tooltip panel
function ShowRichTooltip(parent, data)
local tooltip = vgui.Create("DPanel")
tooltip:SetSize(cLib.Scale(200), cLib.Scale(100))
tooltip.Paint = function(s, w, h)
draw.RoundedBox(4, 0, 0, w, h, Color(30, 30, 35, 250))
end
local title = vgui.Create("DLabel", tooltip)
title:SetText(data.name)
title:SetFont("cLib.SubTitle")
title:Dock(TOP)
title:DockMargin(cLib.Scale(10), cLib.Scale(5), 0, 0)
local desc = vgui.Create("DLabel", tooltip)
desc:SetText(data.description)
desc:SetFont("cLib.Small")
desc:SetTextColor(Color(150, 150, 150))
desc:Dock(TOP)
desc:DockMargin(cLib.Scale(10), cLib.Scale(5), 0, 0)
desc:SetWrap(true)
-- Position near cursor
local x, y = input.GetCursorPos()
tooltip:SetPos(x + 15, y + 15)
return tooltip
end