1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//! # threader
//!
//! Single home for all shared runtime state.
//!
//! ## The two structs
//!
//! [`Persistent`] holds everything that survives across frames: the widget tree,
//! focus state, resources, the message channel. It is never reset between ticks.
//!
//! [`Frame`] holds everything that belongs to a single tick: dt, input, the scene
//! draw list, viewport dimensions. It is updated at the start of every frame and
//! the scene is cleared before widgets draw into it.
//!
//! ## Why this split exists
//!
//! `Persistent` owns everything that survives across frames; `Frame` owns
//! everything that belongs to a single tick. This makes ownership unambiguous:
//! - "Does this survive the frame?" → `Persistent`
//! - "Does this reset every tick?" → `Frame`
//!
//! ## `FrameCtx`
//!
//! [`FrameCtx`] wraps both so any fn that needs the world just takes one argument.
//! Copy what you need locally at the top of the fn:
//!
//! ```ignore
//! let dt = ctx.frame.dt;
//! let input = &ctx.frame.input;
//! let debug = ctx.persistent.debug;
//! ```
//!
//! Write back explicitly when you change persistent state:
//!
//! ```ignore
//! ctx.persistent.nav.focus = Some(new_idx);
//! ctx.persistent.nav.focused_id = Some(id.to_string());
//! ```
//!
//! Never store `FrameCtx` — it is created at the top of `order::run_frame` and
//! lives only for that frame.
//!
//! ## Standalone vs overlay renderer ownership
//!
//! In **overlay** mode the caller owns the `wgpu::Device`, `wgpu::Queue`, and
//! `Pane` renderer; they are stored in `Persistent` so they survive across
//! frames. In **standalone** mode pane owns its own window but the renderer
//! is created fresh each frame inside `api::run` — it is passed through
//! `FrameCtx::standalone_pane` for that one frame and is not stored in
//! `Persistent`. That asymmetry is why `Persistent::renderer` is `None` in
//! standalone mode.
use HashMap;
use ;
use Instant;
use cratePaneAction;
use crate;
use crateInput;
use crateUiMsg;
use crate;
use crate;
use crate;
// ── BackgroundDef ─────────────────────────────────────────────────────────────
/// Describes the optional full-screen background drawn behind all widgets.
///
/// Stored as a named struct rather than a raw tuple so field access is
/// self-documenting at every call site.
// ── Persistent ────────────────────────────────────────────────────────────────
/// Everything that survives across frames.
///
/// Created once at startup and mutated in-place. The only things that replace
/// fields entirely are hot reload (rebuilds the widget tree) and root switches
/// (swaps `active_root` and clears focus).
// ── Frame ─────────────────────────────────────────────────────────────────────
/// Everything that belongs to a single tick.
///
/// `dt` and `last_tick` are updated at the start of each frame by `logic::tick_dt`.
/// `scene` is cleared at the start of each frame (`scene.clear()` in `order::run_frame`)
/// and populated by widget draw calls before being submitted to the GPU.
/// `input` is updated by the platform event loop and reset at the end of each
/// frame by `Input::begin_frame`.
// ── FrameCtx ──────────────────────────────────────────────────────────────────
/// The single argument every per-frame fn takes.
///
/// Gives read/write access to both [`Persistent`] and [`Frame`] without having
/// to pass them as separate arguments everywhere. Created at the top of
/// `order::run_frame` and never stored — its lifetime is exactly one frame.