Gui Architecture
Axon GUI Architecture
Section titled βAxon GUI ArchitectureβCross-platform GUI framework for the Axon programming language.
Version: Draft β Pre-implementation
Status: Planning (M9-M12)
Target: macOS (primary), Linux, Windows
Axon apps are fully compiled native binaries that run on any OS with the Axon runtime installed. The GUI framework ships as part of the Axon distribution β no external dependencies required at deploy time.
Developer writes Axon code β axonc compiles β native binaryUser has Axon runtime installed β runs the appArchitecture Overview
Section titled βArchitecture Overviewβββββββββββββββββββββββββββββββββββββββββββββββββββββ Axon Application ββ (pure Axon code β business logic + UI) ββββββββββββββββββββββββββββββββββββββββββββββββββββ€β axon.ui Module (Axon) ββ Widgets, layout helpers, theme API ββββββββββββββββββββββββββββββββββββββββββββββββββββ€β UI Framework (C: libaxon_ui) ββ Layout engine, event dispatch, widget state ββββββββββββββββββββββββββββββββββββββββββββββββββββ€β Rendering Engine (C: libaxon_render) ββ Software rasterizer, text, images ββ GPU backends: Metal (macOS), Vulkan (Linux/Win)βββββββββββββ¬βββββββββββββββ¬ββββββββββββββββββββββββ€β macOS β Linux β Windows ββ AppKit β X11/Wayland β Win32 ββ (ObjC β (Xlib/ β (CreateWindow, ββ runtime)β libwayland) β WndProc) βββββββββββββ΄βββββββββββββββ΄ββββββββββββββββββββββββ Platform Abstraction Layer (C: libaxon_pal)Design Decisions
Section titled βDesign Decisionsβ1. C Runtime + Axon API
Section titled β1. C Runtime + Axon APIβThe platform-specific code is written in C (and Objective-C for macOS). Axon programs call into it via extern declarations. This means:
- Zero Objective-C/Win32/X11 knowledge needed for Axon developers
- Battle-tested C interop β no new FFI mechanisms required
- Ships with Axon β
libaxon_palandlibaxon_renderare part of the distribution
2. Software Rendering First
Section titled β2. Software Rendering FirstβThe initial renderer is a CPU-based 2D rasterizer β no GPU required. This ensures:
- Works everywhere (SSH, CI, headless, old hardware)
- Simpler implementation and debugging
- GPU backends (Metal, Vulkan) added later for performance
3. Immediate-Mode UI (MVP)
Section titled β3. Immediate-Mode UI (MVP)βThe first UI framework is immediate-mode (like Dear ImGui/Nuklear):
;; Every frame, describe the UI(if (ui.button ctx "Click Me") (set count (add count (i64 1))))(ui.label ctx (fmt "Count: {}" count))Why immediate-mode first:
- Fewer language features needed (no closures for callbacks)
- State lives in user code, not framework
- Simpler to implement and debug
- Good enough for tools, dashboards, and many apps
Future: Declarative mode (like SwiftUI) once Axon has closures and generics.
4. Flexbox Layout
Section titled β4. Flexbox LayoutβLayout uses a flexbox-like algorithm β the same model used by CSS, React Native, and Flutter. Well-understood, well-tested, handles 95% of UI layouts.
Platform Details
Section titled βPlatform DetailsβmacOS (Primary Target)
Section titled βmacOS (Primary Target)βUses the Objective-C runtime C API β no Objective-C compiler required:
// Create an NSWindow from pure Cid window = ((id(*)(id,SEL,CGRect,int,int,int))objc_msgSend)( ((id(*)(id,SEL))objc_msgSend)((id)objc_getClass("NSWindow"), sel_registerName("alloc")), sel_registerName("initWithContentRect:styleMask:backing:defer:"), frame, 15, 2, 0);Key runtime functions: objc_msgSend, objc_getClass, sel_registerName, class_addMethod.
Link flags: -framework Cocoa
Two backends:
- X11 (via Xlib) β widest compatibility, simpler API
- Wayland (via libwayland) β modern compositors, more complex
Framebuffer via MIT-SHM (X11) or wl_shm (Wayland) for zero-copy pixel blitting.
Link flags: -lX11 -lXext
Windows
Section titled βWindowsβUses Win32 API: CreateWindowEx, GetMessage/DispatchMessage loop, GDI for framebuffer.
Link flags: -lgdi32 -luser32 -lkernel32
Language Prerequisites
Section titled βLanguage PrerequisitesβThe GUI framework requires these language features (planned for M2-M5):
| Feature | Milestone | Why Needed |
|---|---|---|
| Function pointers | M2 | Event callbacks |
| Enums | M2 | Event types, widget states |
| Pattern matching | M2 | Event dispatch |
| Generics | M2 | Type-safe containers |
| Result types | M3 | Fallible operations |
| Multi-file modules | M4 | Code organization |
| Heap allocation | M5 | Widget trees, buffers |
| String type | M5 | Text everywhere |
| Dynamic arrays | M5 | Widget children |
| Hash maps | M5 | Widget lookup, styles |
Milestones
Section titled βMilestonesβ| Milestone | Focus | Key Deliverable |
|---|---|---|
| M9 | Platform Layer | libaxon_pal β windows, events, framebuffer |
| M10 | Rendering | libaxon_render β shapes, text, images |
| M11 | UI Framework | Layout, widgets, themes, axon.ui API |
| M12 | Polish | Full widgets, app bundling, tooling |
Future Directions
Section titled βFuture Directionsβ- Declarative UI β SwiftUI-like syntax with closures and reactive state
- Custom UI DSL β
.axuifiles compiled alongside.axscode - WebAssembly target β Run Axon GUI apps in browsers
- Mobile β iOS (UIKit) and Android (NDK) backends
- 3D rendering β Scene graph, shaders, game engine integration