Tutorial: Building a Desktop Application

Build rich, 120 FPS hardware-accelerated desktop GUI applications with Material Design 3 and native OS integration using std.ui.

1. Initializing the Desktop Project

nyx init nyx-studio-app --template desktop
cd nyx-studio-app

2. Building the Material UI Interface

Use Nyx's declarative GUI component trees to construct the application window:

import std.ui
import std.io

pub fn main() {
    // 1. Initialize native window with theme and dimensions
    let mut app = ui.create_app("Nyx Mission Studio", 1024, 768)
    app.set_theme(ui.Theme.MaterialDark)

    // 2. Build Sidebar Navigation & Main Content View
    let mut window = ui.Window::new("Nyx Analytics Dashboard")

    let header = ui.Card::elevated("Real-Time Telemetry Feed")
        .with_padding(16.0)
        .with_content(ui.Text::headline("Active Nodes: 128 | Latency: 4.2ms"))

    let start_btn = ui.Button::filled("Launch Inference Engine")
        .with_icon("rocket_launch")
        .on_click(|| {
            std.io.println("Inference engine launched on GPU 0!")
        })

    let slider = ui.Slider::continuous(0.0, 100.0, 75.0)
        .on_change(|val| {
            std.io.println("Threshold updated: " + val.to_string())
        })

    // 3. Assemble Layout Hierarchy
    window.add_child(header)
    window.add_child(start_btn)
    window.add_child(slider)

    // 4. Start 120 FPS Event Loop
    app.run(window)
}

3. Native OS Features

Nyx provides direct access to system tray icons, native file dialogues, and GPU rendering surfaces (Vulkan, DirectX 12, Metal):

import std.ui.dialog

let selected_file = dialog.open_file_picker("Select GeoTIFF Raster", ["*.tif", "*.tiff"])
match selected_file {
    Option.Some(path) => std.io.println("Loaded file: " + path),
    Option.None => std.io.println("File selection cancelled"),
}

4. Packaging Native Executables

# Build standalone Windows executable
nyx build --release --target x86_64-pc-windows-msvc

# Build macOS universal binary (.app bundle)
nyx package --target universal-apple-darwin

# Build Linux AppImage
nyx package --target x86_64-unknown-linux-gnu