Module imgui
ReaWrap ImGui wrapper module.
Provides OOP abstractions over ReaImGui for cleaner, more Pythonic code.
Info:
- License: MIT
- Author: Nomad Monad
Class Context
Class Context
ImGui context wrapper that provides shorthand methods.
- Context:new (name, opts)
-
Create a new ImGui context wrapper.
Parameters:
- name string Context name (window title)
- opts table|nil Optional settings {config_flags}
Returns:
-
Context
- Context:destroy ()
- Destroy the context. Note: In ReaImGui 0.8+, contexts are garbage collected automatically. This method just clears the reference to allow GC.
- Context:get_raw ()
-
Get the raw ImGui context pointer.
Returns:
-
userdata Raw context
- Context:is_valid ()
-
Check if context is valid.
Returns:
-
boolean
- Context:begin_window (title, p_open, flags)
-
Begin a window.
Parameters:
- title string Window title
- p_open boolean|nil Closeable window flag (pass true for closeable)
- flags number|nil Window flags
Returns:
- boolean visible Whether window is visible
- boolean open Whether window is still open
- Context:end_window ()
- End a window.
- Context:set_next_window_size (width, height, cond)
-
Set next window size.
Parameters:
- width number
- height number
- cond number|nil Condition (default: FirstUseEver)
- Context:set_next_window_pos (x, y, cond)
-
Set next window position.
Parameters:
- x number
- y number
- cond number|nil Condition
- Context:begin_child (id, width, height, flags)
-
Begin a child region.
Parameters:
- id string Child ID
- width number|nil Width (0 = auto)
- height number|nil Height (0 = auto)
- flags number|nil Child flags
Returns:
-
boolean
- Context:end_child ()
- End a child region.
- Context:with_child (id, width, height, child_flags, window_flags, fn)
-
Execute function with automatic child region cleanup.
Automatically calls end_child() after function execution, even if an error occurs.
Parameters:
- id string Child ID
- width number|nil Width (0 = auto)
- height number|nil Height (0 = auto)
- child_flags number|nil Child flags
- window_flags number|nil Window flags
- fn function Function to execute with child context
Returns:
-
boolean True if child was created
- Context:text (text)
-
Display text.
Parameters:
- text string
- Context:text_fmt (fmt, ...)
-
Display formatted text.
Parameters:
- fmt string Format string
- ... Format arguments
- Context:text_disabled (text)
-
Display disabled/grayed text.
Parameters:
- text string
- Context:text_colored (color, text)
-
Display colored text.
Parameters:
- color number RGBA color (0xRRGGBBAA)
- text string
- Context:text_wrapped (text)
-
Display wrapped text.
Parameters:
- text string
- Context:button (label, width, height)
-
Create a button.
Parameters:
- label string Button label
- width number|nil Button width (0 = auto)
- height number|nil Button height (0 = auto)
Returns:
-
boolean True if clicked
- Context:small_button (label)
-
Create a small button (no frame padding).
Parameters:
- label string
Returns:
-
boolean True if clicked
- Context:invisible_button (id, width, height)
-
Create an invisible button.
Parameters:
- id string
- width number
- height number
Returns:
-
boolean True if clicked
- Context:checkbox (label, value)
-
Create a checkbox.
Parameters:
- label string
- value boolean Current value
Returns:
- boolean changed Whether value changed
- boolean value New value
- Context:radio_button (label, active)
-
Create a radio button.
Parameters:
- label string
- active boolean Whether this option is active
Returns:
-
boolean True if clicked
- Context:selectable (label, selected, flags)
-
Create a selectable item.
Parameters:
- label string
- selected boolean|nil Whether selected
- flags number|nil Selectable flags
Returns:
-
boolean True if clicked
- Context:begin_combo (label, preview_value, flags)
-
Begin a combo box.
Parameters:
- label string
- preview_value string Preview text
- flags number|nil Combo flags
Returns:
-
boolean True if open
- Context:end_combo ()
- End a combo box.
- Context:dummy (width, height)
-
Add dummy space.
Parameters:
- width number
- height number
- Context:input_text (label, value, flags)
-
Create a text input.
Parameters:
- label string
- value string Current value
- flags number|nil Input text flags
Returns:
- boolean changed
- string new_value
- Context:input_int (label, value, step, step_fast)
-
Create an integer input.
Parameters:
- label string
- value number Current value
- step number|nil Step amount
- step_fast number|nil Fast step amount
Returns:
- boolean changed
- number new_value
- Context:input_double (label, value, step, step_fast, format)
-
Create a float input.
Parameters:
- label string
- value number Current value
- step number|nil Step amount
- step_fast number|nil Fast step amount
- format string|nil Display format
Returns:
- boolean changed
- number new_value
- Context:slider_int (label, value, min, max, format)
-
Create a slider (integer).
Parameters:
- label string
- value number Current value
- min number Minimum value
- max number Maximum value
- format string|nil Display format
Returns:
- boolean changed
- number new_value
- Context:slider_double (label, value, min, max, format)
-
Create a slider (float).
Parameters:
- label string
- value number Current value
- min number Minimum value
- max number Maximum value
- format string|nil Display format
Returns:
- boolean changed
- number new_value
- Context:same_line ()
- Add horizontal spacing and continue on same line.
- Context:same_line_ex (offset, spacing)
-
Add horizontal spacing and continue on same line with offset.
Parameters:
- offset number|nil X offset
- spacing number|nil Spacing
- Context:spacing ()
- Add vertical spacing.
- Context:separator ()
- Add a separator line.
- Context:newline ()
- Add a newline.
- Context:begin_group ()
- Begin a horizontal group.
- Context:end_group ()
- End a horizontal group.
- Context:push_item_width (width)
-
Push item width.
Parameters:
- width number Item width (-1 = remaining, 0 = default)
- Context:pop_item_width ()
- Pop item width.
- Context:set_cursor_pos_x (x)
-
Set cursor position X.
Parameters:
- x number
- Context:set_cursor_pos_y (y)
-
Set cursor position Y.
Parameters:
- y number
- Context:get_cursor_pos_x ()
-
Get cursor position X.
Returns:
-
number
- Context:get_cursor_pos_y ()
-
Get cursor position Y.
Returns:
-
number
- Context:indent (width)
-
Indent content.
Parameters:
- width number|nil Indent width
- Context:unindent (width)
-
Unindent content.
Parameters:
- width number|nil Unindent width
- Context:push_id (id)
-
Push an ID onto the ID stack.
Use to avoid ID conflicts when creating multiple widgets with same labels.
Parameters:
- id string|number ID to push
- Context:pop_id ()
- Pop an ID from the ID stack.
- Context:set_next_item_width (width)
-
Set width for the next item.
Parameters:
- width number Width in pixels
- Context:begin_table (id, columns, flags)
-
Begin a table.
Parameters:
- id string Table ID
- columns number Number of columns
- flags number|nil Table flags
Returns:
-
boolean
- Context:end_table ()
- End a table.
- Context:table_next_row (flags, min_height)
-
Move to next table row.
Parameters:
- flags number|nil Row flags
- min_height number|nil Minimum row height
- Context:table_next_column ()
-
Move to next table column.
Returns:
-
boolean
- Context:table_set_column_index (column)
-
Set current table column index.
Parameters:
- column number Column index (0-based)
Returns:
-
boolean
- Context:table_setup_column (label, flags, init_width)
-
Set up a table column.
Parameters:
- label string Column label
- flags number|nil Column flags
- init_width number|nil Initial width
- Context:table_headers_row ()
- Display table headers row.
- Context:with_table (id, columns, flags, fn)
-
Execute function with automatic table cleanup.
Automatically calls end_table() after function execution, even if an error occurs.
Parameters:
- id string Table ID
- columns number Number of columns
- flags number|nil Table flags
- fn function Function to execute with table context
Returns:
-
boolean True if table was created
- Context:tree_node (label, flags)
-
Create a tree node.
Parameters:
- label string
- flags number|nil Tree node flags
Returns:
-
boolean True if open
- Context:tree_node_ex (label, flags)
-
Create a tree node with extended options.
Parameters:
- label string
- flags number|nil Tree node flags
Returns:
-
boolean True if open
- Context:tree_pop ()
- Pop a tree node.
- Context:with_tree_node (label, flags, fn)
-
Execute function with automatic tree node cleanup.
Automatically calls tree_pop() after function execution if tree was opened.
Parameters:
- label string Tree node label
- flags number|nil Tree node flags
- fn function Function to execute with tree context
Returns:
-
boolean True if tree was opened
- Context:collapsing_header (label, flags)
-
Create a collapsing header.
Parameters:
- label string
- flags number|nil
Returns:
-
boolean True if open
- Context:begin_popup (id, flags)
-
Begin a popup.
Parameters:
- id string Popup ID
- flags number|nil Window flags
Returns:
-
boolean
- Context:begin_popup_modal (title, p_open, flags)
-
Begin a popup modal.
Parameters:
- title string Modal title
- p_open boolean|nil
- flags number|nil Window flags
Returns:
- boolean visible
- boolean|nil open
- Context:end_popup ()
- End a popup.
- Context:open_popup (id)
-
Open a popup.
Parameters:
- id string Popup ID
- Context:close_current_popup ()
- Close current popup.
- Context:begin_popup_context_item (id)
-
Begin a context menu (right-click popup).
Parameters:
- id string|nil Popup ID
Returns:
-
boolean
- Context:set_tooltip (text)
-
Set tooltip for previous item.
Parameters:
- text string Tooltip text
- Context:begin_tooltip ()
- Begin a tooltip region.
- Context:end_tooltip ()
- End a tooltip region.
- Context:help_marker (text)
-
Show tooltip if previous item is hovered.
Parameters:
- text string Tooltip text
- Context:begin_menu_bar ()
-
Begin a menu bar.
Returns:
-
boolean
- Context:end_menu_bar ()
- End a menu bar.
- Context:begin_menu (label, enabled)
-
Begin a menu.
Parameters:
- label string Menu label
- enabled boolean|nil Whether enabled
Returns:
-
boolean
- Context:end_menu ()
- End a menu.
- Context:menu_item (label, shortcut, selected, enabled)
-
Create a menu item.
Parameters:
- label string Item label
- shortcut string|nil Keyboard shortcut text
- selected boolean|nil Whether selected
- enabled boolean|nil Whether enabled
Returns:
-
boolean clicked
- Context:begin_tab_bar (id, flags)
-
Begin a tab bar.
Parameters:
- id string Tab bar ID
- flags number|nil Tab bar flags
Returns:
-
boolean
- Context:end_tab_bar ()
- End a tab bar.
- Context:begin_tab_item (label, p_open, flags)
-
Begin a tab item.
Parameters:
- label string Tab label
- p_open boolean|nil Closeable tab flag
- flags number|nil Tab item flags
Returns:
- boolean selected
- boolean|nil open
- Context:end_tab_item ()
- End a tab item.
- Context:is_item_hovered (flags)
-
Check if previous item is hovered.
Parameters:
- flags number|nil Hovered flags
Returns:
-
boolean
- Context:is_item_clicked (button)
-
Check if previous item is clicked.
Parameters:
- button number|nil Mouse button (0=left, 1=right, 2=middle)
Returns:
-
boolean
- Context:is_item_active ()
-
Check if previous item is active.
Returns:
-
boolean
- Context:is_item_deactivated_after_edit ()
-
Check if previous item was just made inactive and made a value change.
Returns:
-
boolean
- Context:is_item_focused ()
-
Check if previous item is focused.
Returns:
-
boolean
- Context:is_mouse_down (button)
-
Check if mouse button is down.
Parameters:
- button number Mouse button
Returns:
-
boolean
- Context:is_mouse_clicked (button)
-
Check if mouse button was clicked.
Parameters:
- button number Mouse button
Returns:
-
boolean
- Context:is_mouse_double_clicked (button)
-
Check if mouse button was double-clicked.
Parameters:
- button number Mouse button
Returns:
-
boolean
- Context:is_key_down (key)
-
Check if key is down.
Parameters:
- key number Key code
Returns:
-
boolean
- Context:is_key_pressed (key)
-
Check if key was pressed.
Parameters:
- key number Key code
Returns:
-
boolean
- Context:get_key_mods ()
-
Get current modifier key flags.
Returns:
-
number Bitmask of modifier keys
- Context:is_shift_down ()
-
Check if shift modifier is held.
Returns:
-
boolean
- Context:is_ctrl_down ()
-
Check if ctrl/cmd modifier is held.
Returns:
-
boolean
- Context:is_alt_down ()
-
Check if alt modifier is held.
Returns:
-
boolean
- Context:begin_drag_drop_source (flags)
-
Begin a drag source on the last item.
Call between item creation and next item. Returns true if dragging.
Parameters:
- flags number|nil DragDropFlags (default 0)
Returns:
-
boolean True if drag source is active
- Context:end_drag_drop_source ()
- End drag source (must call if begin_drag_drop_source returned true).
- Context:set_drag_drop_payload (type, data, cond)
-
Set drag payload data.
Parameters:
- type string Payload type identifier
- data string Payload data
- cond number|nil SetCond flags (default Always)
Returns:
-
boolean
- Context:begin_drag_drop_target ()
-
Begin a drop target on the last item.
Returns:
-
boolean True if drop target is active
- Context:end_drag_drop_target ()
- End drop target (must call if begin_drag_drop_target returned true).
- Context:accept_drag_drop_payload (type, flags)
-
Accept a drag payload.
Parameters:
- type string Expected payload type
- flags number|nil DragDropFlags (default 0)
Returns:
-
boolean, string|nil Accepted, payload data
- Context:get_drag_drop_payload (type)
-
Get current drag payload (peek without accepting).
Parameters:
- type string|nil Expected payload type (nil for any)
Returns:
-
boolean, string|nil Has payload, payload data
- Context:begin_disabled (disabled)
-
Begin disabled state.
Parameters:
- disabled boolean|nil Whether to disable (default true)
- Context:end_disabled ()
- End disabled state.
- Context:with_disabled (disabled, fn)
-
Execute callback in disabled state if condition is true.
Parameters:
- disabled boolean Whether to disable
- fn function Callback to execute
- Context:push_style_color (idx, color)
-
Push a style color.
Parameters:
- idx number Color index (ImGui_Col_*)
- color number RGBA color
- Context:pop_style_color (count)
-
Pop style colors.
Parameters:
- count number|nil Number to pop (default 1)
- Context:push_style_var (idx, value, value2)
-
Push a style variable (float or vec2).
Parameters:
- idx number Variable index (ImGui_StyleVar_*)
- value number Value (or first component of Vec2)
- value2 number|nil Second component for Vec2 style vars
- Context:pop_style_var (count)
-
Pop style variables.
Parameters:
- count number|nil Number to pop (default 1)
- Context:get_cursor_screen_pos ()
-
Get cursor screen position.
Returns:
- number x
- number y
- Context:set_cursor_screen_pos (x, y)
-
Set cursor screen position.
Parameters:
- x number
- y number
- Context:get_mouse_pos ()
-
Get mouse position.
Returns:
- number x
- number y
- Context:set_keyboard_focus_here (offset)
-
Set keyboard focus to next widget.
Parameters:
- offset number|nil Offset (default 0 = next widget)
- Context:push_font (font, size)
-
Push a font.
Parameters:
- font userdata Font object
- size number|nil Font size (optional)
- Context:pop_font ()
- Pop font.
- Context:get_window_draw_list ()
-
Get window draw list.
Returns:
-
userdata Draw list
- Context:draw_list_add_rect_filled (draw_list, x1, y1, x2, y2, color, rounding)
-
Draw a filled rectangle.
Parameters:
- draw_list userdata Draw list
- x1 number Top-left X
- y1 number Top-left Y
- x2 number Bottom-right X
- y2 number Bottom-right Y
- color number RGBA color
- rounding number|nil Corner rounding
- Context:draw_list_add_rect (draw_list, x1, y1, x2, y2, color, rounding, thickness)
-
Draw a rectangle outline.
Parameters:
- draw_list userdata Draw list
- x1 number Top-left X
- y1 number Top-left Y
- x2 number Bottom-right X
- y2 number Bottom-right Y
- color number RGBA color
- rounding number|nil Corner rounding
- thickness number|nil Border thickness
- Context:draw_list_add_line (draw_list, x1, y1, x2, y2, color, thickness)
-
Draw a line.
Parameters:
- draw_list userdata Draw list
- x1 number Start X
- y1 number Start Y
- x2 number End X
- y2 number End Y
- color number RGBA color
- thickness number|nil Line thickness
- Context:draw_list_add_text (draw_list, x, y, color, text)
-
Draw text.
Parameters:
- draw_list userdata Draw list
- x number X position
- y number Y position
- color number RGBA color
- text string Text to draw
- Context:v_slider_double (label, width, height, value, min, max, format)
-
Create a vertical slider (double/float).
Parameters:
- label string
- width number Slider width
- height number Slider height
- value number Current value
- min number Minimum value
- max number Maximum value
- format string|nil Display format
Returns:
- boolean changed
- number new_value
- Context:calc_text_size (text)
-
Calculate text size.
Parameters:
- text string
Returns:
- number width
- number height
- Context:get_content_region_avail_width ()
-
Get content region available width.
Returns:
-
number
- Context:get_content_region_avail ()
-
Get content region available.
Returns:
- number width
- number height
- Context:get_window_size ()
-
Get window size.
Returns:
- number width
- number height
- Context:get_window_pos ()
-
Get window position.
Returns:
- number x
- number y
- context.Context
- Module Exports
- context:create_context (name, opts)
-
Create a new context (convenience function).
Parameters:
- name string Context name
- opts table|nil Options
Returns:
-
Context
- context:is_available ()
-
Check if ReaImGui is available.
Returns:
-
boolean
- context:get_version ()
-
Get ReaImGui version.
Returns:
-
string|nil Version string or nil if not available