cLib.DModal

VGUI - Advanced Updated: Dec 10, 2025

cLib.DModal

Modal dialogs with animations (Alert, Confirm, Prompt).

Quick Functions

Alert

Simple notification with OK button.

cLib.Alert(title, message, buttonText, callback)
cLib.Alert("Notice", "Operation completed!", "OK", function()
    print("Alert closed")
end)

-- Simple version
cLib.Alert("Success", "Item purchased!")

Confirm

Yes/No confirmation dialog.

cLib.Confirm(title, message, onConfirm, onCancel)
cLib.Confirm("Delete", "Are you sure you want to delete this item?",
    function()
        DeleteItem()
        print("Deleted!")
    end,
    function()
        print("Cancelled")
    end
)

Prompt

Text input dialog.

cLib.Prompt(title, message, placeholder, default, onSubmit, onCancel)
cLib.Prompt("Rename", "Enter new name:", "Name", "Item",
    function(value)
        if value and value ~= "" then
            RenameItem(value)
        end
    end
)

Custom Modal

local modal = vgui.Create("cLib.DModal")
modal:SetTitle("Custom Dialog")
modal:SetMessage("This is a custom modal with multiple options.")
modal:SetIcon("icon64/info.png")  -- Optional large icon

-- Add buttons (text, callback, isPrimary)
modal:AddButton("Cancel", nil, false)
modal:AddButton("Skip", function() SkipStep() end, false)
modal:AddButton("Continue", function() NextStep() end, true)

Methods

MethodDescription
SetTitle(string)Modal title
SetMessage(string)Modal message
SetIcon(path)Large icon (64x64)
AddButton(text, callback, primary)Add button
Close()Close modal

Styling

local modal = vgui.Create("cLib.DModal")
modal:SetTitle("Warning")
modal:SetMessage("This action cannot be undone!")

-- Custom colors
modal:SetBackgroundColor(Color(40, 40, 45))
modal:SetTitleColor(cLib.GetColor("cLib.warning"))
modal:SetMessageColor(Color(200, 200, 200))

modal:AddButton("Cancel")
modal:AddButton("Delete", function() Delete() end, true)

Chained Confirmations

function ConfirmDangerousAction()
    cLib.Confirm("Warning", "This will reset all data. Continue?",
        function()
            cLib.Confirm("Final Warning", "This CANNOT be undone! Are you absolutely sure?",
                function()
                    ResetAllData()
                    cLib.Alert("Done", "All data has been reset.")
                end
            )
        end
    )
end