Skip to content

testing: split a closure-free PlacedFrame out of Placed (#373, PR A) - #408

Merged
samitbasu merged 9 commits into
mainfrom
driver-373a
Nov 19, 2026
Merged

samitbasu merged 9 commits into
mainfrom
driver-373a

Conversation

@samitbasu

@samitbasu samitbasu commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Part of #373 (PR A of the split in the design note).

What

  • testing::PlacedFrame holds a laid-out frame's query data: nodes, ids, prims, roots, the kept handle and the context. It has no closures.
  • Placed<A> holds a PlacedFrame beside its draw, drag, dismiss and window closures, and derefs to it. Every query is defined once, on the frame: at, try_at, overlays, overlay, overlay_with, expect_overlay, menu_open(_with), diff, overflowing, node, rect, nodes, shell, len, dump.
  • Placed::draw(..) returns the PlacedFrame it drew, after its paint closures have run. A test keeps it in its own harness state; an app ignores it. There is no global, no flag in Kept, and LayoutState stays Send.
  • Painting a node's text, icon or image now borrows its prim and puts it back instead of consuming it, so the returned frame still answers text() after the draw.

Review changes

The first version handed the frame over through a thread-local keyed by the layout's scope, behind testing::keep_frames / testing::take_frame and a Kept.keep_frame flag. The user rejected that, so all of it is gone, along with LayoutState::scope, which only the hand-over used. keep_frames' doctest is now Placed::draw's, keeping the returned frame in the harness state.

Breaking changes

Placed::draw returns PlacedFrame instead of (). A call used as a statement is unchanged. One whose value was used as (), such as a match arm, needs a block; the frame bench was one. Placed's query methods keep their names and signatures. diff now takes &PlacedFrame, which a &Placed<A> derefs to.

New doc comments are marked TODO(prose).

Checks

🤖 Generated with Claude Code

https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o

samitbasu and others added 2 commits November 18, 2026 18:09
`Placed::draw(self)` consumes the frame, so a harness that wants to ask
a frame after drawing it had to copy what it needed out first (the test
rig keeps `(path, rect)` and `(path, id)` lists for this). The query data
(nodes, ids, prims, roots, the kept handle and the context) now lives in
`testing::PlacedFrame`, which has no closures; `Placed<A>` holds it beside
the draw, drag, dismiss and window closures and derefs to it, so every
query (`at`, `try_at`, `overlays`, `overlay`, `expect_overlay`,
`menu_open`, `diff`, `overflowing`, `node`, `rect`, `nodes`, `shell`,
`dump`) is defined once, on the frame.

`testing::keep_frames(&layout)` asks a layout to keep each frame it
draws, and `testing::take_frame(&layout)` takes it: `draw` moves the
frame there instead of dropping it, nothing cloned. The hand-off is a
thread-local keyed by the layout, not a field of the layout's state,
because a frame's paint closures are not `Send` and `LayoutState` is.

Painting a node's text, icon or image now borrows its prim and puts it
back, instead of consuming it, so the frame still answers `text()` after
the draw.

No behaviour change; the public methods of `Placed` keep their
signatures (`diff` now takes any frame, which a `&Placed<A>` derefs to).

Part of #373.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
…the new docs for prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
@samitbasu

Copy link
Copy Markdown
Owner Author

User review (2026-11-19): the thread-local hand-over is rejected. Use design (a): Placed::draw(..) returns the PlacedFrame (the query data, after the paint closures have run). Tests keep it in their own harness state; apps ignore it. There's no keep_frames/take_frame, no Kept.keep_frame flag and no global. LayoutState stays Send. #413 and the C–F stack rebase onto this (merge only).

samitbasu and others added 7 commits November 19, 2026 09:32
…and-over

The kept frame reached a test through a thread-local keyed by the
layout's scope, behind a flag in Kept (keep_frames / take_frame). Draw
now returns the PlacedFrame it drew, after its paint closures ran: a
test keeps it in its own harness state, and an app ignores it. No
global, no flag, and LayoutState stays Send.

Removed: testing::keep_frames, testing::take_frame, Kept.keep_frame,
the KEPT_FRAMES thread-local, and LayoutState::scope, which only the
hand-over used. keep_frames' doctest moves to Placed::draw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o
@samitbasu

Copy link
Copy Markdown
Owner Author

Approved by the user on its tests, after the rework to a returned frame (2026-11-19). GitHub's required checks pass on the branch merged with current main. Merging.

@samitbasu
samitbasu merged commit db1ade5 into main Nov 19, 2026
4 checks passed
samitbasu added a commit that referenced this pull request Nov 19, 2026
…nswers

#408 landed with Placed::draw answering its PlacedFrame, and without the
keep_frames / take_frame hand-over this branch was built on. The driver
now stores the frame its draw closure answers: Driver::whole_frame's
closure answers the frame its layout's draw answered, and Driver::new's
does so for the view. LayoutState::scope, which only the hand-over used,
is gone with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant