Drawing
ui
Windows and widgets, built on Dear ImGui.
ui draws windows and widgets with Dear ImGui, the same toolkit as the plugins' own windows. It only works inside on_render. If you know ImGui, the names are the same in snake_case.
local enabled, range, mode = true, 600, 1
function on_render()
ui.set_next_window_size(Vec2(320, 0), ui.Cond.FirstUseEver)
local _, visible = ui.begin_window("My plugin")
if visible then
local changed
changed, enabled = ui.checkbox("Enabled", enabled)
changed, range = ui.slider_float("Range", range, 100, 1500, "%.0f")
changed, mode = ui.combo("Mode", mode, { "Closest", "Weakest", "Strongest" })
if ui.button("Reset") then range = 600 end
end
ui.end_window()
endRules
- Widgets that hold a value take the current value and return
changed, new_value. Store the new value; nothing is kept for you. - Every
begin_*andpush_*needs itsend_*orpop_*.begin_windowandbegin_childneed their end always; the ones that return whether they're open (tree_node,begin_menu,begin_table,begin_tab_item, popups) only when they returned true. - An
end_*that doesn't match is a Lua error, and whatever is still open whenon_renderreturns is closed for you, with a warning. - A label is also the widget's id, so two widgets with the same label in one window clash. Add
##and something unique after the visible text ("Delete##3"), or wrap them inpush_id/pop_id. - Indices (combos, list boxes, table columns) start at 1.
- Flags are numbers from the tables in ui flags; combine several with
|.
Windows
ui.begin_window(title [, open [, flags]])open, visible
Starts a window. With
open, the window has a close button and open comes back false once it's clicked. visible is false while it's collapsed. Always call ui.end_window().Ends the window.
A scrolling region inside a window. Always call
ui.end_child().Ends the child region.
Places the next window.
cond is a ui.Cond value, such as ui.Cond.FirstUseEver to only do it the first time.Sizes the next window. A 0 width or height fits the content.
Limits how small and large the next window can be.
The current window's position.
The current window's size.
Whether it has focus (
ui.FocusedFlags).Whether the mouse is over it (
ui.HoveredFlags).ui.is_window_appearing()boolean
Whether it's showing for the first frame.
ui.is_window_collapsed()boolean
Whether it's collapsed.
Text
A line of text. Several values are joined with spaces.
Text in a color.
Dimmed text.
Text that wraps at the window's edge.
Text with a bullet.
A bullet, for the next item on the line.
ui.text_block(text)boolean
Text that works as a button: no frame, true when clicked.
A read-only text box.
A tooltip by the mouse. Usually after
if ui.is_item_hovered() then.Starts a tooltip with any content. End it with
ui.end_tooltip().Buttons and choices
A row that highlights and can be clicked.
ui.checkbox(label, value)changed, value
A checkbox.
ui.combo(label, index, items [, height])changed, index
A dropdown of strings.
ui.list_box(label, index, items [, height])changed, index
A list of strings to pick from.
ui.color_edit(label, color [, flags])changed, Color
A color picker, with alpha unless
flags has ui.ColorEditFlags.NoAlpha.Inputs, sliders and drags
format is a printf format such as "%.1f" or "%d ms".
ui.input_text(label, text [, max_length [, flags]])changed, text
A text box (256 characters by default).
A text box showing
hint while empty.A multi-line text box (4096 characters by default).
An integer box with +/- buttons.
A number box.
A number box with more precision.
An integer slider.
A number slider.
A vertical integer slider.
A vertical number slider.
An integer you change by dragging.
A number you change by dragging.
ui.input_vec2(label, vec [, format])changed, Vec2
Two number boxes.
ui.input_vec3 takes a Vec3.Two drag fields.
ui.drag_vec3 takes a Vec3.ui.slider_vec2(label, vec, min, max [, format])changed, Vec2
Two sliders.
ui.slider_vec3 takes a Vec3.Images, bars and plots
Draws an image: a game icon (
item:icon(), skill.icon...) or one loaded with gfx.image_from_png.A bar filled from 0 to 1, with optional text on it.
A line graph of a list of numbers.
A bar graph of a list of numbers.
Layout
Puts the next item on the same line.
Ends the line.
A horizontal line.
A little vertical space.
Indents what follows.
ui.unindent([width]) undoes it.Lines text up with the buttons and boxes next to it.
Groups items so they act as one (for
same_line or hover checks). End with ui.end_group().Grays out and disables what follows. End with
ui.end_disabled().Makes the labels that follow unique, for lists of similar widgets. End with
ui.pop_id().Sets the width of the widgets that follow. End with
ui.pop_item_width().Sets the next widget's width.
ui.calc_item_width()number
The width the next widget would get.
Wraps text at
x. End with ui.pop_text_wrap_pos().Changes a color, such as
ui.Col.Text. End with ui.pop_style_color([count]).Changes spacing or padding, such as
ui.StyleVar.ItemSpacing. End with ui.pop_style_var([count])."DEFAULT", "MENU" or "HEADER". End with ui.pop_font().ui.font_size()number
The current font's size in pixels.
ui.font_global_scale()number
The scale applied to all text.
Sets it, between 0.25 and 4.
How big a text is drawn.
The height of a line of text.
The same, with the space between lines.
ui.get_frame_height()number
The height of a button or box.
The same, with the space after it.
The space left in the window.
Where the next item goes, in the window.
Moves where the next item goes.
Where the next item goes, on screen.
Moves it, in screen coordinates.
ui.get_scroll()Vec2
How far the window is scrolled.
How far it can scroll.
Scrolls the window to the end, for logs.
Trees and headers
A header that opens and closes its section. Nothing to end.
A node that unfolds. When it returns true, call
ui.tree_pop() after its content.Ends an open tree node.
Opens or closes the next tree node or header.
Popups
Opens a popup.
ui.begin_popup_modal(name [, open [, flags]])visible, open
A modal popup. Call
ui.end_popup() when visible.A right-click menu on the last item. Call
ui.end_popup() when true.Ends the popup.
Closes the popup you're in.
Menus
Tabs
A row of tabs. Call
ui.end_tab_bar() when true.ui.begin_tab_item(label [, open [, flags]])selected, open
A tab. Its content follows when
selected; then call ui.end_tab_item(). With open, the tab has a close button.Tables
if ui.begin_table("players", 2, ui.TableFlags.Borders | ui.TableFlags.RowBg) then
ui.table_setup_column("Name")
ui.table_setup_column("Health")
ui.table_headers_row()
for _, p in ipairs(agents.players()) do
ui.table_next_row()
ui.table_next_column(); ui.text(p:name() or "?")
ui.table_next_column(); ui.text(string.format("%.0f%%", p:health().percent))
end
ui.end_table()
endA table with 1 to 64 columns. Call
ui.end_table() when true.Names a column. Before the first row, once per column.
A row of column names.
Starts a row.
ui.table_next_column()boolean
Moves to the next cell.
Moves to a cell of the row, from 1.
ui.table_get_column_index()integer
The current column, from 1.
ui.table_get_row_index()integer
The current row.
The current column's width.
Colors a row or cell;
target is a ui.TableBgTarget value.Drag and drop
Payloads are strings, with a type name of up to 32 characters.
Makes the last item draggable. When true, set a payload and call
ui.end_drag_drop_source().What's being dragged.
ui.begin_drag_drop_target()boolean
Makes the last item a drop target. When true, call
ui.end_drag_drop_target().The payload, once dropped here.
Drawing in a window
ui.draw draws shapes into the current window, in screen coordinates. Start from ui.get_cursor_screen_pos().
A rectangle outline;
flags are ui.DrawFlags for which corners are round.A filled rectangle.
A rectangle with a color in each corner.
A four-sided outline.
A filled four-sided shape.
A triangle outline.
A filled triangle.
A circle outline.
A filled circle.
Items, keys and the mouse
Keys here are ui.Key values; mouse buttons are 0 (left), 1 (right) and 2 (middle).
ui.is_item_hovered([flags])boolean
Whether the mouse is over the last item.
ui.is_item_clicked([button])boolean
Whether the last item was clicked.
ui.is_item_active()boolean
Whether the last item is being used (held, dragged, typed in).
ui.is_item_focused()boolean
Whether it has keyboard focus.
ui.is_any_item_hovered()boolean
Whether the mouse is over any item.
ui.is_any_item_active()boolean
Whether any item is in use.
ui.is_any_item_focused()boolean
Whether any item has focus.
Focuses the last item when its window appears.
Focuses the next item.
ui.is_key_down(key)boolean
Whether a key is held.
ui.is_key_pressed(key)boolean
Whether a key was pressed this frame.
ui.is_key_released(key)boolean
Whether a key was released this frame.
ui.is_mouse_down(button)boolean
Whether a mouse button is held.
ui.is_mouse_clicked(button)boolean
Whether it was clicked this frame.
ui.is_mouse_released(button)boolean
Whether it was released this frame.
Whether it was double-clicked.
How many clicks in a row.
Whether the mouse is being dragged.
ui.is_any_mouse_down()boolean
Whether any mouse button is held.
The mouse position on screen.
ui.in_render()boolean
Whether drawing is possible now (inside
on_render).