Module imgui.window
Window abstraction for ReaImGui.
Provides a class-based approach to creating ImGui windows with lifecycle management.
Info:
- License: MIT
- Author: Nomad Monad
Class Window
| Window:new (opts) | Create a new Window instance. |
| Window:open (run_loop) | Open the window and start rendering. |
| Window:close () | Close the window. |
| Window:_do_close () | Internal: Actually close the window (called after frame completes). |
| Window:defer_action (action) | Queue an action to run after the current frame completes. |
| Window:is_open () | Check if window is open. |
| Window:get_context () | Get the ImGui context. |
| Window:render_frame () | Render a single frame. |
| Window:_run_loop () | Internal: Run the defer loop. |
| Window.run (opts) | Create and immediately open a window. |
Class Modal
| Modal:new (opts) | Create a new Modal dialog. |
| Modal:set_result (result) | Set the modal result and close. |
| Modal:render_frame () | Render a modal frame. |
| Window.confirm (title, message, on_confirm, on_cancel) | Show a confirmation dialog. |
| Window.alert (title, message, on_close) | Show an alert dialog. |
Class Window
Window class for managing ImGui windows.
- Window:new (opts)
-
Create a new Window instance.
Parameters:
- opts table Window options
- title string Window title
- width number|nil Initial width (default 400)
- height number|nil Initial height (default 300)
- x number|nil Initial X position
- y number|nil Initial Y position
- flags number|nil Window flags
- closeable boolean|nil Whether window can be closed (default true)
- dockable boolean|nil Whether window can be docked (default false)
- on_open function|nil Called when window opens
- on_close function|nil Called when window closes
- on_draw function Required draw callback (receives gui context)
Returns:
-
Window
- opts table Window options
- Window:open (run_loop)
-
Open the window and start rendering.
Parameters:
- run_loop boolean|nil If true, runs the defer loop automatically
- Window:close ()
- Close the window. When called during on_draw, the actual close is deferred until after the frame.
- Window:_do_close ()
- Internal: Actually close the window (called after frame completes).
- Window:defer_action (action)
-
Queue an action to run after the current frame completes.
Useful for actions that shouldn't happen during on_draw.
Parameters:
- action function The function to call after the frame
- Window:is_open ()
-
Check if window is open.
Returns:
-
boolean
- Window:get_context ()
-
Get the ImGui context.
Returns:
-
Context
- Window:render_frame ()
-
Render a single frame.
Returns:
-
boolean True if window should continue, false if closed
- Window:_run_loop ()
- Internal: Run the defer loop.
- Window.run (opts)
-
Create and immediately open a window.
Parameters:
- opts table Window options (see Window:new)
Returns:
-
Window
Class Modal
Modal dialog class (extends Window behavior).
- Modal:new (opts)
-
Create a new Modal dialog.
Parameters:
- opts table Modal options (same as Window, plus result callback)
- on_result function|nil Called with result when modal closes
Returns:
-
Modal
- opts table Modal options (same as Window, plus result callback)
- Modal:set_result (result)
-
Set the modal result and close.
Parameters:
- result any The result value
- Modal:render_frame ()
-
Render a modal frame.
Returns:
-
boolean
- Window.confirm (title, message, on_confirm, on_cancel)
-
Show a confirmation dialog.
Parameters:
- title string Dialog title
- message string Message to display
- on_confirm function Called if user confirms
- on_cancel function|nil Called if user cancels
- Window.alert (title, message, on_close)
-
Show an alert dialog.
Parameters:
- title string Dialog title
- message string Message to display
- on_close function|nil Called when dialog closes