Skip to content

HUD plugins: the layout compiler; classic compiles to the hand-written layout's geometry - #1151

Merged
GLinnik21 merged 5 commits into
mainfrom
hud/pr5c-compile
Oct 30, 2026
Merged

GLinnik21 merged 5 commits into
mainfrom
hud/pr5c-compile

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

PR5c of the player-HUD plugin plan (docs/hud-plugins.md, "Architecture", "Package format 1.0", "Cost", "Captions: the band a HUD occupies"). hud_format could parse a package and prove its reachability; it could not lay one out. This PR adds the layout compiler, and proves it on the one package whose answer is already known: classic, compiled, reports the same rects as the hand-written layout (the geometry report; the chapters strip's top is the one pinned delta, below). It changes no frame of classic and draws nothing.

What changes

  • appkit/src/hud_format/compile.rs (new, pure): compile(&Package, &dyn Measure, CompileCtx) -> Compiled.
    • States are reach's. The compiler iterates Layout::valuations and Layout::explore and evaluates every when with Layout::holds, so there is no second state walk and no second condition evaluator: the state count is reach's (classic 18, reference 6, minimal 3). The one addition is transport.paused, an axis only when the package names it in a when or in a number or gap (see "Review fixes"). reach.rs publishes Slot, State, Valuation and Layout to its sibling with no semantic change.
    • CompiledState carries the rect of every control keyed by id, a flat Vec<DrawOp> in draw order (scrim, then the bands in z order: text, image, icon, rule, ground, facts, playbar, strip, control, the Up Next offer, the Skip pill), the scrim, the band boxes, the bar and grab rects, and the stand-ins.
    • Compiled::geometry(state, SkipKind) -> Option<HudGeometry> is the one geometry type the player reads (grab band, bar, row and RowAnchor, items, tab row, title, tabs, band).
    • Compiled::band() -> HudBand is HudBand::from_controls_top over the compact states of every valuation, slot and pause: interactive extents (controls, the stand-ins, the bar WITH its largest knob, the tabs) under band: controls, every drawn extent but the scrim under band: block. Classic is HudBand::CLASSIC, pinned. It is also the band field of every HudGeometry the package reports.
    • Cost per state, REPORTED only: draw ops, glyph runs, texture bytes, blended pixel area and the three largest contributors. Nothing enforces it; the ceilings are calibrated on the television in PR7 and PR8.
    • CompileKey { sha256, app_version, lang } is the cache key's type only: no cache, no store, no global, no hashing.
  • Text is measured through the existing plx_machine::machine::Measure, the capability classic::geometry(.., &dyn Measure) takes (TtfMeasure, TableMeasure, FixtureMeasure). The compiler defines no measurer and implements none.
  • Two values classic computed privately are exposed, with no frame change (so the compiler and the hand-written layout size a stand-in with one formula):
    • classic::stand_in_w(advance, floor): the stand-in pill formula ctrl_slot_measure used (advance + 2 * 34, never below floor). The float result is identical.
    • up_next::layout_at(anchor, next_w, credits_w): layout_of over any row anchor; layout_of is now layout_at(frame_geometry().row_anchor, ..).
    • Widened to pub(crate) for the golden: title_right, info_panel::{card_geometry, button_rect}, chapters_panel::{card_rect, label_ys}.
  • HudGeometry carries the caption band as a field (review fix 5): classic::frame_geometry fills it from its row anchor exactly as band() computed it (no frame change), the compiler from the compiled extents, and band() reads the field. HudGeometry no longer derives Default (it had no user).
  • Prose: hud_format.rs's module doc no longer says the compiler is wave B's, and report.rs / schema_emit.rs name PR5d (not PR5c) as the lint and schema flags' PR.

Why

The compiler is the piece PR7 renders from and PR5d lints with. The risk is a layout that is subtly not classic's; the golden de-risks that before anything draws.

Mismatches and their fixes

None in the geometry. compiled_classic_matches_the_hand_written_layout passed on its first run: 320 comparisons (10 shipped languages x 2 measurers x movie/episode x with/without chapters x Discs, Up Next, Skip at both labels), each over all 13 rects of HudGeometry (grab, bar, row, anchor, five items, tab row, title, two tabs), every one the exact f32; the test asserts the count. That is a statement about the compiler's rules, so the test is made to discriminate: with the Skip/Up Next floor temporarily removed from the compiler it fails with 180 mismatches (the row and the Skip pill, compiled x=1616 w=208 against hand-written x=1592 w=232). The temporary line is not in the commit.

What the compiler needed to reproduce classic (the rules the format's prose leaves to the compiler, now in compile.rs's module doc and tests):

  • Bands stack bottom-up in one VStack anchored at the safe area's bottom minus inset, and a band's gap_before is the gap to the band above. That alone gives classic's 1013 / 949 / 890 / 882 / 856 / 792 / 768 chain.
  • A start-aligned w: fill runs to the nearest left edge of a later group's present cell scaled by CTRL_FOCUS_SCALE, minus the band gap: that is classic::title_right, and tests pin the compiled title's right edge to it, in a Skip state for the label actually shown.
  • The stand-ins sit on the union of the replaced segments, anchored on that union's edge up_next.align names (an end-aligned offer on the END of the replaced segments, not the band's); their floor is the replaced segment's width with every absentable item collapsed (232 for classic), so the transport does not jump when a segment begins.

