imgui
stableBuild immediate-mode UI layouts by declaring widgets into a UiContext and reading back the element list each frame.
use plugin imgui::{UiContext.new, button, label, …} Functions (21)
- UiContext.new Create a new UI context
- button Add a button widget
- label Add a text label widget
- slider Add a numeric slider widget
- checkbox Add a checkbox widget
- text_input Add a text input widget
- combo Add a dropdown combo box widget
- radio_button Add a radio button widget
- progress_bar Add a progress bar widget
- color_edit Add an RGBA color editor widget
- begin_panel Begin a collapsible panel group
- end_panel End the current panel group
- begin_tree_node Begin a tree node group
- end_tree_node End the current tree node
- begin_menu Begin a menu group
- end_menu End the current menu
- menu_item Add a menu item widget
- separator Add a horizontal separator
- same_line Place the next widget on the same line
- elements Get all declared widgets as a table
- clear Clear all widgets and reset IDs
Overview
imgui is a retained data layer for immediate-mode UIs: instead of drawing
pixels, it records the widgets you declare into a stateful UiContext handle and
hands the list back to you each frame so your own renderer can draw it. Every
widget call appends an element table (a map with a type tag, the widget's
properties, and a unique id) to the context, and grouping calls like
begin_panel/end_panel push marker elements so the renderer can reconstruct
nesting. The context is stateful: IDs auto-increment and persist until you
clear it, which is why the typical loop clears at the top of a frame, declares
fresh widgets, then reads elements at the bottom.
Use it when you want to describe a UI declaratively in Zolo and feed the resulting element list to a host (a game engine, a canvas, an ImGui binding) without owning any drawing code yourself.
Common patterns
Build a frame from scratch: clear, declare widgets, then read them back.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.clear()
ui.label("Settings")
ui.slider("Volume", 0.0, 1.0, 0.8)
ui.checkbox("Fullscreen", true)
for el in ui.elements() {
print("{el["type"]}")
}
Group related widgets inside a panel so the renderer can nest them.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.begin_panel("Audio")
ui.slider("Master", 0.0, 1.0, 0.7)
ui.slider("Music", 0.0, 1.0, 0.5)
ui.separator()
ui.checkbox("Mute", false)
ui.end_panel()
Lay out a button row using same_line between widgets.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.button("Save")
ui.same_line()
ui.button("Cancel")
let els = ui.elements()
print("first: {els[1]["type"]}")
Create a new UI context
Creates a new immediate-mode UI context. Declare widgets on it each frame, read back the element list, then pass it to your renderer.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.button("Click me")
let elems = ui.elements()
print(elems[1]["type"])
Add a text label widget
Adds a static text label. Returns {type: "label", text, id}.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.label("Player Health:")
ui.label("100 / 100")
Add a numeric slider widget
Adds a numeric slider widget. Returns {type: "slider", label, min, max, value, id}.
use plugin imgui::{UiContext}
let ui = UiContext.new()
let s = ui.slider("Volume", 0.0, 1.0, 0.75)
print(s["value"])
Add a checkbox widget
Adds a checkbox widget. Returns {type: "checkbox", label, checked, id}.
use plugin imgui::{UiContext}
let ui = UiContext.new()
let cb = ui.checkbox("Enable shadows", true)
print(cb["checked"])
Add a text input widget
Adds a text input field. Returns {type: "text_input", label, value, id}.
use plugin imgui::{UiContext}
let ui = UiContext.new()
let inp = ui.text_input("Username", "player1")
print(inp["value"])
Add a dropdown combo box widget
Adds a dropdown combo box. items is a table of strings; selected is the 0-based index of the current selection. Returns {type: "combo", label, items, selected, id}.
use plugin imgui::{UiContext}
let ui = UiContext.new()
let c = ui.combo("Quality", ["Low", "Medium", "High"], 1)
print(c["selected"])
Add a progress bar widget
Adds a progress bar. fraction is 0.0–1.0. overlay is text shown inside the bar (pass an empty string for none). Returns {type: "progress_bar", fraction, overlay, id}.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.progress_bar(0.65, "65%")
Add an RGBA color editor widget
Adds an RGBA color picker. Channel values are floats 0.0–1.0. Returns {type: "color_edit", label, r, g, b, a, id}.
use plugin imgui::{UiContext}
let ui = UiContext.new()
let col = ui.color_edit("Background", 0.1, 0.2, 0.3, 1.0)
print(col["r"])
Begin a collapsible panel group
Begins a named panel group. All widgets added after this call belong to the panel until end_panel is called.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.begin_panel("Settings")
ui.slider("Volume", 0.0, 1.0, 0.5)
ui.end_panel()
End the current panel group
Closes the current panel group opened with begin_panel.
Begin a tree node group
Opens a collapsible tree node. Widgets declared between begin_tree_node and end_tree_node are nested children.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.begin_tree_node("Advanced")
ui.checkbox("Debug mode", false)
ui.end_tree_node()
End the current tree node
Closes the current tree node opened with begin_tree_node.
Add a horizontal separator
Adds a horizontal separator line between widgets.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.label("Section A")
ui.separator()
ui.label("Section B")
Place the next widget on the same line
Instructs the renderer to place the next widget on the same horizontal line as the previous one.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.button("OK")
ui.same_line()
ui.button("Cancel")
Get all declared widgets as a table
Returns the complete list of declared widgets as a 1-indexed table of element tables. Call this at the end of a frame to hand off to your renderer.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.label("Hello")
ui.button("Go")
let elems = ui.elements()
print(elems[1]["type"])
print(elems[2]["type"])
Iterate the element list to drive your own renderer:
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.label("Status")
ui.progress_bar(0.5, "loading")
ui.button("Retry")
for el in ui.elements() {
print("draw {el["type"]}")
}
Clear all widgets and reset IDs
Removes all widgets from the context and resets element IDs to 1. Call this at the start of each frame to rebuild the UI.
use plugin imgui::{UiContext}
let ui = UiContext.new()
ui.button("Old button")
ui.clear()
ui.button("Fresh button")
let elems = ui.elements()
print(elems[1]["label"])