Gui — native windows
Gui is the built-in backend for real native windows: a pixel framebuffer with shapes, real Unicode text, images, and full input. It is what serez-ui draws on — most apps use the library, but the raw primitives are here when you want to draw yourself.
Gui permission.Under the hood: winit (cross-platform window + input + IME) + softbuffer (a CPU framebuffer — software rendering, no GPU) + cosmic-text (real font rasterization, so accents and Unicode render) + the image crate (PNG/JPG) + arboard (clipboard). Colors are 0xRRGGBB integers. Methods marked new arrived in Serez-Code 7.2.0.
The loop
Open a window, then loop while it is open: clear, draw, and present() (which shows the frame and polls input). idleWait(ms) sleeps until the next event (or a timeout) so an idle window costs ~0 CPU.
use permissions { Gui }
Gui.open("Demo", 480, 320)
while (Gui.isOpen()) {
Gui.clear(0x0f172a)
Gui.fillCircle(240, 160, 60, 0x3b82f6)
Gui.drawText(20, 20, "hello", 2, 0xffffff)
Gui.present() // show the frame + read input
Gui.idleWait(100) // sleep until an event (CPU ~0 at rest)
}
Gui.close()| Method | Returns | Notes |
|---|---|---|
Gui.open(title, w, h) | — | Open the window |
Gui.isOpen() | bool | Still open? (false after Esc / close button) |
Gui.clear(color) | — | Fill the whole canvas |
Gui.present() | — | Blit the frame + poll events |
Gui.idleWait(maxMs) | — | Sleep until input or timeout (idle = ~0 CPU) |
Gui.close() | — | Close the window |
Gui.size() | [w, h] | Current inner size (px) |
Gui.time() | int | ms since the window opened (for animation) |
Drawing
Filled and outlined shapes, gradients, a box blur, and — new — vector primitives for charts and custom graphics (thick anti-aliased lines, polylines, filled polygons). Coordinates are integers; a polyline/polygon takes a flat [x0, y0, x1, y1, ...] array.
| Method | Notes |
|---|---|
Gui.fillRect(x, y, w, h, color) | Filled rectangle |
Gui.fillRectAlpha(x, y, w, h, color, alpha) | Filled rect blended at alpha 0–255 (scrims, highlights) |
Gui.drawRect(x, y, w, h, color) | 1px outline |
Gui.fillRoundRect(x, y, w, h, radius, color) | Rounded filled rect (anti-aliased corners) |
Gui.drawLine(x0, y0, x1, y1, color) | 1px line |
Gui.fillCircle(cx, cy, r, color) | Anti-aliased filled disc |
Gui.setPixel(x, y, color) | Single pixel |
Gui.fillGradient(x, y, w, h, c1, c2, vertical) | Linear gradient (vertical = bool) |
Gui.blur(x, y, w, h, radius) | Box blur a region in place (frosted panels/shadows) |
Gui.drawLineThick(x0, y0, x1, y1, width, color) | new — thick line, rounded ends/joins |
Gui.drawPolyline(points, width, color) | new — connected segments (line charts) |
Gui.fillPolygon(points, color) | new — filled polygon (even-odd; concave OK) |
Gui.drawCircle(cx, cy, r, color) | new — 1px circle outline |
Gui.drawPolyline([20, 160, 80, 110, 140, 140, 200, 80], 3, 0xd32f2f) // line chart
Gui.fillPolygon([300, 280, 380, 120, 460, 280], 0x2e7d32) // filled triangle
Gui.drawLineThick(20, 40, 220, 40, 6, 0x1565c0)Text
drawText rasterizes real glyphs. The optional style is a bitfield: 1 bold, 2 italic, and — new — 4 underline, 8 strikethrough (combine them, e.g. 5 = bold + underline). A seventh argument sets letter-spacing (new). Load a .ttf/.otf with loadFont and select it with setFont.
| Method | Returns | Notes |
|---|---|---|
Gui.drawText(x, y, text, scale, color) | — | Draw text (also …, style and …, style, letterSpacing) |
Gui.measureText(text, scale) | [w] | Pixel width (index [0]) |
Gui.textAdvances(text, scale) | [x0, x1, …] | Cumulative x per character (caret placement) |
Gui.loadFont(path) | — | Load a .ttf/.otf |
Gui.setFont(name) | — | Select a family ("" = default mono grid) |
Gui.setImePosition(x, y) | — | Where the OS IME popup appears |
Gui.drawText(20, 20, "Bold underline", 2, 0x111111, 1 + 4) // style bits
Gui.drawText(20, 60, "S p a c e d", 2, 0x111111, 0, 6) // letterSpacing = 6Images
Load an image to a handle, then draw it (optionally scaled, with global alpha). Load from a file, or — new — from bytes in memory (a fetched image, or one read with File.read_asBinary).
| Method | Returns | Notes |
|---|---|---|
Gui.loadImage(path) | handle | Decode a PNG/JPG file |
Gui.loadImageBytes(bytes) | handle | new — decode from an in-memory byte array |
Gui.drawImage(x, y, handle) | — | Also …, w, h (scale) and …, w, h, alpha |
Gui.imageSize(handle) | [w, h] | Natural size |
Input
After each present(), read the current input. Alongside mouse/keyboard, 7.2.0 added window focus, IME composition, file drag-drop, extra mouse buttons, and touch/pinch — all new.
| Method | Returns | Notes |
|---|---|---|
Gui.mouse() | [x, y] | Cursor position |
Gui.mouseDown() / mouseRightDown() / mouseMiddleDown() | bool | Button held |
Gui.scroll() | [dx, dy] | Wheel delta this frame |
Gui.keyDown(name) | bool | Key held (e.g. "Shift", "a") |
Gui.keysPressed() / keysRepeated() / keysReleased() | [names] | Key edges this frame |
Gui.charsTyped() | string | Text typed this frame (respects OS layout/IME) |
Gui.focused() | bool | new — window has OS focus |
Gui.mouseInWindow() | bool | new — cursor is over the window |
Gui.mouseBackDown() / mouseForwardDown() | bool | new — side buttons |
Gui.imePreedit() | string | new — CJK composition in progress ("" if none) |
Gui.droppedFiles() | [paths] | new — files dropped this frame (needs File to read) |
Gui.hoveredFiles() | [paths] | new — files dragged over the window (before dropping) |
Gui.touches() | [id, phase, x, y, …] | new — flat touch points (phase 0=start/1=move/2=end/3=cancel) |
Gui.pinchDelta() | decimal | new — trackpad pinch/zoom this frame |
Window control
Retitle, resize, move, and decorate the window. Most of the ops below (max size, minimize, always-on-top, taskbar attention, hide cursor, borderless drag, custom icon) are new in 7.2.0.
| Method | Notes |
|---|---|
Gui.setTitle(text) | Change the title bar text |
Gui.setMinSize(w, h) / setMaxSize(w, h) | Size limits (setMaxSize is new; 0,0 = none) |
Gui.setResizable(b) / setDecorations(b) | Toggle resize / the title bar + border |
Gui.setFullscreen(b) / maximize(b) / minimize(b) | Window state (minimize is new) |
Gui.setPosition(x, y) | Move the window |
Gui.dragWindow() | new — start an OS window drag (custom title bars); call on mousedown |
Gui.setAlwaysOnTop(b) | new — keep above other windows |
Gui.requestAttention(b) | new — flash the taskbar entry |
Gui.setCursorVisible(b) | new — hide/show the cursor |
Gui.setWindowIcon(path) | new — app icon ("" removes it) |
Cursor, clipboard & dialogs
| Method | Returns | Notes |
|---|---|---|
Gui.setCursor(name) | — | Named cursor ("hand", "text", "crosshair", …) |
Gui.setCursorImage(path, hotspotX, hotspotY) | — | new — custom cursor image ("" restores default) |
Gui.clipboardGet() / clipboardSet(text) | string / — | Text clipboard |
Gui.clipboardGetImage() | handle | new — read an image from the clipboard (0 if none) |
Gui.clipboardSetImage(handle) | — | new — copy an image handle to the clipboard |
Gui.openFileDialog(filterName, exts) | path | Native open dialog (exts = "json,txt"); "" if cancelled |
Gui.saveFileDialog(filterName, exts, defaultName) | path | Native save dialog |
HiDPI & monitors
| Method | Returns | Notes |
|---|---|---|
Gui.scaleFactor() | decimal | Monitor scale (1.0 = 96 dpi) |
Gui.windowPosition() | [x, y] | new — window position (physical px) |
Gui.monitors() | [dict, …] | new — one dict per monitor: {x, y, width, height, scale, name} |
Gui only for custom drawing (charts, canvases, games).