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-devQuick 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
| Method | Description |
|---|---|
Gui.create(title, w, h) -> int | Create window (-1 on failure) |
Gui.destroy() | Close window |
Gui.running() -> int | 1 if window is open |
Gui.width() -> int | Window width |
Gui.height() -> int | Window height |
Gui.present() | Flip buffer to screen |
Gui.delay(ms) | Wait (use 16 for ~60fps) |
Drawing
| Method | Description |
|---|---|
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
| Method | Description |
|---|---|
Gui.text(x, y, text, scale) | Draw text (built-in 5x7 pixel font, scale 1-4) |
Widgets
| Method | Description |
|---|---|
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) -> int | Check 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
| Method | Description |
|---|---|
Gui.poll() -> string | Get event: "key|code|mod", "mouse|x|y|btn", "quit|0|0|0" |
Gui.key_pressed(keycode) -> int | 1 if key is currently held |
Gui.mouse_x() -> int | Current mouse X |
Gui.mouse_y() -> int | Current mouse Y |
Gui.mouse_down() -> int | 1 if left button held |
Gui.ticks() -> int | Milliseconds since start |
When to Use Gui vs App
| Gui (SDL2) | App (WebView) | |
|---|---|---|
| Use for | Games, graphics, pixel art | Desktop apps, forms, dashboards |
| Fonts | Built-in pixel font | System fonts (CSS) |
| Layout | Manual coordinates | HTML/CSS |
| Styling | Color + rect | Full CSS |
| Binary size | ~50KB + SDL2 | ~50KB (no deps on macOS) |