Atv0.1.0Repositorysigil-ui
Document

sigil-ui

A retained-mode UI library for Sigil, with a software renderer and offscreen, Linux framebuffer, DRM and Wayland surfaces. It draws rectangles, bitmap text and alpha masks into XRGB8888 pixel buffers, and can save renders as PNG files.

A view is a function from application state to an element tree. On each update, sigil-ui reconciles that description with the tree it retained from the previous frame, keeps unchanged display items and repaints damaged rectangles. Keys keep children's identity across reordering; components skip a subtree when their function and input are unchanged. Positions are explicit logical pixels, with integer scaling and named theme colors, fonts and images.

Install

Requires Sigil 0.24. Add the registry dependency to your package's dependencies list, then run sigil deps install:

(from-pkg name: "sigil/sigil-ui" version: "^0.1")

The first registry release is 0.1.0.

Minimal example

This draws a progress bar offscreen and saves it to progress.png:

(import (sigil math)
        (sigil ui raster)
        (sigil ui theme)
        (sigil ui tree)
        (sigil ui png))

(define theme
  (make-theme
    (list (cons 'background #x101820)
          (cons 'accent #xEDBB45))
    '()
    '()))

(define ui
  (make-ui theme (make-canvas 320 80) 1 'background))

(define (view progress)
  (group 0 0
    (list (rect 20 30 (quotient (* 280 progress) 100) 20 'accent))))

(ui-update! ui (view 50))
(write-png! "progress.png" (ui-canvas ui))

ui-update! returns damaged rectangles in logical pixels. To present them on a surface, multiply each coordinate by ui-scale and pass each rectangle with the canvas to surface-present!.

Renderer and surfaces

The display list supports solid and blended rectangles, bitmap text, colored text runs and alpha masks. Pixel loops, PNG encoding and device access are C; the retained tree, themes and display list are Sigil. It has no external graphics library dependencies for offscreen rendering.

(sigil ui surface) provides offscreen buffers, 32-bit XRGB8888 fbdev devices and Linux DRM dumb buffers. DRM master can be dropped and reacquired for display handoff; surface-close! with keep-frame?: #t preserves active scanout on Linux 6.8 or later. Hardware surfaces require access to the device.

(sigil ui wayland) provides windows and fullscreen surfaces, keyboard and pointer events, resizing, integer buffer scaling and damage-aware presentation. It loads libwayland-client and libxkbcommon at runtime. Use a dynamically linked program for Wayland: a fully static musl executable cannot load those libraries. The application owns the event loop; see the demo.

Development and status

Version 0.1 is an early API and may change. Layout, input handling and animation timing belong to the application. Fonts are supplied bitmap fonts; this release does not include a shaping engine, native fractional scaling, GPU rendering, clipboard, drag and drop, IME or accessibility support.

sigil deps install
sigil build
sigil test
cd bench
sigil deps install
sigil build --config release
./build/release/bin/sigil-ui-bench

The benchmark normally uses the published library. For local changes, use Sigil dependency redirects for sigil/sigil-ui to your checkout. The benchmark and demo generate their own untracked locks on installation, so they don't pin an older archive of this repository inside the package itself.

The demo also uses the registry package. From demo/, run sigil deps install, sigil build, then ./build/dev/bin/sigil-ui-demo. It includes Spleen bitmap fonts under their own license.

The default suite needs no display. Additional checks are sigil scripts/check-surface-close.sgl (GCC and libdrm through Guix), sigil scripts/test-wayland-configure.sgl (a C compiler, wayland-scanner and Wayland server development files), and test/wayland/run (headless sway, swaymsg, grim and a C compiler). The live tests start their own compositor.

See the design document for reconciliation rules, the module map and benchmark measurements. Licensed under BSD-3-Clause.