Windows, buttons, sliders, tabs, tables: Dear ImGui for mods, and the mod menu.
Mods build menus with Dear ImGui widgets. Widgets go inside ui.window(title, fn) (a window drawn in the draw
event) or inside ui.panel(title, fn) (a tab of the mod menu, F1). ImGui is immediate mode : your function runs every
frame and draws the widgets anew; a widget's return value tells you what the player did this frame. Keep your state in
your own variables:
copy local god = false
ui .panel("Cheats" , function ()
god = ui .checkbox("God mode" , god)
world .god(god)
if ui .button("Kill everything" ) then world .killAll() end
end )
During a hunt the mouse turns the view; a window the player should click needs ui.cursor(true) (shows the cursor,
pauses mouse look) and ui.cursor(false) afterwards. Window titles are kept apart per mod automatically. Widgets with
the same label in one window need ui.id or a "label##unique" suffix (ImGui shows the part before ##).
# ui.window (title , fn , options? ) → boolean
A window. Call it from a draw handler every frame it should show.
Parameter Type
titlestring window title (also its identity)
fnfunction draws the widgets
options optional table x, y, w, h (first placement; with fixed = true every frame), alpha, closable, noTitle, noResize, noMove, noScroll, autoResize, noBackground, noInput, noCollapse, noFocus
Returns
boolean false when the player closed it (closable windows)
copy local shopOpen = true
on ("draw" , function ()
if not shopOpen then return end
shopOpen = ui .window("Shop" , function ()
ui .text("Credits: 500" )
if ui .button("Buy ammo" ) then buyAmmo() end
end , {x = 40 , y = 120 , w = 260 , h = 160 , closable = true })
end )
# ui.panel (title , fn )
Adds a tab to the mod menu (F1). Call once (e.g. at load); the function runs every frame the tab is shown. Calling again with the same title replaces it.
Parameter Type
titlestring tab title
fnfunction draws the tab's widgets
# ui.removePanel (title )
Removes one of your mod menu tabs.
Parameter Type
titlestring
# ui.cursor (on )
Shows the mouse cursor during a hunt (mouse look pauses) so your windows can be clicked.
# ui.toast (text , seconds? , color? )
A short message at the bottom right.
Parameter Type
textstring
seconds optional number default 4
color optional Color
# ui.screen () → number, number
The window size in UI units.
Returns
number width
number height
# ui.text (... )
Parameter Type
...any values joined by spaces
copy ui .text("Health:" , math.floor(c.health))
# ui.textWrapped (text )
Text wrapped at the window edge.
# ui.heading (text )
A separator line with a title.
# ui.checkbox (label , value ) → boolean, boolean
Parameter Type
labelstring
valueboolean current value
Returns
boolean the value (changed when clicked)
boolean true when it changed
copy enabled = ui .checkbox("Enabled" , enabled)
# ui.radio (label , active ) → boolean
Parameter Type
labelstring
activeboolean whether this option is the chosen one
copy if ui .radio("Easy" , level == 1 ) then level = 1 end
ui .sameLine()
if ui .radio("Hard" , level == 2 ) then level = 2 end
# ui.slider (label , value , min , max , format? ) → number, boolean
Parameter Type
labelstring
valuenumber
minnumber
maxnumber
format optional string printf format, default "%.2f"
Returns
number the value
boolean changed
copy speed = ui .slider("Speed" , speed, 0.5 , 3 )
# ui.sliderInt (label , value , min , max ) → integer, boolean
A slider for whole numbers.
Parameter Type
labelstring
valueinteger
mininteger
maxinteger
Returns
integer value
boolean changed
# ui.drag (label , value , speed? , min? , max? ) → number, boolean
A number changed by dragging.
Parameter Type
labelstring
valuenumber
speed optional number per pixel dragged (default 1)
min optional number
max optional number
Returns
number value
boolean changed
# ui.combo (label , index , items ) → integer, boolean
Parameter Type
labelstring
indexinteger the chosen item, 1-based
itemstable a list of strings
Returns
integer the chosen index
boolean changed
copy mode = ui .combo("Mode" , mode, {"Classic" , "Survival" , "Arena" })
# ui.selectable (label , selected? ) → boolean
A clickable line (lists).
Parameter Type
labelstring
selected optional boolean shown highlighted
# ui.sameLine (offset? , spacing? )
The next widget goes on the same line.
Parameter Type
offset optional number x position
spacing optional number
# ui.indent (w? )
Indents the following widgets.
Parameter Type
w optional number
# ui.collapsing (label , open? ) → boolean
A collapsible section header.
Parameter Type
labelstring
open optional boolean open at first
Returns
boolean true while open
copy if ui .collapsing("Advanced" ) then
debug = ui .checkbox("Debug" , debug)
end
# ui.tabs (id , fn )
Parameter Type
idstring
fnfunction calls ui.tab for each tab
copy ui .tabs("main" , function ()
ui .tab("Stats" , function () ui .text("Kills:" , kills) end )
ui .tab("Options" , function () loud = ui .checkbox("Loud" , loud) end )
end )
# ui.table (id , columns , fn , headers? )
Parameter Type
idstring
columnsinteger 1-64
fnfunction fills it with ui.nextRow / ui.nextColumn
headers optional table column titles
copy ui .table("dinos" , 2 , function ()
for _, c in ipairs(world .creatures()) do
ui .nextRow(); ui .text(c.name)
ui .nextColumn(); ui .text(math.floor(c.distance))
end
end , {"Species" , "Distance" })
# ui.nextRow ()
Starts a table row (and its first cell).
# ui.nextColumn () → boolean
Moves to the next cell of the row.
Returns
boolean whether the cell is visible
# ui.child (id , w? , h? , fn , border? )
A scrolling region inside a window.
Parameter Type
idstring
w optional number 0 = all
h optional number 0 = all
fnfunction
border optional boolean
# ui.group (fn )
Groups widgets (so ui.sameLine treats them as one).
# ui.id (id , fn )
Widgets inside get a separate identity (loops with repeated labels).
Parameter Type
idany
fnfunction
copy for i, item in ipairs(items) do
ui .id(i, function ()
if ui .button("Buy" ) then buy(item) end
end )
end
# ui.hovered () → boolean
Whether the mouse is over the last widget.
# ui.clicked () → boolean
Whether the last widget was clicked.
# ui.width (w )
Width of the next widget.
# ui.scale (factor )
Text size of the current window.
Parameter Type
factornumber
# ui.available () → number, number
Space left in the window.
Returns
number width
number height
# ui.image (file , w? , h? ) → boolean
Parameter Type
filestring a PNG or TGA file of your mod (path in its folder), or a game file by name
w optional number width (default: the image's)
h optional number height (default: keeps the shape)
Returns
boolean false when the image could not be loaded (logged once)
copy ui .image("icons/rex.png" , 64 )