Scenes
A scene is a screenshot’s frame with its layers kept apart, so the app can scroll a list and hold a header over it.
A screenshot is one screen at one scroll. A scene is the same frame with its layers kept apart,
so the app can scroll a list, hold a header over it and show a dialog over that after your app,
core and device have stopped. A core writes one beside the screenshot and
the tree of a frame. A frame with no scene stays a saved picture. The format is pitafix.ui-scene/1,
and pkg/uiscene is the one place that reads, checks and draws it.
A step lists two kinds of artifact for a scene, both with the phase of the frame:
scene, formatpitafix.ui-scene/1: the JSON below.scene-tile, formatpng, withwandh: one picture of a layer. A scene names its pictures by SHA-256, so a picture that more than one scene uses is one file. Every picture a scene names must be ascene-tileof the same step, at the size the scene draws it, or ingest says the scene is unread and the frame stays a picture.
{"schema":"pitafix.ui-scene/1","viewport":{"w":1179,"h":2556,"scale":3},
"layers":[
{"id":"page","box":{"x":0,"y":0,"w":1179,"h":2556},"content":{"w":1179,"h":17379},
"scroll":{"x":0,"y":0},"tiles":[{"sha256":"…","x":0,"y":0,"w":1179,"h":4096}, …]},
{"id":"sticky-1","parent":"page","box":{"x":0,"y":0,"w":1179,"h":168},
"sticky":{"top":0,"within":{"x":0,"y":0,"w":1179,"h":17379}},"tiles":[{"sha256":"…","x":0,"y":0,"w":1179,"h":168,"alpha":true}]},
{"id":"fixed-1","box":{"x":0,"y":2361,"w":1179,"h":195},"tiles":[…]}],
"nodes":{"name":"html","layer":"page","bounds":{…},"children":[…]},
"action":{"layer":"page","box":{"x":0,"y":6648,"w":1179,"h":216},"point":{"x":589.5,"y":6756}}}Every number is in the pixels of the screenshot of the same phase, as in the tree. The fields:
viewport: the screenshot's size, andscale, the device pixels of a point.layers, in paint order, bottom first. A layer is a box that shows content.boxis where it shows, in the content of itsparentor in the viewport when it has none, andcontentis the size of what it shows. Content larger than the box on an axis scrolls on it.scrollis the offset it was captured at, so a scene nobody scrolled is the frame's screenshot. A parent comes before its children.captured: the part of the content that has pictures, when that is less than all of it. The layer scrolls no further, and the app says where the capture ends.limitssays why in a few words for a person. Use the names inpkg/uiscene/scene.go:virtual-list,capture-limit,changed-between-steps,backdrop-filter,estimated-extent,app-overlay. For another reason, add a name there with its meaning.sticky: a layer held at an edge of its parent's box while the parent scrolls past its own place, attop,bottom,leftorrightfrom that edge, and never out ofwithin.- Layers with no parent stay where they are over everything: a fixed header, a bar, a dialog and
what dims the page behind it. Their
scrollis zero. tiles: one image pixel to one content pixel, on whole pixels, each side at most 8192. The web cores use 4096.alphasays a picture is see-through in places, and anything that makes a smaller copy of it must keep that.nodes: the elements, as apitafix.tree/1tree. A node'slayernames the layer whose content its bounds are in, and a node that names none is in its parent's. Children are in paint order, the later over the earlier. A node carries what the frame's tree carries: component name, role, label, id, file and line.action, on the scene of a step's before frame only: the layer and box in content pixels of the step's target, and the point it tapped where it tapped one.
The rules a core keeps:
- At rest, and put back. Capture the scene when the screenshot is taken, with the app settled, and leave scroll offsets, focus and the document as you found them. The extra pass must not change the walk. Check that the next action's target box is where the frame said.
- The scene equals the screenshot. Composed at each layer's captured scroll, the scene matches the frame's screenshot to a few pixels. A seam on a fractional pixel or a focus ring makes a few hundred. A whole screen is a bug.
- Hold fixed and sticky parts out of the pictures under them. Take them as layers of their
own, over a transparent background where they are see-through. A dialog's picture covers its
backdrop, so a point on the dimmed page belongs to the dialog's layer and finds no element
under it. A layer that blurs what is behind it can only be taken as it looked: keep the live
pixels and say
backdrop-filter. - Never stitch what changed. Take overlapping pictures when you step through a list, check
that the overlap is the same content (pixels, and the elements in it) before using it, and
when it is not, stop and say
changed-between-steps. Saycapture-limitwhere you stop at a cap andvirtual-listwhen rows are made as the list scrolls. - Mask before anything is written, off-screen content included. A picture, a label and an id hold no secret, whether the element was on screen or not.
- A pass that fails takes only the scene down. The step keeps its screenshot and tree, and
the capture log says why in one line. Offer the capture option
scene=off, on by default, and say in your docs what the pass does to the app. The web cores scroll the page, so scroll events fire and whatever the app loads or marks as seen on scroll runs. - A frame that shows what the last one did shares its scene. When the before picture equals
the previous after, do not run the pass again: write a before scene with the same layers and
pictures and add the
action. The step still lists each picture it names, with the same path and hash.
The web cores' pass is internal/scenecap in the pitafix-rigs repository, and its
docs/api/scenecap.md says how it works.
An Android or iOS core writes the same scene from what its platform gives it: a scroll view's
content and offset, the system's bars as top-level layers, and the nodes of its own accessibility
or semantics tree in content pixels. Known gaps are named in the core's docs, not left to show.
The Kotlin Multiplatform core's pass on the Android host render is the one to copy for a native
app (cmd/pitafix-core-kmp/scene.go and docs/api/core-kmp.md in pitafix-rigs). It scrolls each scroller through
its own semantics scroll action and takes a picture and a tree at each offset, 0.7 of the box
apart, 8 screens at most around where the frame was captured. An eager column's offsets are its
scroll range. A lazy list's range is an estimate, so its pictures are placed by the keys of the
items two of them share, read from the list's own state, and pictures with no item in common are
not joined. What stays put is found by comparing pixels between positions and is left in a base
layer that is the frame as captured; the scroller's layer is cut to the rows and columns that
move, and says app-overlay where the app draws over its content, as a scroll thumb. The scroll
is put back and the picture compared byte for byte with the frame's, and a pass that cannot put
it back drops the scene. A collapsing app bar moves with a semantics scroll and must be put back
too. A route that shows real data masks each position's tree and pixels before cutting, never
after joining.
For iOS, the same core's layer 3 (a Kotlin/Native test binary that draws Field's Compose page on a
simulator) writes the same raw files from PitaFixScene.kt beside its harness, and the same Go code
builds the scene, but it reads the harness's own composition form through a tree reader the core
gives it (sceneEmitter.treeOf). The Compose test API is common code, so ScrollBy and the scroll
range work on iOS as on Android, and the harness can write files. Render the page and scroll it in
steps rather than draw it once in a taller window: a lazy list still has to be stepped, and one
method is enough. What a real shell draws is another matter: SwiftUI's bars and the glass
that blurs the content beneath them move with that content, so what stays put cannot be told from
pixels by rows, and a core that takes scenes from the real shell needs the page to publish its scroll
and to take a scroll command, and per-pixel masks for what stays put. Say that a frame has no
scene, or says backdrop-filter, before it shows a scene that is nearly right.