API Reference

Complete reference for all MicroUI.jl functions and types.

Core Module

MicroUI.MicroUIModule

MicroUI.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
source
MicroUI.BaseCommandType

Base header present in all command types Contains type information and size for command buffer traversal

source
MicroUI.ClipCommandType

Clipping command to set the active clipping rectangle All subsequent rendering will be clipped to this region

source
MicroUI.ClipResultType

Clipping 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
source
MicroUI.ColorType

RGBA color with 8 bits per channel All color values in the library use this format

source
MicroUI.ColorIdType

Predefined color IDs for different UI elements These indices map to colors in the style's color array

source
MicroUI.CommandIteratorType

Iterator for traversing the command buffer Handles jump commands automatically for proper Z-order rendering

source
MicroUI.CommandListType

Command buffer that stores all rendering commands for a frame Manages both binary command data and string storage

source
MicroUI.CommandTypeType

Types of rendering commands that can be stored in the command buffer Each command type corresponds to a specific rendering operation

source
MicroUI.ContainerType

Container represents a window, panel, or other widget grouping Maintains its own command buffer region and layout state

source
MicroUI.ContextType

Main context structure containing all UI state This is the primary object that applications interact with

source
MicroUI.ContextMethod

Create new context with default settings Applications should call init! after creation

source
MicroUI.IconCommandType

Icon drawing command for built-in symbols Icons are simple geometric shapes drawn at specified rectangles

source
MicroUI.IconIdType

Built-in icon identifiers for common UI symbols Icons are drawn as simple geometric shapes

source
MicroUI.IdType

Unique identifier for widgets and containers, generated from strings

source
MicroUI.JumpCommandType

Jump command for non-linear command buffer traversal Used to implement container Z-ordering and command list linking

source
MicroUI.KeyType

Keyboard key flags for modifier keys and special keys Can be combined to check for key combinations

source
MicroUI.LayoutType

Layout state for a container or layout context Manages positioning, sizing, and flow of widgets within a region

source
MicroUI.MouseButtonType

Mouse button flags that can be combined with bitwise operations Multiple buttons can be pressed simultaneously

source
MicroUI.OptionType

Option flags for controlling widget and container behavior These flags can be combined using bitwise OR operations

source
MicroUI.PoolItemType

Pool item for efficient resource management Tracks when resources were last used for automatic cleanup

source
MicroUI.RealType

Floating point type used for numeric values throughout the library

source
MicroUI.RectType

Rectangle defined by position and size Forms the basis for all layout and clipping operations

source
MicroUI.RectCommandType

Rectangle drawing command for filled rectangles Used for backgrounds, borders, and solid color areas

source
MicroUI.ResultType

Result flags returned by interactive widgets Indicate what actions occurred during the last frame

source
MicroUI.StackType

Generic stack data structure with overflow protection Used for managing nested contexts (containers, clips, layouts, etc.)

source
MicroUI.StyleType

Visual style configuration for the UI Contains colors, sizes, and other visual parameters

source
MicroUI.Vec2Type

2D integer vector for positions, sizes, and offsets Used extensively for layout calculations and positioning

source
MicroUI.begin_window_exMethod

Begin window with full customization options Creates moveable, resizable window with title bar and optional controls

source
MicroUI.buttonMethod

Simple button widget with label Default button with center-aligned text

source
MicroUI.button_exMethod

Button widget with full customization options Returns RES_SUBMIT flag when clicked

source
MicroUI.check_clipMethod

Test if rectangle is visible within current clipping region Returns clipping result for optimization decisions

source
MicroUI.draw_box!Method

Draw rectangle outline (border) Draws four separate rectangles for top, bottom, left, and right edges

source
MicroUI.draw_icon!Method

Draw built-in icon with automatic clipping Icons are simple geometric shapes rendered by the backend

source
MicroUI.draw_text!Method

Draw text string with automatic clipping handling Sets up clipping if needed and creates text command

source
MicroUI.end_frameMethod

End current frame and prepare command buffer for rendering Handles container sorting, scrolling, and focus management

source
MicroUI.expand_rectMethod

Expand rectangle by given amount in all directions Useful for creating borders and padding

source
MicroUI.format_realMethod

Format real numbers for display in widgets Provides consistent number formatting throughout the UI

source
MicroUI.get_idMethod

Generate unique ID from string data Uses FNV-1a hash algorithm for consistent ID generation

source
MicroUI.get_stringMethod

Retrieve a string from the string table by index Used when processing text commands during rendering

source
MicroUI.header_implMethod

Implementation for header and treenode widgets Handles expand/collapse state and visual styling

source
MicroUI.in_hover_rootMethod

Check if current container stack contains the hover root Used to determine if widgets should respond to mouse input

source
MicroUI.init!Method

Initialize or reset context to default state Should be called before first use and when resetting UI state

source
MicroUI.labelMethod

Simple text label widget Displays single line of text within widget rectangle

source
MicroUI.layout_nextMethod

Calculate and return rectangle for next widget Handles both manual positioning and automatic layout flow

source
MicroUI.layout_row!Method

Set up new layout row with specified items and dimensions Controls how widgets are positioned horizontally

source
MicroUI.mouse_overMethod

Test if mouse is over widget rectangle Considers clipping and hover root for proper interaction

source
MicroUI.next_command!Method

Advance iterator to next command, handling jumps automatically Returns (hascommand, commandtype, command_offset)

source
MicroUI.number!Method

Simple number widget Default number input with standard step and formatting

source
MicroUI.number_ex!Method

Number input widget with drag adjustment Allows precise number input and mouse drag adjustment

source
MicroUI.pool_init!Method

Initialize pool item with given ID Finds least recently used slot and assigns it to the ID

source
MicroUI.push_id!Method

Push new ID scope onto ID stack Creates hierarchical namespace for widget IDs

source
MicroUI.push_layout!Method

Create new layout context with given body rectangle and scroll offset Used when entering containers or column layouts

source
MicroUI.read_commandMethod

Read a command from the buffer at the specified offset Type parameter specifies which command type to read

source
MicroUI.set_focus!Method

Set keyboard focus to specific widget Widget will receive keyboard input and be highlighted

source
MicroUI.slider_ex!Method

Slider widget with full customization Allows dragging to adjust value within specified range

source
MicroUI.textMethod

Multi-line text display widget Automatically handles word wrapping and line breaks

source
MicroUI.write_string!Method

Store a string in the command list and return its index Used by text commands to reference their string data

source

Macro DSL

MicroUI.Macros.WidgetStateType

Widget state container that persists between frames. Stores variables, refs for stateful widgets, event handlers, and window state.

source
MicroUI.Macros.@contextMacro

Context 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
end

Returns the MicroUI Context with all rendering commands.

source
MicroUI.Macros.@rangeMacro

Helper macro for creating ranges with proper types. Usage: range(0.0, 1.0) -> tuple of Real values

source
MicroUI.Macros.@reactiveMacro

Reactive computation using window state variables. Usage: @reactive result = windowstate.variables[:var1] + windowstate.variables[:var2] Or use helper: @reactive result = @v(var1) + @v(var2)

source
MicroUI.Macros.@stateMacro

Variable access helper for reactive expressions. Usage: @state(variable_name) -> gets value from window state

source
MicroUI.Macros.@windowMacro

Window 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
end
source

Usage 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
end

Integration 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
end

Required 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)