Skip to content

bullseye::testing: headless layout, key-path queries and layout diff (#68) - #70

Merged
samitbasu merged 3 commits into
mainfrom
headless-layout
Nov 10, 2026
Merged

samitbasu merged 3 commits into
mainfrom
headless-layout

Conversation

@samitbasu

Copy link
Copy Markdown
Owner

Closes #68, requested by the user so CI can catch layout bugs like the reference shell's Lettering card. When chosen, its bold name and check overflowed the card, the w_px(34) sample shrank (flex-shrink: 1), and the name moved left.

Shape (decided in #68)

use bullseye::testing::Headless;

let mut headless = Headless::new(vec2(1200.0, 800.0))
    .prepare(|ctx| Theme::install_controls(ctx))   // any FnOnce(&Context), run once before the warm-up pass
    .base_text(base)
    .theme(egui::Theme::Light);
let before = headless.layout(&app, view);          // build + layout only: no window, no GPU, no draw

let r    = before.at(Region::Viewport).at(Part::Lettering).at(Lettering::Mono).at("sample").rect();
let name = before.at(Part::Lettering).at(Lettering::Mono).text("Mono").rect();   // unkeyed text by content
let none = before.at(Part::Lettering).at(Lettering::Mono).try_at("check");       // Option

let changes = before.diff(&after);                 // Vec<Change { path, before, after }>
  • Chained .at(key) only, with no macro (user's choice). It hashes with the builder's own child_id, so ids can't drift. It passes through scope keys.
  • #[track_caller] panics name the requested path and the children that exist there.
  • .text(..) reads the text the layout already records. Zero or several matches panic and list the candidates.
  • diff matches identified nodes by id and anonymous nodes by path and occurrence. Rects compare exactly, because layout is exact and only drawing rounds.
  • Headless owns its egui Context. On the first layout it sets the theme, runs the queued prepare closures, and runs one warm-up pass so fonts set by prepare apply. Each layout is one pass that builds and lays out.
  • pub mod testing is always compiled and adds no dependencies, so downstream crates' tests can use it.

Tests

tests/it/headless.rs has 14 tests:

  • parity with the existing harness;
  • at hashing matches the builder;
  • missing-node panic text, and try_at;
  • text with unique, zero and duplicate matches;
  • diff: identical layouts, a changed node, pushed siblings, a node present in only one layout;
  • prepare fonts change measured widths;
  • the theme is visible to the build.

The regression, choosing_a_card_changes_only_its_check, was verified to fail without flex_none() on the sample:

"/Lettering(Mono)/\"sample\""  [8,8]-[42,28]    → [8,8]-[29.2,28]
"/Lettering(Mono)/\"name\""    [50,8]-[121.8,28] → [37.2,8]-[108.9,28]
"/Lettering(Mono)/\"check\""   None             → [116.9,8]-[132,28]

With flex_none(), only the check changes, in both directions. The test asserts its own precondition: the chosen card really overflows.

This is test tooling with no UI change, so there's nothing to try. All goldens are unchanged, and cargo xtask ci is green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up

samitbasu and others added 3 commits November 10, 2026 08:39
…68)

Unit tests could not read a computed layout without hand-building a
context, hashing ids by hand and matching nodes between two layouts.
Headless owns an egui Context, runs the prepare closures once, then one
warm-up pass so fonts exist (set_fonts applies on the next pass), then
each layout call is one pass that builds and lays out without drawing, at
the given size, base text and theme.

Placed::at / Query::at chain keys through the builder's own child_id, so
ids cannot disagree; a missing node panics (track_caller) with the
readable path and the nearest existing children. Query::text finds a
unique text node by content via the placed primitives. Placed::diff
matches identified nodes by id and anonymous ones by path and reports
exact border-box differences, with None for a side that lacks the node.

Always compiled (egui only, no new dependencies), no feature needed.
No behaviour change to existing code; Placed.by_id becomes crate-visible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
Covers parity with the support harness, id agreement with the builder,
missing-node panics, text lookup, diff, prepare fonts and theme. The
toggle-card test guards that choosing an item changes only its check;
without flex_none on the w_px sample it reports the sample and the name
as moved.

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

Placed<A> does not borrow the Headless, so &mut self serves every test
pattern, including laying out twice and diffing. The queued prepare
closures and the warm flag become plain fields, drained on the first
layout. Order is unchanged: theme set, prepare run, one warm-up pass.
Adds a doc example on Headless itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
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.

Headless layout queries for unit tests: rects by key path, text lookup, layout diff

1 participant