Windows, menus, buttons and other UI widgets (uses Dear ImGui)
More...
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.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.
|
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.
|
| |
|
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.
|
| |
|
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)
|
| |
|
| 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) |
| |
◆ imgui.button()
| boolean imgui.button |
( |
string | label, |
|
|
number | width, |
|
|
number | height ) |
Shows a button
- Parameters
-
| label | The button's text |
| width | Width in pixels, 0 to fit the text (optional, default: 0) |
| height | Height 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
-
| x | Horizontal alignment from 0 (left) to 1 (right), 0.5 is centered (optional, default: 0) |
| y | Vertical 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
-
| label | The checkbox's text |
| checked | Whether 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
-
| label | The text next to it |
| selected | Index (starting at 1) of the selected item |
| items | A 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
-
| enable | true 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
-
| x | New X position inside the window (optional) |
| y | New Y position inside the window (optional) |
- Returns
- If
x and y are omitted: a table with the fields x and y
◆ imgui.darktheme()
Switches to the dark color theme
◆ imgui.disabledtext()
| nil imgui.disabledtext |
( |
string | text | ) |
|
Shows greyed-out text
- Parameters
-
◆ imgui.drawcursor()
| nil imgui.drawcursor |
( |
boolean | enable | ) |
|
Chooses if ImGui draws the mouse cursor itself
- Parameters
-
| enable | true 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
-
| enable | true to use the buttons |
◆ 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
-
◆ 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
-
| label | The text next to it |
| selected | Index (starting at 1) of the selected item |
| items | A 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()
◆ imgui.menubegin()
| boolean imgui.menubegin |
( |
string | label, |
|
|
boolean | enabled ) |
Starts a menu (or a sub-menu, inside another menu)
- Parameters
-
| label | The menu's name |
| enabled | false to grey it out (optional, default: true) |
- Returns
true if the menu is open. Only then add items and call imgui.menuend().
◆ imgui.menuend()
◆ imgui.menuitem()
| boolean imgui.menuitem |
( |
string | label, |
|
|
boolean | selected, |
|
|
boolean | enabled ) |
Adds an item to the open menu
- Parameters
-
| label | The item's text |
| selected | true to show a check mark next to it (optional, default: false) |
| enabled | false to grey it out (optional, default: true) |
- Returns
true on the frame it's chosen
◆ 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
-
| x | Left position |
| y | Top position |
| condition | When 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
-
| width | Width in pixels |
| height | Height in pixels |
| condition | When 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
-
| percent | Progress from 0 to 100 (optional, default: 0) |
| width | Width in pixels, 0 for automatic (optional, default: 0) |
| height | Height 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
-
| label | The radio button's text |
| active | Whether 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()
Starts a new ImGui frame. Call it at the start of every frame, before any widget.
◆ 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 |
( |
| ) |
|
◆ imgui.sameline()
Puts the next widget on the same line as the previous one, instead of below it
◆ 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
-
| cursor | One of the mouse cursor constants |
◆ 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
-
- Returns
true on the frame it's pressed
◆ imgui.text()
| nil imgui.text |
( |
string | text | ) |
|
Shows a line of text
- Parameters
-
◆ imgui.textsize()
| table imgui.textsize |
( |
string | text | ) |
|
Gets the size a text will have when shown with ImGui
- Parameters
-
- 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
-
- 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
-
| front | true to use the front touch screen |
| rear | true to also use the rear touch pad (optional, default: false) |
| indirect | true to use the front touch screen like a laptop touchpad (moving a cursor), instead of touching widgets directly (optional, default: false) |
◆ 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
-
| title | The window title, it must be unique |
| flags | Window 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()
◆ imgui.windowfocus()
| nil imgui.windowfocus |
( |
string | title | ) |
|
Gives focus to a window (brings it to the front)
- Parameters
-
| title | Title 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
-
| rounding | Corner 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
-