UI Examples
This page contains examples for creating UI for your mod using the built-in ImGui library.Everything you need to know about Dear ImGui can be found here and here.
Basic Window
ImGui.SetNextWindowPos(100, 500, ImGuiCond.FirstUseEver) -- set window position x, yImGui.SetNextWindowSize(300, 600, ImGuiCond.Appearing) -- set window size w, hif ImGui.Begin("Unique Window Name") thenImGui.Text("Hello World")-- more window contents hereendImGui.End()
Modal/Popup Window
if ImGui.Button("Pop Button", 120, 0) thenImGui.OpenPopup("Delete?")endif ImGui.BeginPopupModal("Delete?", true, ImGuiWindowFlags.AlwaysAutoResize) thenImGui.Text("This is a popup")if ImGui.Button("Close") then ImGui.CloseCurrentPopup() endImGui.EndPopup()end
Combo Box with Selectables
local DropdownOptions = {"1", "2", "3", "4", "5"}local DropdownSelected = "1"if ImGui.BeginCombo("##My Combo Box", DropdownSelected) then -- Remove the ## if you'd like for the title to display above combo boxfor i, option in ipairs(DropdownSelected) doif ImGui.Selectable(option, (option == DropdownSelected)) thenDropdownSelected = optionImGui.SetItemDefaultFocus()endendImGui.EndCombo()end
Button
if ImGui.Button("Click Me!", 100, 20) then -- Label, width, height - Use -1 as width for button to span available horizontal space-- do stuff here when button is clickedendregisterForEvent("onUpdate", function()if btn thenprint("You pressed me!")emdend)registerForEvent("onDraw", function()btn = ImGui.Button("Click me I'm a Sexy Button", 250, 25)end)
Last updated