The chapters strip. The compiled strip matches chapters_panel's card size and pitch, and the name and timestamp sit 26 and 34 px under it as chapters_panel::label_ys has them (pinned), but the strip sits one CAPTION line (28.8 px with FixtureMeasure) above CH_TOP: the timestamp is a line with a height in the compiled chain, while the hand-written layout places it by origin. The fixture's chapters gap_before (43) is the PR5b placeholder; the value that reproduces CH_TOP is 43 - line_h(CAPTION), measurer-dependent. The test pins the delta (to a thousandth of a pixel) rather than forcing it. PR7 or the fixture's owner decides.

Decisions and deviations from the brief

  • No new Measure trait (brief item 1 as written said to define one): the coordinator's correction applies, and the existing plx_machine::machine::Measure is used.
  • Compiled::geometry(key, SkipKind) -> Option<HudGeometry>, where the brief wrote geometry(state) -> HudGeometry. Skip has two labels and so two widths; a key the package cannot reach has no state. A Skip state carries the layout for the other label too (CompiledState::skip_variant(kind)), because the host band's start-aligned fills (the title) stop at the pill actually shown.
  • AppLabels is plain data in CompileCtx; the app builds it from the viewer's language (a different language is a different compile, which is what CompileKey::lang is for). There is no production constructor here: the tests build it from i18n::msg, and PR7 owns the real one. A pill or button whose command has no label measures its padding only.
  • Previous and Next collapse when title.is_episode is false. A reach gap to report, not fixed here (deferred to PR5d, reach.rs): a package that places previous/next without naming title.is_episode (the reference) has one valuation, so it has no movie-form compiled state and a movie playing under it would show them. reach counting a placed previous/next as naming the condition would give it a movie valuation (about 12 states instead of 6).
  • The playbar, with its largest knob, counts as an interactive extent for band: controls (hero-center's band is the top of the focused knob's glow, KNOB_GLOW_R = 17 above the track's middle).
  • Section states report no bar, grab or row (the !sections bands are absent there), where classic::frame_geometry reports them always. Only the compact states are held against the hand-written layout, as the brief asks.
  • Real advances are available in unit tests: ShippedMeasure (plx_base::fontcov::advances) parses the shipped fonts itself and runs headless under make test-crate, so the golden uses the real fonts as well as FixtureMeasure.

Review fixes

The review of the first head (5f0101dff) returned FIX FIRST. Each finding, and what was done:

  1. check-localization red. The checker follows simple let bindings into title: / caption: initialisers; the compiler's RECT fields (title, caption) were built inline from format key names. They are now bound to locals first and the struct uses the shorthand. The checker and its ledgers are untouched. python3 ci/check-localization.py exits 0.
  2. MAJOR: frame-dependent conditions were settled at compile time and lost.
    • transport.paused is a compile AXIS whenever a when or a number or gap names it (StateKey::paused, Compiled::lookup(.., paused)): every state is compiled twice and the renderer picks per frame. It never enters reach's valuations (R1 counts it as holding either way), so a package that does not name it keeps reach's count: classic stays 18, reference 6, minimal 3. An ink or bold keyed on it moves nothing and stays Live.
    • item.* is the strip card's. A card's cell keeps its room on every card; whether a card DRAWS it is a Live<bool> over the cell's item.* terms (CardOp::present, with the negation applied by Live::at). An ink or bold keyed on an item.* term stays Live. A NUMBER or GAP keyed on one cannot be (a layout per card): the base value applies and Compiled::findings() reports a CompileFinding { pointer, term, message }. That finding is NOT a registered code: PR5d adds one (the 06xx family) and prints it with the other lint findings.
    • The earlier prose claim ("item.* terms are lenient in when, treated true"; "transport.paused is not a state dimension") was wrong and is corrected here and in the handoff.
    • Tests: the reference's equaliser (when: item.is_current) is present for the current card only; an item-gated cell under the art is present per card and keeps its room; a title band with when: transport.paused is present exactly in the paused states (12 states, twice the 6); a gap keyed on transport.paused moves the title and nothing else, and only while paused; classic, reference, palette and hero-center keep reach's counts; a gap keyed on item.focused is a finding and lays out as the base.
  3. align: end anchored on the band's edge. Up Next, the Skip pill and Standin::row now anchor on union.x + union.w, the end edge of the replaced segments. Test: a band [end: row (replaced), end: menu]; the offer ends at the replaced row's end and does not overlap menu. Classic has no segment after the row, so its 320-comparison golden is unchanged.
  4. Skip title width. The title's fill stopped at the WIDER pill. A Skip state is now compiled for each label (CompiledState::skip_variant(SkipKind), skip_alt for the credits layout when it differs). Test: the title's right edge against classic::title_right for both labels in all ten languages, under both measurers.
  5. The band counts the knob. top() takes the bar's top as the focused knob's glow (classic::KNOB_GLOW_R = 17, a named constant now shared with draw_playbar) above the track's middle, so the band never moves with focus. Classic stays HudBand::CLASSIC (pinned). Hero-center is re-pinned to track.y + track.h / 2 - 17 (was the track's top), with the arithmetic in the test.
  6. One band value. HudGeometry has a band field; classic::frame_geometry fills it from its row anchor exactly as before; the compiler fills it from the compiled extents; HudGeometry::band() reads it. A test asserts the geometry's band equals Compiled::band() for every state of every fixture, both skip kinds. Every existing band pin is green.
  7. Row items past BTN_N. HudGeometry::items holds BTN_N = 5 stops (classic's row); the reference has 9 and R1 guarantees More. Compiled keeps all of them: controls and row_ids hold every control, and a test asserts the reference's nine. The zip into items carries a comment naming the PR7 obligation (widen the report to the longest row a package can place). PR7 must do this (see the handoff's "What PR7 needs").
  8. label_ys was widened for the golden but unread. The chapters test now compares the strip template's name and time text y with chapters_panel::label_ys() (26 / 34 under the card), to a thousandth of a pixel. Shown live by shifting the expected value by 1 px: the test fails.

Also: max_lines and genres_max were read without the keyed-value resolver (a keyed value read as 0 / 1); they go through it like every other keyable number.

Known edge, named not fixed: a keyable number that is really a PAINT-like scalar, text.alpha, is classified as geometry. Keyed on item.* it reports the finding (whose wording says "laid out once for every card"); keyed on transport.paused it makes paused an axis. No fixture keys it. Widening DrawOp::Text::alpha to Live<f32> is PR5d's call if the lint wants it.

Tests

compile_tests.rs (31 tests): the golden (above); the title's right edge against title_right (Discs, Up Next, and Skip at each label in all ten languages); band() == HudBand::CLASSIC under both measurers; the state counts against check (18 / 6 / 3); all six fixtures compile in every state, in every shipped language, under both measurers, with controls, bands, bar and grab inside the canvas and the count equal to check(..).states; the info section against info_panel; the chapters strip against chapters_panel (the delta above, and the 26 / 34 name and time offsets); classic's compact cost pinned and the strip's visible-card count (6); Live values; an unreachable state has no geometry; the Skip pill is end-anchored at both widths in every language; a centred offer stays centred on what it replaces (the reference); the replaced segments leave the frame but not the layout; a different label is a different width; band: block against band: controls; compiling twice is one value; CompileKey is a plain value; and the ten tests the review fixes added (equaliser per card, item-gated cell per card, paused band, paused gap, classic's counts, item-keyed finding, end-anchored offer beside a menu, one band value, the reference's nine controls, the Skip title per label), plus the label_ys offsets in the chapters test.

Issue

No issue tracks the HUD-plugin work; none was opened for this PR.

Gates

Local, on the final head 6d337288b (committed tree, git status --short empty after the runs, origin/main already an ancestor). Crate tests only; CI is the full gate:

  • make test-crate C=plx_appkit T=hud_format: test result: ok. 210 passed; 0 failed; 0 ignored; 0 measured; 378 filtered out; finished in 5.40s
  • make test-crate C=plx_appkit T=player_hud: test result: ok. 73 passed; 0 failed; 0 ignored; 0 measured; 515 filtered out; finished in 8.40s
  • python3 ci/check-localization.py: exit 0 ("Localization inventory: product text boundaries passed")
  • Also green: T=up_next (7 passed), T=info_panel (17 passed), T=chapters_panel (6 passed), T=skip_pill (2 passed), python3 ci/check-module-layers.py and bash ci/check-deps.sh (all gates green).

Not run here, left to CI: make check, make check-nodef, the ARM build, and any crate downstream of plx_appkit (HudGeometry lost Default and gained the required band field; a search found no constructor outside classic.rs). No TV or simulator pass: classic's frames do not change (stand_in_w and layout_at are the old expressions moved, and band is filled as band() computed it), and nothing draws from the compiled value yet.

🤖 Generated with Claude Code

GLinnik21 and others added 4 commits October 30, 2026 03:18
… state, and classic compiles to exactly the hand-written layout

`hud_format::compile::compile(&Package, &dyn Measure, CompileCtx) -> Compiled` lays a parsed package
out once in every state `reach` enumerates (it iterates `Layout::valuations` / `Layout::explore` and
evaluates `when` with `Layout::holds`, so there is no second state walk and no second condition
evaluator). A `CompiledState` carries the rect of every control keyed by id, a flat draw list in draw
order, the scrim, the bands, the bar and grab rects and the stand-ins, and
`Compiled::geometry(state, SkipKind) -> HudGeometry` is the one geometry type the player reads.
`Compiled::band()` is `HudBand::from_controls_top` over the compact states (classic is
`HudBand::CLASSIC`). Per state the compiler REPORTS a cost (draw ops, glyph runs, texture bytes,
blended pixel area, the three largest contributors); nothing enforces it, the ceilings are
calibrated on the television later. `CompileKey` is the cache key's type only.

Text is measured through the existing `plx_machine::machine::Measure`, the capability
`classic::geometry` takes; the compiler defines no measurer. Widths come from the same widget
functions the hand-written layout calls, and two values classic computed privately are now exposed
with no frame change: `classic::stand_in_w` (the stand-in pill formula `ctrl_slot_measure` used) and
`up_next::layout_at` (`layout_of` over any row anchor). `reach`'s `Slot`, `State`, `Valuation` and
`Layout` are published to the sibling compiler without a semantic change, and `title_right`,
`info_panel::{card_geometry, button_rect}` and `chapters_panel::{card_rect, label_ys}` widen to
`pub(crate)` for the golden.

`compiled_classic_matches_the_hand_written_layout` compares the compiled classic package with
`classic::geometry` field for field and to the exact f32, in every compact slot (Discs, Up Next, Skip
at both labels), for a movie and an episode, with and without chapters, in all ten shipped languages,
under both `FixtureMeasure` and `ShippedMeasure`. The info section matches `info_panel`'s card, still
and buttons; the chapters strip matches `chapters_panel`'s cards but for its top, which sits one
CAPTION line higher because the timestamp is a line with a height in the compiled chain (the fixture's
chapters gap is the placeholder; the delta is pinned, not forced). Every fixture compiles in every
state with its controls inside the canvas, and the state counts are `reach`'s (classic 18, reference
6, minimal 3). The prose that named PR5c as the lint flag's PR now names PR5d.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in PR3 (#1150: command vocabulary, control identity, the shared performer), which touched
up_next.rs and player_hud/. No conflict.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The compiled-vs-hand-written golden now checks its comparison count exactly (10 languages x 2
measurers x movie/episode x with/without chapters x 4 slots = 320), so a loop that quietly compares
less cannot pass.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… stand-ins, one band

Fixes the review of #1151 (FIX FIRST) in one round:

- check-localization: the compiler's rect fields are bound to locals before the
  struct initialiser, so no `title:`/`caption:` initialiser names a format key.
- transport.paused is an axis of the compile when a `when` or a number or gap
  names it (StateKey::paused); it never enters reach's valuations, so a package
  that does not name it keeps reach's state count (classic 18). Ink and bold
  keyed on it stay Live.
- item.* is the strip card's: a card's cell keeps its room and is present per
  card as a Live<bool> (CardOp::present); an ink or bold keyed on one stays Live.
  A number or gap keyed on one is a CompileFinding (PR5d registers its code),
  never a silent default.
- Up Next, the Skip pill and Standin::row anchor an end-aligned offer on the end
  edge of the replaced segments, not the band's.
- A Skip state carries the title laid out for the other pill too (skip_variant),
  so the fill stops at the label actually shown, as classic::title_right does.
- The band counts the bar with its largest (focused) knob and is one field of
  HudGeometry, filled by classic from its row anchor and by the compiler from its
  extents; band() reads the field.
- Compiled keeps every row control in `controls` and `row_ids`; the report's
  BTN_N = 5 slots are PR7's to widen (commented at the zip).
- max_lines and genres_max read through the keyed-value resolver like every
  other keyable number.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@GLinnik21 GLinnik21 changed the title HUD plugins: the layout compiler; classic compiles to exactly the hand-written layout HUD plugins: the layout compiler; classic compiles to the hand-written layout's geometry Oct 30, 2026
@GLinnik21
GLinnik21 marked this pull request as ready for review October 30, 2026 01:07
@GLinnik21
GLinnik21 merged commit 70a7aa6 into main Oct 30, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the hud/pr5c-compile branch October 30, 2026 01:18
GLinnik21 added a commit to LovelessCodes/plx-native that referenced this pull request Oct 31, 2026
Main landed the HUD plugin work (plxnative#1151, plxnative#1153, plxnative#1154): the layout compiler,
the lint and one renderer drawing from the embedded builtin:classic package.
The hand-written classic draw this PR edited is gone, so the Skip pill joining
the transport row now lives in the compiled layout.

- classic.rs, motion.rs: main's versions. The PR's join_slot / draw_discs /
  icon_hit edits targeted code main deleted; their behaviour is carried by
  the compiler (`layout.up_next.joins`, set by builtin:classic) and state.rs.
- hud_format/compile.rs: a joined Skip state keeps the five disc stops from
  the package row and puts the pill at items[BTN_SKIP], a CONTROL_GAP left of
  the run. A package that does not set `joins` still replaces the row.
- player_hud/geometry.rs: frame_state looks the Skip state up with the
  episode pair; row_len / row_command / row_enabled / row_primary treat a
  Skip pill that replaces the row as the row's one stop; new row_joined.
- player_hud/render.rs, skip_pill.rs: the Disc widget draws under a Skip
  slot; the SkipPill widget draws at its own ordinal when joined.
- player/mod.rs: neighbour walks ControlSlot::travel when the pill is joined.
- Re-recorded the Skip rows of the three frozen goldens (geometry,
  title-right, census). Every non-Skip line is byte-identical.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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