LifeLua 21-08-2025
Documentation for LifeLua, a Lua interpreter for the PS Vita
Loading...
Searching...
No Matches
imgui

Windows, menus, buttons and other UI widgets (uses Dear ImGui) More...

Detailed Description

ImGui is an "immediate mode" UI library: there are no button objects to create or keep. Instead, every frame you call the widget functions in the order they should appear, and each one tells you right away if the user interacted with it (e.g. imgui.button() returns true on the frame it's pressed).

Call imgui.init() once at the start, then put your widgets between imgui.renderinit() and imgui.renderterm() in your main loop:

imgui.init()
imgui.darktheme()
imgui.touch(true) -- use the touch screen
imgui.gamepad(true) -- use the buttons/D-pad to move between widgets
local sound = true
local level = 1
local levels = {"Easy", "Normal", "Hard"}
while true do
imgui.renderinit()
imgui.nextwindowposition(20, 20, ImGuiCond_FirstUseEver)
imgui.nextwindowsize(400, 250, ImGuiCond_FirstUseEver)
imgui.windowbegin("Settings")
imgui.text("Hello from ImGui!")
sound = imgui.checkbox("Sound", sound)
level = imgui.combobox("Difficulty", level, levels)
if imgui.button("Start") then
-- start the game with levels[level]
end
imgui.windowend()
imgui.renderterm()
draw.swapbuffers()
end
ImGuiCond ImGuiCond_FirstUseEver
Apply it only if the window has no saved position/size yet.
Definition lj_imgui.h:374

You can draw other things (with draw, image, ...) in the same frame; draw them before imgui.renderterm() to have the ImGui windows on top of them.

Note
The text of imgui.text(), imgui.disabledtext(), imgui.wrappedtext() and imgui.tooltip() is read as a C format string, so write %% to show a % sign.

Window flags

Used with imgui.windowbegin(). Add them together to combine them.

ImGuiWindowFlags ImGuiWindowFlags_None
 Default window.
 
ImGuiWindowFlags ImGuiWindowFlags_NoTitleBar
 No title bar.
 
ImGuiWindowFlags ImGuiWindowFlags_NoResize
 Can't be resized by the user.
 
ImGuiWindowFlags ImGuiWindowFlags_NoMove
 Can't be moved by the user.
 
ImGuiWindowFlags ImGuiWindowFlags_NoScrollbar
 No scrollbars (it can still scroll)
 
ImGuiWindowFlags ImGuiWindowFlags_NoScrollWithMouse
 Can't be scrolled with the mouse wheel.
 
ImGuiWindowFlags ImGuiWindowFlags_NoCollapse
 Can't be collapsed.
 
ImGuiWindowFlags ImGuiWindowFlags_NoBackground
 No background or border.
 
ImGuiWindowFlags ImGuiWindowFlags_NoSavedSettings
 Don't remember its position/size.
 
ImGuiWindowFlags ImGuiWindowFlags_NoMouseInputs
 Ignores the mouse/touch (they go through it)
 
ImGuiWindowFlags ImGuiWindowFlags_MenuBar
 Has a menu bar.
 
ImGuiWindowFlags ImGuiWindowFlags_HorizontalScrollbar
 Allow a horizontal scrollbar.
 
ImGuiWindowFlags ImGuiWindowFlags_NoFocusOnAppearing
 Don't take focus when it appears.
 
ImGuiWindowFlags ImGuiWindowFlags_NoBringToFrontOnFocus
 Don't come to the front when it gets focus.
 
ImGuiWindowFlags ImGuiWindowFlags_AlwaysVerticalScrollbar
 Always show the vertical scrollbar.
 
ImGuiWindowFlags ImGuiWindowFlags_AlwaysUseWindowPadding
 Always use the window padding, even for child windows without a border.
 
ImGuiWindowFlags ImGuiWindowFlags_NoNav
 Can't be navigated with the buttons.
 
ImGuiWindowFlags ImGuiWindowFlags_NoDecoration
 Same as NoTitleBar + NoResize + NoScrollbar + NoCollapse.
 
ImGuiWindowFlags ImGuiWindowFlags_NoInputs
 Ignores all input (same as NoMouseInputs + NoNav)
 
ImGuiWindowFlags ImGuiWindowFlags_UnsavedDocument
 Shows a * after the title.
 
ImGuiWindowFlags ImGuiWindowFlags_ChildWindow
 Used internally by ImGui, don't use.
 
ImGuiWindowFlags ImGuiWindowFlags_Tooltip
 Used internally by ImGui, don't use.
 
ImGuiWindowFlags ImGuiWindowFlags_Popup
 Used internally by ImGui, don't use.
 
ImGuiWindowFlags ImGuiWindowFlags_Modal
 Used internally by ImGui, don't use.
 
ImGuiWindowFlags ImGuiWindowFlags_ChildMenu
 Used internally by ImGui, don't use.
 

Conditions

Used with imgui.nextwindowposition() and imgui.nextwindowsize()

ImGuiCond ImGuiCond_None
 Same as ImGuiCond_Always.
 
ImGuiCond ImGuiCond_Always
 Apply it every time (the user can't move/resize the window)
 
ImGuiCond ImGuiCond_Once
 Apply it only the first time it's called.
 
ImGuiCond ImGuiCond_FirstUseEver
 Apply it only if the window has no saved position/size yet.
 
ImGuiCond ImGuiCond_Appearing
 Apply it every time the window appears after being hidden.
 

Mouse cursors

Used with imgui.setcursor()

ImGuiMouseCursor ImGuiMouseCursor_None
 No cursor.
 
ImGuiMouseCursor ImGuiMouseCursor_Arrow
 Normal arrow.
 
ImGuiMouseCursor ImGuiMouseCursor_TextInput
 Text cursor.
 
ImGuiMouseCursor ImGuiMouseCursor_ResizeAll
 Move in all directions.
 
ImGuiMouseCursor ImGuiMouseCursor_ResizeNS
 Resize up/down.
 
ImGuiMouseCursor ImGuiMouseCursor_ResizeEW
 Resize left/right.
 
ImGuiMouseCursor ImGuiMouseCursor_ResizeNESW
 Resize diagonally (bottom-left/top-right)
 
ImGuiMouseCursor ImGuiMouseCursor_ResizeNWSE
 Resize diagonally (top-left/bottom-right)
 
ImGuiMouseCursor ImGuiMouseCursor_Hand
 Pointing hand.
 
ImGuiMouseCursor ImGuiMouseCursor_NotAllowed
 "Not allowed" sign
 
ImGuiMouseCursor ImGuiMouseCursor_COUNT
 Number of cursor types (not a cursor)
 

Setup

nil imgui.init ()
 
nil imgui.shutdown ()
 
nil imgui.touch (boolean front, boolean rear, boolean indirect)
 
nil imgui.gamepad (boolean enable)
 
nil imgui.cursor (boolean enable)
 
nil imgui.drawcursor (boolean enable)
 
nil imgui.setcursor (ImGuiMouseCursor cursor)
 
nil imgui.darktheme ()
 
nil imgui.lighttheme ()
 
nil imgui.classictheme ()
 
string imgui.version ()
 

Frame

nil imgui.renderinit ()
 
nil imgui.renderterm ()
 
nil imgui.metrics ()
 

Windows

nil imgui.nextwindowposition (number x, number y, ImGuiCond condition)
 
nil imgui.nextwindowsize (number width, number height, ImGuiCond condition)
 
nil imgui.windowbegin (string title, ImGuiWindowFlags flags)
 
nil imgui.windowend ()
 
nil imgui.windowfocus (string title)
 
nil imgui.windowrounding (number rounding)
 

Main menu bar & menus

boolean imgui.menubarbegin ()
 
nil imgui.menubarend ()
 
boolean imgui.menubegin (string label, boolean enabled)
 
nil imgui.menuend ()
 
boolean imgui.menuitem (string label, boolean selected, boolean enabled)
 

Text

nil imgui.text (string text)
 
nil imgui.disabledtext (string text)
 
nil imgui.wrappedtext (string text)
 
table imgui.textsize (string text)
 
nil imgui.tooltip (string text)
 

Widgets

boolean imgui.button (string label, number width, number height)
 
boolean imgui.smallbutton (string label)
 
boolean imgui.checkbox (string label, boolean checked)
 
boolean imgui.radiobutton (string label, boolean active)
 
number imgui.combobox (string label, number selected, table items)
 
number imgui.listbox (string label, number selected, table items)
 
nil imgui.progressbar (number percent, number width, number height)
 

Layout & style

nil imgui.sameline ()
 
nil imgui.separator ()
 
table imgui.cursorposition (number x, number y)
 
nil imgui.itemwidth (number width)
 
nil imgui.resetitemwidth ()
 
nil imgui.buttontextalign (number x, number y)
 

Function Documentation

◆ imgui.button()

boolean imgui.button ( string label,
number width,
number height )

Shows a button

Parameters
labelThe button's text
widthWidth in pixels, 0 to fit the text (optional, default: 0)
heightHeight in pixels, 0 to fit the text (optional, default: 0)
Returns
true on the frame it's pressed

◆ imgui.buttontextalign()

nil imgui.buttontextalign ( number x,
number y )

Sets where the text is placed inside the buttons shown after calling it

Parameters
xHorizontal alignment from 0 (left) to 1 (right), 0.5 is centered (optional, default: 0)
yVertical alignment from 0 (top) to 1 (bottom), 0.5 is centered (optional, default: 0)

◆ imgui.checkbox()

boolean imgui.checkbox ( string label,
boolean checked )

Shows a checkbox

Parameters
labelThe checkbox's text
checkedWhether it's checked now
Returns
Whether it's checked after this frame. Store it and pass it again next frame.
Example:
music_on = imgui.checkbox("Music", music_on)

◆ imgui.classictheme()

nil imgui.classictheme ( )

Switches to the classic color theme

◆ imgui.combobox()

number imgui.combobox ( string label,
number selected,
table items )

Shows a drop-down list

Parameters
labelThe text next to it
selectedIndex (starting at 1) of the selected item
itemsA list of strings to choose from
Returns
The index of the selected item after this frame. Store it and pass it again next frame.

◆ imgui.cursor()

nil imgui.cursor ( boolean enable)

Chooses if the left analog stick moves a mouse cursor

Parameters
enabletrue to use the left stick as a mouse

◆ imgui.cursorposition()

table imgui.cursorposition ( number x,
number y )

Gets or sets where the next widget is placed in the current window

Parameters
xNew X position inside the window (optional)
yNew Y position inside the window (optional)
Returns
If x and y are omitted: a table with the fields x and y

◆ imgui.darktheme()

nil imgui.darktheme ( )

Switches to the dark color theme

◆ imgui.disabledtext()

nil imgui.disabledtext ( string text)

Shows greyed-out text

Parameters
textThe text

◆ imgui.drawcursor()

nil imgui.drawcursor ( boolean enable)

Chooses if ImGui draws the mouse cursor itself

Parameters
enabletrue to draw the cursor

◆ imgui.gamepad()

nil imgui.gamepad ( boolean enable)

Chooses if the buttons can be used to move between and use widgets (D-pad to move, the accept button to press)

Parameters
enabletrue to use the buttons

◆ imgui.init()

nil imgui.init ( )

Starts ImGui. Call it once before using any other ImGui function.

◆ imgui.itemwidth()

nil imgui.itemwidth ( number width)

Sets the width of the next widgets (like combo boxes and progress bars) until imgui.resetitemwidth()

Parameters
widthWidth in pixels

◆ imgui.lighttheme()

nil imgui.lighttheme ( )

Switches to the light color theme

◆ imgui.listbox()

number imgui.listbox ( string label,
number selected,
table items )

Shows a list box (a list where all the items are visible)

Parameters
labelThe text next to it
selectedIndex (starting at 1) of the selected item
itemsA list of strings to choose from
Returns
The index of the selected item after this frame. Store it and pass it again next frame.

◆ imgui.menubarbegin()

boolean imgui.menubarbegin ( )

Starts the menu bar at the top of the screen

Returns
true if the menu bar is shown. Only then add menus and call imgui.menubarend().
Example:
if imgui.menubarbegin() then
if imgui.menubegin("File") then
if imgui.menuitem("Exit") then os.exit() end
imgui.menuend()
end
imgui.menubarend()
end

◆ imgui.menubarend()

nil imgui.menubarend ( )

Ends the menu bar. Only call it if imgui.menubarbegin() returned true.

◆ imgui.menubegin()

boolean imgui.menubegin ( string label,
boolean enabled )

Starts a menu (or a sub-menu, inside another menu)

Parameters
labelThe menu's name
enabledfalse to grey it out (optional, default: true)
Returns
true if the menu is open. Only then add items and call imgui.menuend().

◆ imgui.menuend()

nil imgui.menuend ( )

Ends a menu. Only call it if imgui.menubegin() returned true.

◆ imgui.menuitem()

boolean imgui.menuitem ( string label,
boolean selected,
boolean enabled )

Adds an item to the open menu

Parameters
labelThe item's text
selectedtrue to show a check mark next to it (optional, default: false)
enabledfalse to grey it out (optional, default: true)
Returns
true on the frame it's chosen

◆ imgui.metrics()

nil imgui.metrics ( )

Shows the ImGui metrics/debug window, with information about the windows and how fast they draw

◆ imgui.nextwindowposition()

nil imgui.nextwindowposition ( number x,
number y,
ImGuiCond condition )

Sets the position of the next window created with imgui.windowbegin()

Parameters
xLeft position
yTop position
conditionWhen to apply it, one of the condition constants (optional, default: ImGuiCond_Always)

◆ imgui.nextwindowsize()

nil imgui.nextwindowsize ( number width,
number height,
ImGuiCond condition )

Sets the size of the next window created with imgui.windowbegin()

Parameters
widthWidth in pixels
heightHeight in pixels
conditionWhen to apply it, one of the condition constants (optional, default: ImGuiCond_Always)

◆ imgui.progressbar()

nil imgui.progressbar ( number percent,
number width,
number height )

Shows a progress bar

Parameters
percentProgress from 0 to 100 (optional, default: 0)
widthWidth in pixels, 0 for automatic (optional, default: 0)
heightHeight in pixels, 0 for automatic (optional, default: 0)

◆ imgui.radiobutton()

boolean imgui.radiobutton ( string label,
boolean active )

Shows a radio button (one choice out of several)

Parameters
labelThe radio button's text
activeWhether it's the selected choice
Returns
true on the frame it's pressed
Example:
if imgui.radiobutton("Small", size == 1) then size = 1 end
imgui.sameline()
if imgui.radiobutton("Big", size == 2) then size = 2 end

◆ imgui.renderinit()

nil imgui.renderinit ( )

Starts a new ImGui frame. Call it at the start of every frame, before any widget.

◆ imgui.renderterm()

nil imgui.renderterm ( )

Ends the ImGui frame and draws all the widgets. Call it after your last widget, before draw.swapbuffers().

◆ imgui.resetitemwidth()

nil imgui.resetitemwidth ( )

Goes back to the widget width used before the last imgui.itemwidth()

◆ imgui.sameline()

nil imgui.sameline ( )

Puts the next widget on the same line as the previous one, instead of below it

◆ imgui.separator()

nil imgui.separator ( )

Draws a horizontal line to separate widgets

◆ imgui.setcursor()

nil imgui.setcursor ( ImGuiMouseCursor cursor)

Changes the shape of the mouse cursor for this frame

Parameters
cursorOne of the mouse cursor constants

◆ imgui.shutdown()

nil imgui.shutdown ( )

Stops ImGui and frees its memory

◆ imgui.smallbutton()

boolean imgui.smallbutton ( string label)

Shows a small button, with less padding, that fits in a line of text

Parameters
labelThe button's text
Returns
true on the frame it's pressed

◆ imgui.text()

nil imgui.text ( string text)

Shows a line of text

Parameters
textThe text

◆ imgui.textsize()

table imgui.textsize ( string text)

Gets the size a text will have when shown with ImGui

Parameters
textThe text
Returns
A table with the fields x (width) and y (height)

◆ imgui.tooltip()

nil imgui.tooltip ( string text)

Shows a tooltip when the last widget is hovered by the cursor

Parameters
textThe tooltip text
Example:
imgui.button("Save")
imgui.tooltip("Saves your progress")

◆ imgui.touch()

nil imgui.touch ( boolean front,
boolean rear,
boolean indirect )

Chooses if the touch screens can be used to interact with ImGui

Parameters
fronttrue to use the front touch screen
reartrue to also use the rear touch pad (optional, default: false)
indirecttrue to use the front touch screen like a laptop touchpad (moving a cursor), instead of touching widgets directly (optional, default: false)

◆ imgui.version()

string imgui.version ( )

Gets the version of Dear ImGui

Returns
The version, e.g. "1.79 WIP"

◆ imgui.windowbegin()

nil imgui.windowbegin ( string title,
ImGuiWindowFlags flags )

Starts a window. The widgets called after it are placed in this window, until imgui.windowend().

Parameters
titleThe window title, it must be unique
flagsWindow flag constants, added together (optional, default: ImGuiWindowFlags_None)
Example:
imgui.text("This window can't be moved or resized")
imgui.windowend()
ImGuiWindowFlags ImGuiWindowFlags_NoResize
Can't be resized by the user.
Definition lj_imgui.h:344
ImGuiWindowFlags ImGuiWindowFlags_NoMove
Can't be moved by the user.
Definition lj_imgui.h:345

◆ imgui.windowend()

nil imgui.windowend ( )

Ends the window started with imgui.windowbegin()

◆ imgui.windowfocus()

nil imgui.windowfocus ( string title)

Gives focus to a window (brings it to the front)

Parameters
titleTitle of the window (optional, default: the current window)

◆ imgui.windowrounding()

nil imgui.windowrounding ( number rounding)

Sets how rounded the corners of the windows are. Applies to the windows started after calling it.

Parameters
roundingCorner radius in pixels (optional, default: 0)

◆ imgui.wrappedtext()

nil imgui.wrappedtext ( string text)

Shows text that wraps onto the next line at the edge of the window

Parameters
textThe text