jevsnes.git / packages / panels / README.md
1# Chapter 7: panels, everything drawn beside the picture
2
3The window shows the game in the middle and, around it, what we want to
4know about the game: what the bot thinks it is doing, the game state in
5words, every question Jev was asked, the pad, and a timeline to scrub. This
6crate draws all of that. It does not draw the game: the picture is never
7drawn over, so nothing covers the game's own hearts, rupees and item box.
8
9Every panel here is a function from a plain value to [egui](https://github.com/emilk/egui)
10calls (and, being built with the hot-patch flags, can be changed while the
11game runs: chapter 27). egui is an *immediate-mode* UI: there is no tree of widgets kept
12between frames. Each frame, the app calls `panels::state::show(ui, &state)`
13(or its neighbours), and whatever those calls describe is what is on screen.
14If you have written a React component that is a pure function of its props,
15you have written one of these; the difference is that it is called sixty
16times a second and there is no diffing.
17
18> **Aside: plain data in, on purpose.** The bot panel never sees a
19> `zbanks::Report`, and the replay panel never sees a `replay::Tree`. Those
20> crates link C or write files, and this one must stay portable (chapter 1).
21> So the app converts what it has into this crate's own small structs, and
22> these functions only draw.
23
24The layout is one function of the window's size, `Layout::of`: the
25picture's cell is exactly 4:3 with no slack, the two side columns are
26always the same width, and directly under the picture are the scrubber and
27then the pad. A test says so.
28
29```mermaid
30flowchart TB
31  subgraph window
32    direction LR
33    L["left: Bot, MCP"] --- P["picture, 4:3"] --- R["right: State, Jev"]
34  end
35  P --- S["scrubber"] --- PAD["pad"]
36```
37
38> **Try it.** `nix develop -c buck2 test //packages/panels:test` checks the
39> layout invariant, the scrubber's click-to-frame maths and the Jev
40> history's rows (the favourite, a missing probability, a long option
41> wrapping). To see the panels themselves, open the window (chapter 12).
42
43## For the people who maintain it
44
45### In this folder
46
47| Path | What |
48| --- | --- |
49| [src/lib.rs](src/lib.rs) | The modules. |
50| [src/bot.rs](src/bot.rs) | What the bot says about itself: its info line, task list, goal list with scores, traps, and the stall and recovery lines. Plain data in; this crate never links the bot. |
51| [src/jev.rs](src/jev.rs) | Jev at the goal choice: on or off, the shared spend guards (spent so far, plainly, with no cap), a usage graph bucketed by game frame across the current recording with a playhead, and a scrollable, click-to-expand history of every choice (the request as sent, every option's probability, the pick and upstream's own, tokens, latency, cost, or why nothing was asked). |
52| [src/state.rs](src/state.rs) | The `alttp::State` in words. |
53| [src/pad.rs](src/pad.rs) | A SNES pad. Buttons held on the last frame are lit; a press that came with a confidence carries it as a percentage. |
54| [src/layout.rs](src/layout.rs) | The whole window layout as one function of its size, with its test. |
55| [src/replay.rs](src/replay.rs) | The replay timeline: a scrubber over everything a recording has played, play/pause, skip to end, the speed control, and "run the bot from here". |
56| [src/palette.rs](src/palette.rs) | Every colour these panels use, legible on the dark theme. |
57| [BUCK](BUCK) | The `rust_library`, built with the hot-patch flags (`-Csave-temps=true`, `-Clink-dead-code`), and `//packages/panels:test`. |
58
59The MCP panel is not here: only the native window has a server, so it lives
60in `apps/native`.
61
62← Previous: [Chapter 6, replay/](../replay/) · Up: [packages](../) · Next: [Chapter 8, mcp/](../mcp/) →