NEW in v1.1

UI Constructs

Reox provides first-class language constructs for building native UIs on NeolyxOS. These compile directly to optimized C code with zero runtime overhead.

Variant (Tagged Unions)

variant declares a type-safe enumeration with optional associated data. Similar to Rust's enum or Swift's enum with associated values.

// Simple enumeration
variant Direction {
    Up,
    Down,
    Left,
    Right
}

// With associated data (tagged union)
variant Shape {
    Circle(radius: float),
    Rect(w: int, h: int)
}

// Compiles to C tagged union:
// typedef enum { SHAPE_CIRCLE, SHAPE_RECT } Shape_Tag;
// struct Shape { Shape_Tag tag; union { ... } data; };

Protocol (Interfaces)

protocol defines a contract of method signatures. Types conforming to a protocol must implement all required methods. Compiles to a vtable struct with function pointers.

protocol Renderable {
    fn render(ctx: int);
    fn size() -> int;
}

// Compiles to C vtable:
// typedef struct Renderable_vtable {
//     void (*render)(void* self, int64_t ctx);
//     int64_t (*size)(void* self);
// } Renderable_vtable;

Extension (Type Methods)

extension adds methods to an existing type without modifying its original definition. Methods are compiled as namespaced functions (e.g., Color_brighten).

struct Color { r: int, g: int, b: int }

extension Color {
    fn brighten(amount: int) -> int {
        return amount * 2;
    }
}

// Call as: Color_brighten(10)

Layer (View Components)

layer is the primary building block for UI. A layer can declare fields, signals, methods, and gesture handlers. It compiles to a C struct with callback slots and namespaced functions.

layer Button {
    signal on_click;
    let label: string = "Click";

    // Gesture handlers
    on_tap {
        emit on_click();
    }

    on_swipe(direction: int) {
        print("Swiped");
    }

    fn body() {
        let width: int = 800;
    }
}

Gesture Handlers: Layers support on_tap, on_pan, on_swipe, on_pinch, and on_rotate. Each generates a static C callback function (e.g., Button_on_tap(void* ctx)).

Panel (Top-Level Windows)

panel represents a top-level application window. It can set properties like title and size, and contains a root() method that defines the window content.

panel MainWindow {
    title: "My App",
    size: (800, 600),

    fn root() {
        let title: string = "REOX App";
    }
}

Constants & Type Aliases

// Compile-time constants
const MAX_WIDTH: int = 800;
const MAX_HEIGHT: int = 600;

// Type aliases
typealias Dimension = int;
typealias Callback = (int) -> void;

// Use the alias like the original type
let width: Dimension = MAX_WIDTH;

// Compiles to C:
// static const int64_t MAX_WIDTH = 800;
// typedef int64_t Dimension;

Compilation Overview

Every UI construct compiles to efficient, debuggable C. No virtual machine, no garbage collector.

Reox Construct

  • variant
  • protocol
  • extension
  • layer
  • const
  • typealias

C Output

  • C enum + tagged union struct
  • vtable struct (function pointers)
  • Namespaced standalone functions
  • Struct + signal slots + gesture callbacks
  • static const
  • typedef
DocsPackagesCommunityBlog