Getting Started with C
This guide shows how to create your first Azul application in C.
Quick Start
Download the pre-compiled library from releases and include azul.h in your project.
Hello World
// Your application state
typedef struct MyApp;
// Destructor (required by AZ_REFLECT)
void
;
// Layout function - converts state to UI
AzStyledDom
int
Naming Conventions
Functions are named Az + class name + _ + function name:
// Rust: app::App::new()
// Rust: dom::Dom::body()
Enums are named Az + enum name + _ + variant name:
// Rust: LayoutAlignItems::Stretch
AzLayoutAlignItems_Stretch
// Rust: Update::RefreshDom
Union enums use compile-time macros:
AzStyleCursorValue cursor = ;
Adding Callbacks
// Callback function
AzUpdate
// In layout function
AzDom button = ;
;
;
// Attach callback
AzEventFilter event = ;
;
Memory Management
Classes marked with "has destructor" have _delete() functions. Destructors
automatically call sub-destructors for all fields (no need to recurse manually):
AzApp app = ;
// ... use app ...
; // Cleans up app and all its contents
All classes can be deep-copied via _deepCopy() - note this can be expensive for large objects:
AzWindowCreateOptions w = ;
AzWindowCreateOptions copy = ;
Pattern Matching
Use _matchRef and _matchMut functions to emulate Rust pattern matching:
// Create a union enum
AzStyleCursorValue cursor = ;
// Destructure with const reference
AzStyleCursor* result;
if
// Destructure with mutable reference
AzStyleCursor* resultMut;
if
The difference between _matchRef() and _matchMut() is that _matchRef
takes a const* and _matchMut() takes a restrict* to the result.
The lifetime of result is equal to the lifetime of cursor since result
simply points to the payload of the tagged union.
The AZ_REFLECT Macro
The AZ_REFLECT macro enables runtime type reflection for RefAny. It generates:
YourType_upcast()- Convert your struct to RefAnyYourType_downcastRef()- Checked const borrow from RefAnyYourType_downcastRefMut()- Checked mutable borrow from RefAny
typedef struct MyStruct;
void // Destructor
;
// Usage:
// Create a RefAny from your struct
AzRefAny object = ;
// Read-only access (const borrow)
MyStructRef structref = ;
if
; // Release the borrow
// Mutable access (restrict borrow)
// Cannot borrow ref and refmut simultaneously - checked at runtime!
MyStructRefMut structrefmut = ;
if
; // Release the borrow
// Clean up - decreases refcount, calls destructor when 0
;
Vectors and Strings
Create vectors at compile time:
AzScanCodeVec v = ;
AzString s = ; // Compile-time string
Compilation
# Linux
# macOS
# Windows
Next Steps
- CSS Styling - Supported CSS properties
- Widgets - Interactive components
- Architecture - Framework design