API Reference
Complete reference for all MicroUI.jl functions and types.
Core Module
MicroUI.MicroUI — ModuleMicroUI.jl - A Julia implementation of an immediate mode GUI library
This module provides a complete immediate mode GUI (IMGUI) implementation in Julia, inspired by the microui C library. Immediate mode GUIs rebuild the entire interface each frame, making them simpler to reason about and integrate into applications.
Key concepts:
- No persistent widget state - everything is recreated each frame
- Direct integration with rendering backends
- Minimal memory allocations during runtime
- Command-based rendering system for backend independence
MicroUI.CLIPSTACK_SIZE — ConstantMaximum depth of clipping rectangle stack for nested clipping regions
MicroUI.COMMANDLIST_SIZE — ConstantSize of the command buffer in bytes - stores all rendering commands for a frame
MicroUI.CONTAINERPOOL_SIZE — ConstantSize of the container pool for efficient container reuse
MicroUI.CONTAINERSTACK_SIZE — ConstantMaximum depth of nested containers (windows, panels, etc.)
MicroUI.DEFAULT_STYLE — ConstantDefault visual style with dark theme colors Provides sensible defaults for all UI elements
MicroUI.HASH_INITIAL — ConstantHash constant for ID generation
MicroUI.IDSTACK_SIZE — ConstantMaximum depth of ID stack for hierarchical widget identification
MicroUI.LAYOUTSTACK_SIZE — ConstantMaximum depth of layout stack for nested layout contexts
MicroUI.MAX_FMT — ConstantMaximum length for number format strings
MicroUI.MAX_WIDTHS — ConstantMaximum number of columns in a layout row
MicroUI.REAL_FMT — ConstantDefault format string for real number display
MicroUI.RELATIVE — ConstantLayout positioning modes
MicroUI.ROOTLIST_SIZE — ConstantMaximum number of root containers (windows) that can be active simultaneously
MicroUI.SLIDER_FMT — ConstantDefault format string for slider values
MicroUI.TREENODEPOOL_SIZE — ConstantSize of the treenode pool for efficient treenode state management
MicroUI.UNCLIPPED_RECT — ConstantUnclipped rectangle for resetting clipping state
MicroUI.VERSION — ConstantCurrent version of the MicroUI library
MicroUI.BaseCommand — TypeBase header present in all command types Contains type information and size for command buffer traversal
MicroUI.ClipCommand — TypeClipping command to set the active clipping rectangle All subsequent rendering will be clipped to this region
MicroUI.ClipResult — TypeClipping test results when checking if a rectangle is visible within the clip region
- CLIP_NONE: Rectangle is fully visible, no clipping needed
- CLIP_PART: Rectangle is partially visible, clipping required
- CLIP_ALL: Rectangle is completely outside clip region, skip rendering
MicroUI.Color — TypeRGBA color with 8 bits per channel All color values in the library use this format
MicroUI.ColorId — TypePredefined color IDs for different UI elements These indices map to colors in the style's color array
MicroUI.Command — TypeAbstract base type for all rendering commands
MicroUI.CommandIterator — TypeIterator for traversing the command buffer Handles jump commands automatically for proper Z-order rendering
MicroUI.CommandList — TypeCommand buffer that stores all rendering commands for a frame Manages both binary command data and string storage
MicroUI.CommandPtr — TypePointer/index into the command buffer for command linking
MicroUI.CommandType — TypeTypes of rendering commands that can be stored in the command buffer Each command type corresponds to a specific rendering operation
MicroUI.Container — TypeContainer represents a window, panel, or other widget grouping Maintains its own command buffer region and layout state
MicroUI.Context — TypeMain context structure containing all UI state This is the primary object that applications interact with
MicroUI.Context — MethodCreate new context with default settings Applications should call init! after creation
MicroUI.Font — TypeFont handle - can be any type depending on rendering backend
MicroUI.IconCommand — TypeIcon drawing command for built-in symbols Icons are simple geometric shapes drawn at specified rectangles
MicroUI.IconId — TypeBuilt-in icon identifiers for common UI symbols Icons are drawn as simple geometric shapes
MicroUI.Id — TypeUnique identifier for widgets and containers, generated from strings
MicroUI.JumpCommand — TypeJump command for non-linear command buffer traversal Used to implement container Z-ordering and command list linking
MicroUI.Key — TypeKeyboard key flags for modifier keys and special keys Can be combined to check for key combinations
MicroUI.Layout — TypeLayout state for a container or layout context Manages positioning, sizing, and flow of widgets within a region
MicroUI.MouseButton — TypeMouse button flags that can be combined with bitwise operations Multiple buttons can be pressed simultaneously
MicroUI.Option — TypeOption flags for controlling widget and container behavior These flags can be combined using bitwise OR operations
MicroUI.PoolItem — TypePool item for efficient resource management Tracks when resources were last used for automatic cleanup
MicroUI.Real — TypeFloating point type used for numeric values throughout the library
MicroUI.Rect — TypeRectangle defined by position and size Forms the basis for all layout and clipping operations
MicroUI.RectCommand — TypeRectangle drawing command for filled rectangles Used for backgrounds, borders, and solid color areas
MicroUI.Result — TypeResult flags returned by interactive widgets Indicate what actions occurred during the last frame
MicroUI.Stack — TypeGeneric stack data structure with overflow protection Used for managing nested contexts (containers, clips, layouts, etc.)
MicroUI.Style — TypeVisual style configuration for the UI Contains colors, sizes, and other visual parameters
MicroUI.TextCommand — TypeText rendering command for drawing strings Includes position, color, and string data
MicroUI.Vec2 — Type2D integer vector for positions, sizes, and offsets Used extensively for layout calculations and positioning
Base.:* — MethodScale vector by scalar
Base.:+ — MethodAdd two vectors
Base.:- — MethodSubtract two vectors
Base.isempty — MethodCheck if stack is empty
MicroUI.begin_frame — MethodBegin a new frame of UI processing Must be called before any widgets or containers
MicroUI.begin_panel — MethodSimple panel widget
MicroUI.begin_panel_ex — MethodBegin panel container Creates nested container within current layout
MicroUI.begin_popup — MethodBegin popup window Creates auto-sizing popup with no title bar or resize controls
MicroUI.begin_root_container! — MethodInitialize root container for rendering Sets up command buffer region and hover detection
MicroUI.begin_treenode — MethodSimple treenode widget
MicroUI.begin_treenode_ex — MethodBegin collapsible treenode section Returns RES_ACTIVE if expanded
MicroUI.begin_window — MethodSimple window widget
MicroUI.begin_window_ex — MethodBegin window with full customization options Creates moveable, resizable window with title bar and optional controls
MicroUI.bring_to_front! — MethodBring container to front by updating its Z-index Higher Z-index containers are rendered on top
MicroUI.button — MethodSimple button widget with label Default button with center-aligned text
MicroUI.button_ex — MethodButton widget with full customization options Returns RES_SUBMIT flag when clicked
MicroUI.check_clip — MethodTest if rectangle is visible within current clipping region Returns clipping result for optimization decisions
MicroUI.checkbox! — MethodCheckbox widget for boolean values Returns RES_CHANGE when toggled
MicroUI.clamp — MethodClamp value between minimum and maximum bounds
MicroUI.compare_zindex — MethodCompare containers by Z-index for sorting
MicroUI.default_draw_frame — MethodDefault frame drawing function Draws a filled rectangle with optional border
MicroUI.draw_box! — MethodDraw rectangle outline (border) Draws four separate rectangles for top, bottom, left, and right edges
MicroUI.draw_control_frame! — MethodDraw control frame with state-dependent styling Automatically selects color based on focus and hover state
MicroUI.draw_control_text! — MethodDraw control text with proper alignment and clipping Handles text positioning within widget rectangles
MicroUI.draw_icon! — MethodDraw built-in icon with automatic clipping Icons are simple geometric shapes rendered by the backend
MicroUI.draw_rect! — MethodDraw filled rectangle with clipping Only draws visible portions of the rectangle
MicroUI.draw_scrollbar! — MethodDraw scrollbar for given axis Handles scrollbar interaction and thumb positioning
MicroUI.draw_text! — MethodDraw text string with automatic clipping handling Sets up clipping if needed and creates text command
MicroUI.end_frame — MethodEnd current frame and prepare command buffer for rendering Handles container sorting, scrolling, and focus management
MicroUI.end_panel — MethodEnd panel container
MicroUI.end_popup — MethodEnd popup window
MicroUI.end_root_container! — MethodFinalize root container Sets up command buffer tail and cleans up stacks
MicroUI.end_treenode — MethodEnd treenode section
MicroUI.end_window — MethodEnd window and clean up
MicroUI.expand_rect — MethodExpand rectangle by given amount in all directions Useful for creating borders and padding
MicroUI.expand_rect — MethodExpand rectangle by n pixels in all directions
MicroUI.format_real — MethodFormat real numbers for display in widgets Provides consistent number formatting throughout the UI
MicroUI.get_clip_rect — MethodGet current clipping rectangle
MicroUI.get_container — MethodConvenience function to get container by name
MicroUI.get_container — MethodGet or create container with given ID Uses pool for efficient container reuse
MicroUI.get_current_container — MethodGet current container from container stack
MicroUI.get_id — MethodGenerate unique ID from string data Uses FNV-1a hash algorithm for consistent ID generation
MicroUI.get_layout — MethodGet current layout context from stack
MicroUI.get_string — MethodRetrieve a string from the string table by index Used when processing text commands during rendering
MicroUI.header — MethodSimple header widget
MicroUI.header_ex — MethodHeader widget for grouping content
MicroUI.header_impl — MethodImplementation for header and treenode widgets Handles expand/collapse state and visual styling
MicroUI.in_hover_root — MethodCheck if current container stack contains the hover root Used to determine if widgets should respond to mouse input
MicroUI.init! — MethodInitialize or reset context to default state Should be called before first use and when resetting UI state
MicroUI.input_keydown! — MethodHandle key press event
MicroUI.input_keyup! — MethodHandle key release event
MicroUI.input_mousedown! — MethodConvenience overload for Int32 coordinates
MicroUI.input_mousedown! — MethodHandle mouse button press event
MicroUI.input_mousemove! — MethodUpdate mouse position
MicroUI.input_mouseup! — MethodConvenience overload for Int32 coordinates
MicroUI.input_mouseup! — MethodHandle mouse button release event
MicroUI.input_scroll! — MethodHandle mouse scroll wheel input
MicroUI.input_text! — MethodAdd text input for current frame
MicroUI.intersect_rects — MethodCalculate intersection of two rectangles Returns rectangle representing overlapping area
MicroUI.label — MethodSimple text label widget Displays single line of text within widget rectangle
MicroUI.layout_begin_column! — MethodStart column layout context within current layout
MicroUI.layout_end_column! — MethodEnd column layout and merge extents with parent Updates parent layout's position and maximum extents
MicroUI.layout_height! — MethodSet default height for next widget
MicroUI.layout_next — MethodCalculate and return rectangle for next widget Handles both manual positioning and automatic layout flow
MicroUI.layout_row! — MethodSet up new layout row with specified items and dimensions Controls how widgets are positioned horizontally
MicroUI.layout_set_next! — MethodManually set rectangle for next widget Can be relative to current position or absolute
MicroUI.layout_width! — MethodSet default width for next widget
MicroUI.mouse_over — MethodTest if mouse is over widget rectangle Considers clipping and hover root for proper interaction
MicroUI.next_command! — MethodAdvance iterator to next command, handling jumps automatically Returns (hascommand, commandtype, command_offset)
MicroUI.number! — MethodSimple number widget Default number input with standard step and formatting
MicroUI.number_ex! — MethodNumber input widget with drag adjustment Allows precise number input and mouse drag adjustment
MicroUI.number_textbox! — MethodNumber editing textbox for slider/number widgets Handles special number editing mode with shift+click
MicroUI.open_popup! — MethodOpen popup window at mouse position Sets up popup to appear at current mouse location
MicroUI.pool_get — MethodFind pool item by ID Returns index if found, -1 if not found
MicroUI.pool_init! — MethodInitialize pool item with given ID Finds least recently used slot and assigns it to the ID
MicroUI.pool_update! — MethodUpdate pool item's last access time to current frame
MicroUI.pop! — MethodPop item from stack with underflow checking
MicroUI.pop_clip_rect! — MethodRemove current clipping rectangle from stack
MicroUI.pop_container! — MethodPop container and update its content size Called when exiting containers to finalize layout
MicroUI.pop_id! — MethodPop ID scope from stack
MicroUI.push! — MethodPush item onto stack with overflow checking
MicroUI.push_clip_rect! — MethodPush new clipping rectangle onto stack
MicroUI.push_command! — MethodAdd command to command buffer Returns offset where command was written
MicroUI.push_container_body! — MethodSet up container body with scrollbars and layout Prepares container for content rendering
MicroUI.push_id! — MethodPush new ID scope onto ID stack Creates hierarchical namespace for widget IDs
MicroUI.push_jump_command! — MethodAdd jump command for non-linear command buffer traversal Used to implement container Z-ordering
MicroUI.push_layout! — MethodCreate new layout context with given body rectangle and scroll offset Used when entering containers or column layouts
MicroUI.push_text_command! — MethodAdd text rendering command with string data Handles string storage and creates complete text command
MicroUI.read_command — MethodRead a command from the buffer at the specified offset Type parameter specifies which command type to read
MicroUI.rect_overlaps_vec2 — MethodTest if point is inside rectangle Used for hit testing and mouse interaction
MicroUI.scrollbars! — MethodHandle scrollbars for container Adjusts body rectangle to make room for scrollbars
MicroUI.set_clip! — MethodSet clipping rectangle for subsequent rendering commands
MicroUI.set_focus! — MethodSet keyboard focus to specific widget Widget will receive keyboard input and be highlighted
MicroUI.slider! — MethodSimple slider widget Default slider with standard formatting
MicroUI.slider_ex! — MethodSlider widget with full customization Allows dragging to adjust value within specified range
MicroUI.text — MethodMulti-line text display widget Automatically handles word wrapping and line breaks
MicroUI.textbox! — MethodSimple textbox widget Default textbox with no special options
MicroUI.textbox_ex! — MethodTextbox widget with options Provides text input with specified buffer size
MicroUI.textbox_raw! — MethodRaw textbox implementation with full control Handles text input, editing, and cursor display
MicroUI.top — MethodGet top item from stack without removing it
MicroUI.update_control! — MethodUpdate widget interaction state Handles hover, focus, and click detection for interactive widgets
MicroUI.write_command! — MethodWrite a command to the command buffer Returns the offset where the command was written
MicroUI.write_string! — MethodStore a string in the command list and return its index Used by text commands to reference their string data
Macro DSL
MicroUI.Macros.WIDGET_STATES — ConstantGlobal registry of all widget states, keyed by window ID
MicroUI.Macros.WidgetState — TypeWidget state container that persists between frames. Stores variables, refs for stateful widgets, event handlers, and window state.
MicroUI.Macros.clear_widget_states! — MethodClear all widget states (useful for testing and cleanup)
MicroUI.Macros.ensure_int_vector — MethodConvert to proper vector type for layout.
MicroUI.Macros.ensure_real — MethodConvert to Real (Float32) for MicroUI consistency.
MicroUI.Macros.get_widget_state — MethodGet or create widget state for a given window ID. Returns the same instance for the same window across multiple frames.
MicroUI.Macros.parse_assignment — MethodParse assignment expressions like 'var = value'. Returns (variablename, valueexpression) tuple.
MicroUI.Macros.@button — MacroButton widget. Usage: @button name = "text"
MicroUI.Macros.@checkbox — MacroCheckbox widget with bulletproof type handling. Usage: @checkbox name = true/false
MicroUI.Macros.@close_window — MacroClose window macro. Usage: @close_window "Window Title"
MicroUI.Macros.@column — MacroColumn layout. Usage: @column begin ... end
MicroUI.Macros.@context — MacroContext management macro for MicroUI.
Creates and manages a MicroUI context with proper frame lifecycle. All windows and UI elements must be inside a @context block.
Usage:
ctx = @context begin
@window "My Window" begin
@var message = "Hello World"
end
endReturns the MicroUI Context with all rendering commands.
MicroUI.Macros.@debug_types — MacroDebug macro to check types of widget state values. Usage: @debugtypes windowname
MicroUI.Macros.@foreach — MacroLoop for dynamic widgets. Usage: @foreach i in 1:5 begin ... end
MicroUI.Macros.@maxlength — MacroHelper macro for maxlength with proper types. Usage: maxlength(256) -> Int value
MicroUI.Macros.@number — MacroNumber widget macro for precise numeric input. Usage: @number num_name = 10.0 step(1.0)
MicroUI.Macros.@onclick — MacroClick event handler. Usage: @onclick widget_name begin ... end
MicroUI.Macros.@open_window — MacroOpen window macro. Usage: @open_window "Window Title"
MicroUI.Macros.@panel — MacroPanel macro for grouped widgets. Usage: @panel "Title" begin ... end
MicroUI.Macros.@popup — MacroPopup message. Usage: @popup "message"
MicroUI.Macros.@range — MacroHelper macro for creating ranges with proper types. Usage: range(0.0, 1.0) -> tuple of Real values
MicroUI.Macros.@reactive — MacroReactive computation using window state variables. Usage: @reactive result = windowstate.variables[:var1] + windowstate.variables[:var2] Or use helper: @reactive result = @v(var1) + @v(var2)
MicroUI.Macros.@row — MacroRow layout with proper integer types. Usage: @row [100, 200, -1] begin ... end
MicroUI.Macros.@simple_label — MacroSimple label widget. Usage: @simple_label name = "text"
MicroUI.Macros.@slider — MacroSlider widget with bulletproof type handling. Usage: @slider name = initial_value range(low, high)
MicroUI.Macros.@state — MacroVariable access helper for reactive expressions. Usage: @state(variable_name) -> gets value from window state
MicroUI.Macros.@step — MacroHelper macro for steps with proper types. Usage: step(1.0) -> Real value
MicroUI.Macros.@text — MacroText display widget. Usage: @text name = "content"
MicroUI.Macros.@textbox — MacroTextbox widget macro for text input. Usage: @textbox text_name = "default text" maxlength(256)
MicroUI.Macros.@var — MacroVariable assignment - stores in state only. Usage: @var name = value
MicroUI.Macros.@when — MacroConditional rendering macro. Usage: @when condition begin ... end
MicroUI.Macros.@window — MacroWindow macro for use within @context blocks.
Creates a window with automatic state management. Must be used inside a @context block. The window state persists between frames for stateful widgets.
Usage:
@context begin
@window "Window Title" begin
@var message = "Hello"
end
endUsage Examples
Basic Application
using MicroUI
# Create context
ctx = Context()
init!(ctx)
# Set up text callbacks
ctx.text_width = (font, str) -> length(str) * 8
ctx.text_height = font -> 16
# Main loop
begin_frame(ctx)
if begin_window(ctx, "My App", Rect(50, 50, 300, 200)) != 0
text(ctx, "Hello, MicroUI!")
if button(ctx, "Click me!") != 0
println("Button clicked!")
end
end_window(ctx)
end
end_frame(ctx)Using Macro DSL
using MicroUI
using MicroUI.Macros
ctx = @context begin
@window "Settings" begin
@var title = "Application Settings"
@text header = title
@checkbox auto_save = true
@slider volume = 0.5 range(0.0, 1.0)
@button save_btn = "Save"
@onclick save_btn begin
@popup "Settings saved!"
end
end
endIntegration with Rendering Backends
MicroUI generates rendering commands that you pass to your graphics backend:
ctx = @context begin
# ... your UI code ...
end
# Process rendering commands
iter = CommandIterator(ctx.command_list)
while true
(has_cmd, cmd_type, cmd_idx) = next_command!(iter)
if !has_cmd
break
end
if cmd_type == MicroUI.COMMAND_RECT
rect_cmd = read_command(ctx.command_list, cmd_idx, RectCommand)
# Draw rectangle: rect_cmd.rect, rect_cmd.color
elseif cmd_type == MicroUI.COMMAND_TEXT
text_cmd = read_command(ctx.command_list, cmd_idx, TextCommand)
text_str = get_string(ctx.command_list, text_cmd.str_index)
# Draw text: text_str at text_cmd.pos with text_cmd.color
end
# ... handle other command types
endRequired Callbacks
Before using MicroUI, set these callbacks on your context:
ctx.text_width = (font, str) -> Int # Measure text width
ctx.text_height = font -> Int # Get font height
ctx.draw_frame = (ctx, rect, colorid) -> Nothing # Draw widget frames (optional)