chui
- chui
- Description
- Author
- Repository
- Requirements
- Backends
- Quick start (SDL2)
- Building the widget tree
- Scrollbox (not yet available)
- Timers
- Threads
- Modifier keys and keyboard shortcuts
- Listbox
- Selectlist (dropdown combo)
- Overlay dialogs (modal-ish floating panels)
- Drag and drop
- Matrix
- Interaction
- Split panes (splitbox)
- Checkboxes and radios
- Frame (group box)
- Text editing
- Canvas widgets
- Finding widgets later
- Custom drawing
- Theming (CSS-like style sheets)
- Testing
- License
- Version history
Description
chui is a small, retained-mode GUI toolkit in Chicken Scheme. You build a widget tree once, hand it to a backend's run-gui, and the backend drives the event loop. The core (chui egg) is backend-neutral; pick one of the rendering backends below.
Author
Matt Welland is the author of the chui eggs.
Repository
The fossil repository for the chui source code is hosted by Kiatoa: https://chiselapp.com/user/kiatoa/repository/mattsgui. Releases are tagged vX.Y and each egg carries a release-info file so chicken-install (via egg-index) can fetch tagged releases.
Requirements
CHICKEN 5. Core egg dependencies: srfi-1, srfi-18, srfi-69, base64, regex, matchable, typed-records. Each backend egg adds its own native library (SDL2, raylib, Allegro 5, hypergiant, or X11 via ezxdisp); see the backend egg pages and the repository's INSTALL.md for OS packages and chicken-install lines.
Backends
All backends expose the same entry point: (run-gui window-title toplev).
| Egg | Library | Notes |
|---|---|---|
| chui-sdl2 | SDL2 + Cairo | primary backend; TTF fonts, PNG/JPG image labels, Cairo-backed canvas widgets |
| chui-sdl3 | SDL3 + Cairo | in-progress SDL3 port (hand-written bindings); headless-verified, not yet released — see chui-sdl3/README.md in the repository |
| chui-raylib | raylib | TTF fonts (baked per size; cached) |
| chui-allegro | Allegro 5 | TTF fonts (cached per path+size) |
| chui-hypergiant | hypergiant (OpenGL) | TTF faces (cached); needs -L -lepoxy when linking |
| chui-ezxdisp | ezxdisp (X11) | minimal: fixed font (colors still themed), heuristic text metrics, no hover repaint on pure mouse motion |
chui-cairo is not a backend: it is a helper egg of Cairo conveniences (colors, text, cached layers, sprites, camera) for drawing inside canvas widgets on backends that hand you a Cairo context (chui-sdl2). See the chui-cairo egg page.
Quick start (SDL2)
(import chui chui-sdl2)
(define toplev
(update-coords
(update-w-h
(vbox
(button "Hello")
(button "Exit" action: (lambda (obj) (exit))))
)
0 0))
(run-gui "my app" toplev)
Build and run (see INSTALL.md in the repository for OS packages and eggs):
csc -setup-mode myapp.scm ./myapp
run-gui blocks until the window is closed.
Building the widget tree
Containers (no drawing of their own; they lay out children):
(vbox child ...) vertical stack
(hbox child ...) horizontal row
(zbox child ...) stacked/overlapping; see zbox-select below
(gridbox cols rows child ...)
(frame "title" child ...)
(splitbox pane1 pane2 ... params: '((width . 500) (height . 300)))
resizable panes, draggable sash; see below
(tabs `("name" content) ...) tabbed panes
Widgets:
(label "text")
(button "text" action: (lambda (obj) ...))
(textbox "initial text") editable; see Text editing
(textbox "" password: #t) shows * for each char; title keeps real text
(checkbox "text" checked: #f) click toggles; see Checkboxes and radios
(radiobutton "text") put inside a radiogroup
(radiogroup rb1 rb2 ...) mutually exclusive selection
(slider) (vslider) (hslider) value 0.0..1.0, drag or click
(canvas draw-fn width: 300 height: 200)
(scrollbox content) NOT YET AVAILABLE — unfinished WIP
stub; see Scrollbox below
(clipbox content width: height:)
(treenode "root" initpath: '(("a" "b" "c") ("a" "d")))
(listbox items visible-rows: editbox:) selectable list; see Listbox
(selectlist items visible-rows:) dropdown combo; see Selectlist
(matrix titles: data: visible-rows:) editable grid; see Matrix
Two passes size and place the tree before display:
(update-w-h tree) compute each widget's width/height (update-coords ... 0 0) assign x/y from the top-left corner
Wrap them as in the quick-start example. After the first display, structural changes (add-child, title!, matrix/listbox row adds, tabs, ...) flag the tree layout-dirty automatically; the backend's refresh re-runs placement only then.
request-layout!
[procedure] (request-layout! #!optional (obj *topwidget*))Forces a re-place of the tree on the next refresh.
layout-dirty?
[procedure] (layout-dirty? #!optional (obj *topwidget*))True when the tree needs re-placement.
params
params: is an association list of per-widget layout hints:
params: '((width . 100) (height . 40) (expandx . #t))
- width / height — fixed size in pixels
- expandx / expandy — stretch to fill the container's row/column
Labels with images (SDL2)
(label "" params: '((image . "icon.png")))
The SDL2 backend loads the file (sdl2-image) and sizes the label to it.
Scrollbox (not yet available)
scrollbox exists in the core as an unfinished WIP stub and is NOT a shipped feature: any scrollbox parented into a live tree crashes the first layout pass with (max) bad argument type - not a number: #f. The idempotent populate and auto-slider work have landed; the layout routing is still open. Use clipbox (fixed viewport) or the canvas content-w/content-h scroll offsets instead until this widget is finished and tested.
Timers
add-timer!
[procedure] (add-timer! interval-sec proc #!key name)Registers a timer firing every interval-sec seconds, optionally named. The backend event loop fires due timers on the GUI thread each iteration (it bounds its event wait with next-timer-delay, so timers fire without user input). A timer proc that returns #t requests a full GUI refresh after mutating widgets. This replaces IUP's iup:timer for dashboard-style periodic refresh.
remove-timer!
[procedure] (remove-timer! name)clear-timers!
[procedure] (clear-timers!)Also: timer-names, next-timer-delay, poll-timers!.
Threads
cooperative-threads!
[procedure] (cooperative-threads! #!optional (val #t))(aliases: deterministic-threads, disable-timer-interrupts) makes green threads switch only cooperatively: the scheduler's timer interrupt (reason 255) is dropped, so threads never preempt the draw pass or block inside C calls mid-frame. Background threads must then explicitly yield (thread-yield! / thread-sleep!) or they starve the GUI loop. chui-sdl2 enables it automatically when the cooperative-threads window option is set (see the chui-sdl2 egg page).
Modifier keys and keyboard shortcuts
The backend tracks modifier state from key-down/key-up; four canonical names: shift ctrl alt meta (lshift/rshift/lctrl/... all normalize). Inside any mouse action, read the state of the event being dispatched with (event-modifiers), or poll the live state with (modifier-held? 'shift) / (shift-held?).
modifier-held?
[procedure] (modifier-held? mod)True while mod ('shift, 'ctrl, 'alt, 'meta) is down. shift-held? is the 'shift alias kept for older apps.
set-modifier-held!
[procedure] (set-modifier-held! key held)Backend entry point: accepts raw keysyms or canonical names and updates the tracked set. clear-modifier-state! resets it. Apps only read.
event-modifiers
[procedure] (event-modifiers)The modifier set carried by the event being dispatched RIGHT NOW. The updater contract takes an optional 6th argument, (updater 'left 'click x y wheel-delta modifiers); when the backend supplies it (chui-sdl2 does on every mouse event), event-modifiers is bound to it for the dispatch; omitting it falls back to the tracked (modifier-state). This is the multi-select prerequisite: a click action tests (memq 'shift (event-modifiers)) to extend a selection.
add-key-binding!
[procedure] (add-key-binding! combo proc)Named shortcuts: combo is a list of modifier names plus one key ('escape, 'return allowed).
(add-key-binding! '(ctrl s) act-save) (add-key-binding! '(shift tab) next-field)
remove-key-binding!
[procedure] (remove-key-binding! combo)key-bindings
[procedure] (key-bindings)Lists the registered combos.
The backend's key-down handler calls (dispatch-key-binding key mods) and returns whether a binding fired. chui-sdl2 policy: ctrl/alt/meta combos fire even while a textbox is being edited; plain-key bindings only fire when no textbox owns the keyboard; Escape closes an open overlay panel.
Listbox
listbox
[procedure] (listbox items #!key visible-rows editbox selected action)(define lb
(listbox '("one" "two" "three")
visible-rows: 10 ;; optional: virtual scroll
editbox: #t ;; optional: combo behavior
selected: 0 ;; optional: initial selection
action: (lambda (o ev idx) ...) ;; ev: select/edit/commit
Click selects an item; arrow keys move the selection. listbox-select!, listbox-selected, listbox-selected-item, listbox-add-item!, listbox-remove-item!, listbox-items-set! manage items and selection.
With visible-rows: only that many rows draw and an auto vslider child drives the offset (listbox-scroll!, listbox-set-scroll-offset!, listbox-select! scrolls the item into view automatically).
With editbox: #t, clicking the already-selected item starts editing: type text and the first item starting with the typed prefix highlights live (listbox-prefix-match!); Enter commits — an exact match selects that item, otherwise the prefix hit (IUP-style combo/target-selector behavior).
Selectlist (dropdown combo)
selectlist
[procedure] (selectlist items #!key name visible-rows selected action)(selectlist '("Wards" "Map" "Market")
name: 'layers visible-rows: 5
action: (lambda (o ev idx) ...)) ;; ev = 'select
The IUP IupList DROPDOWN=YES flavor: a compact face showing the selected item plus a down arrow. Clicking the face drops a popup list that floats OVER every other widget (drawn after the tree, hit-tested before it); clicking a row selects it and closes, clicking anywhere else closes the popup and the click is ABSORBED — a temporarily covered widget underneath is left untouched. The popup opens below the face and flips above when it would run past the bottom of the top-level. visible-rows caps the popup height (default 8). At most one selectlist is open at a time.
selectlist-select!, selectlist-selected, selectlist-selected-item, selectlist-items-set!, selectlist-open!/selectlist-close!/selectlist-open? manage items, selection, and the popup. When items exceed visible-rows the popup grows a slider strip and the mouse wheel scrolls it (selectlist-scroll-offset-set! sets the offset programmatically; opening scrolls the selection into view). Mouse-only: no keyboard navigation of the popup.
IUP flavor map: plain list -> listbox; editbox combo -> listbox editbox: #t; dropdown combo -> selectlist; MULTIPLE=YES is not implemented.
Overlay dialogs (modal-ish floating panels)
The zbox-style replacement for IUP dialogs: a DETACHED widget subtree drawn in the floating layer (same layer as selectlist popups and the drag ghost) that OWNS all input while open — clicks outside the panel are absorbed, Tab cycles the panel's own textboxes, background widgets never activate. One overlay at a time.
make-overlay-panel
[procedure] (make-overlay-panel title content #!optional (buttons '()))Builds the panel as a vbox: title label, the content widget list, and a button row from buttons = (("Save" . save!) ("Cancel" . #f)). Every panel button closes the overlay FIRST, then runs its action (#f = close only).
overlay-open!
[procedure] (overlay-open! panel #!optional (toplev *topwidget*))Measures the panel, centers it over the toplevel, and opens it.
overlay-close!
[procedure] (overlay-close!)overlay-open? / current-overlay
[procedure] (overlay-open?)[procedure] (current-overlay)
make-message-box / make-confirm-box
[procedure] (make-message-box title message #!optional on-close)[procedure] (make-confirm-box title message on-yes #!optional on-no)
Single-OK / Yes-No panels; their callbacks take no arguments (the panel is already closed when they run). Escape also closes an open overlay (chui-sdl2).
Drag and drop
A grab -> ghost -> drop-target layer built on the updater's 'drag events; no new widget type — declaration is by params:.
(canvas draw-fn
params: (list (cons 'drag-source-proc
(lambda (obj x y) (hit-test-task x y)))))
(define drop-zone (vbox ...))
(set-param drop-zone 'drop-target #t)
(set-param drop-zone 'drop-action
(lambda (obj payload x y) (place-task payload x y)))
On the FIRST 'drag over a widget (or nearest ancestor) declaring a drag-source-proc param, the core calls it; a truthy return starts the grab (any payload datum the app interprets), #f means "not draggable here" and the event falls through to normal action dispatch. On button release the backend emits (updater 'left 'drop x y); the core walks up from the widget under the cursor to the nearest drop-target ancestor and calls its drop-action param with the payload. While a grab is active the core OWNS the gesture: 'drag events update the ghost and hover target and are NOT dispatched to widget actions. The floating layer draws a gold ghost box + payload label at the cursor and a gold border around the hovered drop target; a drag-ghost-proc param (proc obj x y payload) on the source replaces the default ghost. chui-sdl2 emits the 'drop release signal; chui-sdl3 does not yet (a grab stays open until drag-cancel!).
drag-start!
[procedure] (drag-start! obj payload #!optional x y)drag-cancel!
[procedure] (drag-cancel!)drag-active?
[procedure] (drag-active?)current-drag-source / current-drag-payload / drag-hover-target
[procedure] (current-drag-source)[procedure] (current-drag-payload)
[procedure] (drag-hover-target)
drag-drop!
[procedure] (drag-drop! obj x y)Programmatic end-of-grab (tests, keyboard-driven moves): hit-tests the drop target and dispatches its drop-action.
Matrix
matrix
[procedure] (matrix #!key titles data visible-rows params action)(define mx
(matrix titles: '("Run" "Status")
data: '(("run-1" "COMPLETED") ("run-2" "RUNNING"))
visible-rows: 12 ;; optional: virtual scroll
params: '((cell-width . 120) (cell-height . 22))
action: (lambda (o ev r c) ...))) ;; ev: select/edit/commit
Click selects a cell; click the selected cell again to edit (Enter commits, Esc cancels, arrows move the selection). matrix-ref, matrix-set!, matrix-insert-row!, matrix-remove-row! manage the cell store.
Virtual scrolling: with visible-rows:, only that many rows draw and an auto vslider child (right edge) drives the offset. matrix-scroll! (0.0..1.0), matrix-set-scroll-offset! (row index), matrix-scroll-to-row! (scroll into view; arrow movement does this automatically).
Per-cell colors (status colors etc.):
(matrix-cell-color-set! mx 3 1 'weak-green) ;; bg, library symbol (matrix-cell-color-set! mx 3 1 '(180 255 180)) ;; bg, int triple (matrix-cell-color-set! mx 3 1 'red 'white) ;; bg + fg (matrix-cell-color-clear! mx 3 1)
NOTE: color triples in user code are ints 0-255; chui scales them to the backend's native representation.
Interaction
- Buttons: action: is called with the widget on click. Buttons and labels highlight on hover.
- Sliders: guiobj-value is 0.0 (top/left) to 1.0 (bottom/right); action: is called on click and drag.
- Tabs: (set-tab tabs-widget "name") switches panes programmatically.
- zbox: (zbox-select zbox-widget n) shows the n-th child (0-based).
- Tree: (tree-add-node tn '("a" "b")), (tree-find-node tn '("a" "b")); click a node's +/- to fold/unfold. With selection-cb: the node buttons route through tree-select-node! (highlighted selection, tree-selected-node); tree-clear!, tree-remove-node! and tree-expand-all! (collapse: #t to fold all) support dynamic rebuilds. On backends that provide atlas-tile-proc (chui-sdl2, chui-sdl3) each node renders as one flat Explorer-style row built from a 10-tile PNG atlas strip (populate-treenode-flat; strip from tree-atlas-path or the PNG embedded in the egg, tree-atlas-bytes); without an atlas backend the old "v"/">" text toggles are used.
Split panes (splitbox)
splitbox
[procedure] (splitbox pane ... #!key params)(splitbox left-pane right-pane
params: '((width . 500) (height . 300)))
Resizable panes with a draggable sash. The box needs a fixed width/height (or its parent gives it one); the sash position is the fraction (0.05..0.95) of the track taken by the first pane, held in the value slot — set it with (guiobj-value-set! sb 0.3) and re-layout, or drag the sash with the mouse. More than two panes: the first takes the fraction, the rest share the remainder. Horizontal sash (panes stacked): (title! 'horizontal sb) or params: '((orientation . horizontal)). Sash thickness: sash-size param (default 6). Splitboxes nest.
Checkboxes and radios
checkbox
[procedure] (checkbox text #!key checked action)(checkbox "subscribe" checked: #t
action: (lambda (o) (print (checkbox-checked? o))))
radiogroup
[procedure] (radiogroup radiobutton ...)(define size (radiogroup (radiobutton "small") (radiobutton "medium" checked: #t) (radiobutton "large")))
Clicking a checkbox toggles it; checkbox-checked? and checkbox-toggle! read/set the state programmatically. A radiogroup lays out like a vbox; clicking a member selects it and deselects the others (a checked: #t child is the initial selection). Read the selection with (radiogroup-selected size) or set it with (radiogroup-select! size rb). The group's own action: fires as (action group selected-obj) when a member is clicked.
Checked state lives in the numeric value slot: 1 = on, 0 = off for checkbox/radiobutton; the group's value is the index of the selected child (-1 = none).
Frame (group box)
frame
[procedure] (frame title child ... #!key margin width height)(frame "Sound settings" (checkbox "Enable output") (hslider value: 0.5))
An IUP-style group box: draws a border rectangle with the title at the upper left, overlapping (and broken into) the top border. The interior is transparent; children are laid out inside it like a vbox, inset by a margin. The frame sizes to its children plus the margin, and is never narrower than its title. Keyword options (margin: n inner padding, width:/height: fixed outer size) may appear anywhere among the children. An expandx child stretches to the inner width.
Text editing
Click a textbox to focus it (it becomes *current-text-receiver*). Keys: printable chars insert at the cursor; Backspace/Delete, Left/Right move the cursor, Tab jumps to the next textbox, Escape/Return end editing. Read the text with (guiobj-title textbox-obj); the cursor position is (guiobj-value textbox-obj).
With action: the textbox's action fires when editing ends — Enter or Escape route through end-text-editing, which calls (action textbox-obj) with the edited text and clears the receiver. This is the commit channel for filter/search fields.
(textbox "" password: #t) masks the display: each character is drawn as *, but (guiobj-title ...) still returns the real text, so all editing and reading work the same.
Canvas widgets
(canvas draw-fn) calls draw-fn with backend-specific drawing arguments. On chui-sdl2 the signature is (draw-fn cr w h): a live Cairo context and the canvas size in pixels. Import chui-cairo and use its helpers inside draw-fn. Canvas redraws happen when the widget is marked changed or the GUI refreshes.
With action: the canvas receives mouse events as (action obj x y button mode . rest):
- mode 'none — button-down (arms press-driven behavior, e.g. starting a drag or a selection rectangle)
- mode 'drag — motion with the button held
- mode 'wheel — mouse wheel; rest carries the notch delta (+ = wheel up)
Hover motion ('move) is deliberately NOT delivered — per-motion spam would change every canvas app.
Core-managed scrolling: give the canvas content-w and/or content-h params (content larger than the widget) and the core keeps clamped scroll-x/scroll-y params. The wheel scrolls by wheel-step pixels per notch (default 40) when scrollable, and the 'wheel event reaches the action either way — apps that prefer zoom-on-wheel can ignore the offset. The drawproc APPLIES the offset itself (chui-cairo's with-camera is the natural way), so the backend stays dumb. Procs: canvas-content-size, canvas-scrollable?, canvas-scroll-offset (values), canvas-set-scroll-offset! (clamps), canvas-scroll-by!.
(canvas draw-fn width: 600 height: 400
params: '((content-w . 2000) (content-h . 1500))
action: (lambda (o x y btn mode . rest) ...))
Finding widgets later
(find-by-name toplev 'b3) auto-names: b1,b2,... buttons,
(find-by-title toplev "Save") l1,... labels, s1 sliders,
cb1 checkboxes, rb1 radiobuttons, etc.
Use these from actions to mutate other widgets:
(title! "new text" (find-by-title toplev "Save"))
Custom drawing
Every widget takes drawproc: — a procedure (obj state) that draws the widget instead of the default. state is one of 'active, 'hover, 'clicked, 'inactive. The default is draw-widget.
Theming (CSS-like style sheets)
Style the widget tree from an s-expression file instead of per-widget params. See docs/styles.md in the repository for the full syntax; example theme: data/theme-dark.sexpr.
(import chui chui-sdl2) (load-style-sheet "data/theme-dark.sexpr") (define toplev (vbox (button "OK" name: 'ok-btn))) (apply-styles toplev) ;; before run-gui (run-gui "my app" toplev)
- Selectors: *, widget type/name, /exact/path, /path type.
- Properties: fg-color, bg-color, edge-color, face-color, shadow-color, font, (state hover ...), (inherit #f).
- Cascade: inline params beat the sheet; more specific selectors beat less; styles propagate to children unless a barrier is set.
- Hot reload while running: (watch-style-sheet!) starts a watcher thread that re-applies the sheet when the file changes on disk; (poll-style-sheet) / (reload-style-sheet) do it manually.
Testing
Headless tests drive the updater directly, no display needed:
csc tests.scm && ./tests # core suite csc tests/hover-test.scm && ./hover-test csc tests/style-test.scm && ./style-test # style plumbing csc tests/sheet-test.scm && ./sheet-test # sheet parser + cascade csc tests/reload-test.scm && ./reload-test # hot reload + watcher
License
Copyright (c) 2025-2026 Matt Welland. Redistribution and use in source and binary forms, with or without modification, is permitted. See the file headers in the repository.
Version history
Version 0.5 (2026-11-18)
- Drag-and-drop chip (drag-start!/drag-drop!/ghost layer); chui-sdl2 emits 'drop on release after a grab
- Overlay dialogs (make-overlay-panel, make-message-box, make-confirm-box); Esc closes an open overlay
- Full modifier-key tracking + named keyboard shortcuts (add-key-binding!, event-modifiers, optional 6th updater arg)
- Canvas 'none button-down delivery; 'move not delivered
- Textbox action: fires on Enter/Esc (end-text-editing)
- matrix-set! targets the selected cell (r,c), not the whole row
- Scrollbox still an unfinished stub — NOT usable in 0.5
- chui-sdl3 backend in-tree (headless-verified) — NOT packaged in 0.5; egg release planned for v0.6
Version 0.4 (2026-10-28)
Version 0.3
- Egg packaging fixes
Version 0.2
- Egg packaging fixes
Version 0.1
- Initial release (2026-10-14), all backend eggs