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

1
ImGui.SetNextWindowPos(100, 500, ImGuiCond.FirstUseEver) -- set window position x, y
2
ImGui.SetNextWindowSize(300, 600, ImGuiCond.Appearing) -- set window size w, h
3
4
if ImGui.Begin("Unique Window Name") then
5
ImGui.Text("Hello World")
6
-- more window contents here
7
end
8
ImGui.End()
Copied!

Modal/Popup Window

1
if ImGui.Button("Pop Button", 120, 0) then
2
ImGui.OpenPopup("Delete?")
3
end
4
5
if ImGui.BeginPopupModal("Delete?", true, ImGuiWindowFlags.AlwaysAutoResize) then
6
ImGui.Text("This is a popup")
7
8
if ImGui.Button("Close") then ImGui.CloseCurrentPopup() end
9
ImGui.EndPopup()
10
end
Copied!

Combo Box with Selectables

1
local DropdownOptions = {"1", "2", "3", "4", "5"}
2
local DropdownSelected = "1"
3
4
if ImGui.BeginCombo("##My Combo Box", DropdownSelected) then -- Remove the ## if you'd like for the title to display above combo box
5
6
for i, option in ipairs(DropdownSelected) do
7
8
if ImGui.Selectable(option, (option == DropdownSelected)) then
9
DropdownSelected = option
10
ImGui.SetItemDefaultFocus()
11
end
12
13
end
14
15
ImGui.EndCombo()
16
end
Copied!

Button

1
if ImGui.Button("Click Me!", 100, 20) then -- Label, width, height - Use -1 as width for button to span available horizontal space
2
-- do stuff here when button is clicked
3
end
Copied!
1
registerForEvent("onUpdate", function()
2
if btn then
3
print("You pressed me!")
4
emd
5
end)
6
7
registerForEvent("onDraw", function()
8
btn = ImGui.Button("Click me I'm a Sexy Button", 250, 25)
9
end)
Copied!
Last modified 8mo ago