Fusuma is a retained widget toolkit with its own layout engine and a renderer you can swap. This page is the map: what the layers are, what a frame does, and why the code is arranged this way.
The layers
Your app is a [Program](/docs/program/): a state, the messages that change it, update and view.
The view layer (fusuma) runs the program. It turns a view into widget-tree nodes, compares as it goes so only what differs changes, keeps timers and subscriptions, and, with the async feature, polls futures on the app's own clock. No async runtime is linked.
The widget tree (fusuma-ui) is where the toolkit lives: one node per widget, hit-testing, focus, scrolling and gestures, dialogs, text input, the semantic tree for assistive technology, and painting with damage tracking. It is no_std and needs no allocator.
Layout is [tsubo](/docs/crates/): integer flexbox and grid with no heap and no dependencies, checked against Taffy as an oracle. The name is the Japanese floor measure of two tatami mats, a whole unit and never a fraction.
The theme is data. Palettes, spacing, radii, type sizes, motion and corner shapes live in TOML and token files and are generated into the code; a test fails when they drift. See Design.
The renderer is one trait, Renderer. Everything above it is the same on every device; everything below it is chosen for the hardware. See Rendering.
The platform crates own the window, the web canvas, the panel or the terminal, feed input in and present frames out. They draw nothing themselves.
One frame
- An input arrives: a pointer, a key, a resize, a timer. The tree handles it and queues an action.
update(state, msg)changes the state in the one place that is allowed to, and returns aTask: nothing, or up to a few effects in order.view(state, env)describes the screen. The description is made on the stack, so the tree is the previous state and nothing else is kept.- The description is synced into the tree. Every setter compares first, so a label with the same text, a style with the same numbers, changes nothing and asks for nothing.
- Layout walks only the subtrees that changed. A box that only moved carries its children. A tree of 900 nodes with one changed cell lays out in a few microseconds.
- Changes record damage: the rectangles whose pixels differ. Several separate changes are drawn apart, and a scroll can move pixels instead of redrawing them when the renderer retains its picture.
paint_framedraws inside the damage through theRenderer, and the platform presents the dirty rectangle.
With nothing changing, nothing is laid out, drawn or sent, and the app sleeps until the next input or timer. That is what lets a battery-powered board keep its screen still, and what lets an e-paper panel refresh only a region.
Why it is shaped like this
- Integer layout, no allocation. A chip has no FPU worth using and often no heap to spare.
tsubodoes its arithmetic in integers and a pass allocates nothing, so the same engine runs on an ESP32-C6 and on a desktop. - Constants for sizes. A tree of
Nnodes andKmessage slots is a type. A running session does not allocate, and a test guards it. - A retained tree with damage. Redrawing everything each frame is fine on a GPU and ruinous on a panel behind an SPI bus. Keeping the tree and recording damage makes both cases cheap.
- Messages are values.
MsgisCopy, so a session can be logged and replayed, a timer can hold one, and a test can send one and look at the tree. - Data, not code, for what varies. Fonts, icons, colours, corner shapes and boards are files. A new Waveshare board is a file when its controllers are already known.
Measured
Layout of the same dashboard, 36 cards in a four-column grid, 902 nodes, on one Apple M-series core in a release build (crates/fusuma-ui/tests/taffy_bench.rs, run by hand):
| Fusuma | Taffy 0.15 | ||
|---|---|---|---|
| from scratch (the window gets another width) | 63 µs | 96 µs | 1.5x |
| one cell changes height inside its row | 2.4 µs | 21 µs | 9x |
| a cell grows, so the cards below move | 3.8 µs | 29 µs | 7.6x |
| a tree 60 levels deep, the leaf changes width | 9 µs | 138 µs | 15x |
| allocations in a from-scratch pass | 0 | 1,551 |
A wrapping flow of 600 boxes is about even (42 µs against 47 µs): it is the shape where Fusuma is not ahead, because every child moves and each move records damage.
Against iced 0.14 on the same dashboard, with a layout-only renderer:
| Fusuma | iced | ||
|---|---|---|---|
| layout from scratch | 88 µs | 17 µs | iced is 5x faster |
| a frame after one cell changed | 4.6 µs | 49 µs | Fusuma is 10x faster |
iced remembers nothing between frames, so a layout of everything is a plain walk and very quick, while Fusuma keeps the tree and lays out only what changed. The case where everything changes at once, a window being dragged, is Fusuma's weak one, and 88 µs is well inside a frame. The tables are the latest runs; the machine is noisy, so read the ratios.
On a board: the gallery on an ESP32-S3 watch at 240 MHz takes 92 ms for a first frame, 12 ms for a tap and 36 ms for a scroll step with the integer renderer.
Next: the program model, or the renderers.