Skip to content

Gui (SDL2 Graphics)

Low-level 2D graphics, games, and creative coding. Uses SDL2 for cross-platform rendering with pixel-level control.

For desktop applications with system fonts and HTML/CSS, use the App module instead.

Prerequisites

bash
# macOS
brew install sdl2

# Linux
apt install libsdl2-dev

Quick Start

wyn
fn main() {
    Gui.create("My Game", 800, 600)
    while Gui.running() > 0 {
        var ev = Gui.poll()
        if ev.split_at("|", 0) == "key" {
            if ev.split_at("|", 1).to_int() == 27 { break }
        }
        Gui.clear(30, 30, 40)
        Gui.color(255, 100, 100)
        Gui.rect(100, 100, 200, 150)
        Gui.color(255, 255, 255)
        Gui.text(100, 80, "Hello!", 2)
        Gui.present()
        Gui.delay(16)
    }
    Gui.destroy()
}

API

Window

MethodDescription
Gui.create(title, w, h) -> intCreate window (-1 on failure)
Gui.destroy()Close window
Gui.running() -> int1 if window is open
Gui.width() -> intWindow width
Gui.height() -> intWindow height
Gui.present()Flip buffer to screen
Gui.delay(ms)Wait (use 16 for ~60fps)

Drawing

MethodDescription
Gui.clear(r, g, b)Clear screen with color
Gui.color(r, g, b)Set draw color (0-255)
Gui.rect(x, y, w, h)Filled rectangle
Gui.rect_outline(x, y, w, h)Rectangle outline
Gui.line(x1, y1, x2, y2)Line
Gui.point(x, y)Single pixel
Gui.circle(cx, cy, r)Filled circle

Text

MethodDescription
Gui.text(x, y, text, scale)Draw text (built-in 5x7 pixel font, scale 1-4)

Widgets

MethodDescription
Gui.panel(x, y, w, h)Dark panel background
Gui.button(x, y, w, h, label)Draw button
Gui.button_clicked(x, y, w, h, mx, my) -> intCheck if mouse is in button area
Gui.label(x, y, text, scale)Alias for text
Gui.progress(x, y, w, h, pct)Progress bar (0-100)

Input

MethodDescription
Gui.poll() -> stringGet event: "key|code|mod", "mouse|x|y|btn", "quit|0|0|0"
Gui.key_pressed(keycode) -> int1 if key is currently held
Gui.mouse_x() -> intCurrent mouse X
Gui.mouse_y() -> intCurrent mouse Y
Gui.mouse_down() -> int1 if left button held
Gui.ticks() -> intMilliseconds since start

When to Use Gui vs App

Gui (SDL2)App (WebView)
Use forGames, graphics, pixel artDesktop apps, forms, dashboards
FontsBuilt-in pixel fontSystem fonts (CSS)
LayoutManual coordinatesHTML/CSS
StylingColor + rectFull CSS
Binary size~50KB + SDL2~50KB (no deps on macOS)

MIT License