Skip to main content

brep_app/
form_view.rs

1//! Schema-driven form layout built on [`form::field_input`].
2//!
3//! The view edits parameter data and returns [`FormViewOut`] actions for the caller
4//! to apply after drawing. It takes no engine or document, so the app and capture
5//! tools can use the same layout without overlapping mutable engine borrows.
6//!
7//! Sections run from references and parameters through schema-ordered groups,
8//! followed by Transform and read-only sections. Transform and Outputs start
9//! collapsed. Reference selections stay visible below their activation button.
10//!
11//! Accordion and arrival-scroll state lives in egui memory keyed by the form's
12//! hit prefix, title, and section.
13
14use crate::form;
15use brep_render::style::{FieldKind, FormField};
16use eframe::egui;
17use serde_json::Value;
18use std::collections::{HashMap, HashSet};
19
20/// Groups that are drawn as a COLLAPSED accordion by default. `Transform` is the
21/// owner's explicit call (R6); the read-only trailing sections join it because
22/// they report, they do not edit. Everything else opens by default — a section
23/// the user must click to see is a section they will miss.
24const COLLAPSED_BY_DEFAULT: &[&str] = &["Transform", "Outputs"];
25
26/// Everything ABOUT the form that the consumer supplies. Borrowed; the form view
27/// holds no state of its own beyond egui memory.
28pub struct FormViewSpec<'a> {
29    /// The form's heading — e.g. `"E3  ⟠ Extrude"`. Also the scope key for this
30    /// form's transient view state and per-field widget ids, so it must be
31    /// STABLE and UNIQUE per subject (a feature id / constraint id qualifies).
32    pub title: &'a str,
33    /// An optional second line under the title (a status, a type name…).
34    pub subtitle: Option<&'a str>,
35    /// The schema fields to render, in schema order.
36    pub fields: &'a [FormField],
37    /// Field keys ([`FormField::key`]) to HIDE this frame — the schema-driven
38    /// field-visibility hook. A field whose key is in this set is dropped BEFORE
39    /// the fields are partitioned into sections, so a group left with nothing
40    /// visible draws no header. `None` (the common case) hides nothing. A feature
41    /// consumer fills this from [`brep_render::features::feature_hidden_params`]
42    /// against the LIVE params each frame, so it reacts to both first display and
43    /// every field change with no extra plumbing.
44    pub hidden: Option<&'a HashSet<String>>,
45    /// A message banner drawn under the title — e.g. the feature's run error.
46    /// A banner marked as an error also carries the Report problem button.
47    pub banner: Option<FormBanner<'a>>,
48    /// Read-only sections appended after the fields — e.g. `[("Outputs", …)]`.
49    pub trailing: Option<&'a [(&'a str, Vec<String>)]>,
50    /// ONE consumer-drawn section `(title, drawer)` placed after the schema
51    /// groups and before the trailing sections — for a subject whose editing
52    /// surface the schema cannot express (a spline's anchor list). The drawer
53    /// is `Fn`, so anything it decides goes through interior mutability the
54    /// consumer owns; the form view stays intent-out like everything else here.
55    pub extra: Option<(&'a str, &'a dyn Fn(&mut egui::Ui))>,
56    /// The exit button's label — the button at the RIGHT end of the title row.
57    /// Both of today's consumers say "Return to tree" — the history feature list
58    /// and the constraint list are BOTH drawn by `panels::tree`, so the word is
59    /// literal, not a metaphor (Q12). A consumer whose list is NOT a tree
60    /// supplies its own wording here.
61    pub exit_label: &'a str,
62    /// Whether this consumer's subject lives in a ROLLED history — i.e. whether
63    /// LEAVING the form also means "roll the model back to the tip".
64    ///
65    /// The form view holds no engine and therefore cannot roll anything itself
66    /// (that is [`FormViewOut::roll_to_tip`], which the caller acts on). What
67    /// this flag does is decide, in ONE place, whether an exit *carries* that
68    /// intent — so no consumer has to hard-code "am I the history panel?" at its
69    /// exit arm. The history panel passes `true`; assembly constraints have no
70    /// rollback at all (the owner's call) and pass `false`, which is why their
71    /// panel has no roll branch to get wrong.
72    pub rollback: bool,
73    /// Prefix for every published hit key. `""` for a consumer that shows ONE
74    /// form at a time (history); a consumer that can show several at once MUST
75    /// pass a prefix carrying the subject id or the rects collide silently.
76    pub hits_prefix: &'a str,
77    /// Why the subject may not change (a PLM revision not checked out, or
78    /// released), or `None`. The fields then draw DISABLED under a banner
79    /// saying why, so nothing is typed that the engine would refuse and the
80    /// field's buffer would keep; the exit button stays live.
81    pub read_only: Option<&'a str>,
82    /// The reference field a pick is RUNNING in, when one is — the form draws
83    /// it as the focused selection box ([`form::ActivePick`]): its button
84    /// reads `Done`, its list is the engine's running picks and its `✕`s come
85    /// out as [`FormViewOut::pick_remove`]. `None` draws every reference field
86    /// at rest.
87    pub picking: Option<form::ActivePick<'a>>,
88}
89
90/// The message under a form's title. The slot also carries statuses and notes,
91/// so whether it is an ERROR is stated by the consumer, never read off a colour.
92#[derive(Debug, Clone, Copy, PartialEq)]
93pub struct FormBanner<'a> {
94    pub text: &'a str,
95    pub color: egui::Color32,
96    pub is_error: bool,
97}
98
99impl<'a> FormBanner<'a> {
100    /// A status or a note: drawn alone.
101    pub fn note(text: &'a str, color: egui::Color32) -> Self {
102        Self { text, color, is_error: false }
103    }
104
105    /// An error: drawn with the Report problem button.
106    pub fn error(text: &'a str, color: egui::Color32) -> Self {
107        Self { text, color, is_error: true }
108    }
109}
110
111/// A form's Report problem button was pressed: what the report is pre-filled
112/// with. It travels through egui memory to the app, which owns the report flow,
113/// so a new dialog gets the button with no plumbing through its panel.
114#[derive(Debug, Default, Clone, PartialEq)]
115pub struct ProblemReportRequest {
116    /// The form's title: which feature or dialog the error came from.
117    pub dialog: String,
118    /// The error text the dialog is showing.
119    pub error: String,
120}
121
122fn problem_report_id() -> egui::Id {
123    egui::Id::new("form-view-report-problem")
124}
125
126/// The Report problem press waiting for the app, if there is one; taking it
127/// clears it, so one press opens one report.
128pub fn take_problem_report_request(ctx: &egui::Context) -> Option<ProblemReportRequest> {
129    ctx.data_mut(|data| data.remove_temp(problem_report_id()))
130}
131
132/// A reference field's `Select` was pressed — the caller dispatches this to its
133/// own picker flavour (`begin_ref_select` / `begin_ref_select_for_constraint`).
134#[derive(Debug, Clone, PartialEq)]
135pub struct RefActivate {
136    /// The JSON key chain the picked selection writes back into.
137    pub path: Vec<String>,
138    /// The field's label, for the picker's prompt.
139    pub label: String,
140    /// The schema's entity-kind filter (`["solid"]`, `["face"]`…).
141    pub filter: Vec<String>,
142    /// Whether the field accepts more than one entity.
143    pub multiple: bool,
144    /// The names already chosen — the picker lights them up as the seed.
145    pub seed: Vec<String>,
146}
147
148/// What the user did in one drawn frame of the form.
149#[derive(Debug, Default, Clone, PartialEq)]
150pub struct FormViewOut {
151    /// A field wrote into `params` — the caller commits the whole buffer.
152    pub changed: bool,
153    /// A [`FieldKind::Button`] field was clicked, by its key (`"editSketch"`).
154    pub button_clicked: Option<String>,
155    /// A reference field's `Select` was pressed. With a pick already running
156    /// in ANOTHER field (`spec.picking`), the consumer finishes that one first:
157    /// focus moves from box to box, one pick at a time.
158    pub ref_activate: Option<RefActivate>,
159    /// The focused reference field's `Done` was pressed: commit the running
160    /// pick.
161    pub pick_done: bool,
162    /// An `✕` on the focused reference field: drop the i-th running pick.
163    pub pick_remove: Option<usize>,
164    /// The title row's exit button was pressed — the caller returns to its list.
165    pub exit_clicked: bool,
166    /// The exit ALSO means "roll the model to the tip" — set only when the exit
167    /// button was pressed AND the consumer declared [`FormViewSpec::rollback`].
168    /// Always `false` for a consumer with no rollback, so its panel never needs
169    /// the branch.
170    pub roll_to_tip: bool,
171    /// The pointer is over a line that NAMES a scene entity — a reference line or
172    /// a read-only trailing line (`Outputs`). The caller feeds it to
173    /// `EngineState::hover_entity_by_name` so the entity lights in the 3D view
174    /// exactly as mousing over it there would, and calls
175    /// `EngineState::dialog_hover_end` when it is `None`.
176    pub hovered_entity: Option<String>,
177}
178
179/// Draw ONE complete schema-driven form into `ui`, editing `params` live, and
180/// return what the user did. `hits`, when supplied, receives the widget screen
181/// rects the headed verifier drives:
182///
183/// | key | what |
184/// |---|---|
185/// | `form:feature` | the title label |
186/// | `form:section:{Group}` | an accordion header |
187/// | `form:return` | the exit button, right end of the title row |
188/// | `form:error` | the error banner, while the form shows an error |
189/// | `form:report-problem` | that banner's Report problem button |
190/// | `field:{path}` | a field's input widget |
191/// | `field:{path}#{variant}` | an OPEN enum's items |
192/// | `field:{path}#activate` / `#x{i}` | a reference's Select / remove buttons (the focused field's Select is its Done) |
193/// | `field:{path}#line{i}` | a reference's i-th chosen-entity line |
194/// | `form:trailing:{Section}:{i}` | a read-only section's i-th line (`Outputs`) |
195///
196/// all with `spec.hits_prefix` prepended.
197/// Padding INSIDE the form's container — the gap between the frame edge and the
198/// first/last widget on every side.
199const FORM_MARGIN: i8 = 10;
200
201/// Gap OUTSIDE the container, between it and the pane edge, so the frame's own
202/// stroke is not flush against the dock border.
203const FORM_OUTER_MARGIN: i8 = 6;
204
205/// Whether the visibility hook hides field `f`: the set names a schema param
206/// (its first path segment, e.g. `offset` hides the whole transform), the
207/// field's own key, or its dotted path (`offset.scale` hides one row of it).
208fn field_hidden(hidden: &HashSet<String>, f: &FormField) -> bool {
209    hidden.contains(f.key())
210        || f.path.first().is_some_and(|param| hidden.contains(param))
211        || (f.path.len() > 1 && hidden.contains(&f.path.join(".")))
212}
213
214pub fn form_view(
215    ui: &mut egui::Ui,
216    spec: &FormViewSpec<'_>,
217    params: &mut Value,
218    mut hits: Option<&mut HashMap<String, egui::Rect>>,
219) -> FormViewOut {
220    let mut out = FormViewOut::default();
221
222    // A form ARRIVES IN VIEW. Every consumer's pane is wrapped in the dock's
223    // `ScrollArea`, whose offset egui remembers PER PANE — so a form opened from
224    // a tree the user had scrolled down inherits that offset and starts part-way
225    // in, with the title row (and the exit button on it) above the viewport. The
226    // enclosing scroll area is asked to bring the CURSOR — which is the form's
227    // TOP EDGE here, before the container's own margins push it down — into
228    // view, ONCE per arrival: keyed on the subject AND on having been drawn on
229    // the previous pass, so re-opening the same subject after a trip back to the
230    // tree resets too, while scrolling INSIDE an open form sticks.
231    //
232    // WHERE this sits matters: inside the container it would align the first
233    // WIDGET, not the form, and leave the pane a margin's worth (measured: 14
234    // pt) past the form's own top edge and border. Out here the cursor IS that
235    // edge. The align is `None` — "only if it is not already visible" — rather
236    // than `Align::TOP`, so a pane already at the top computes a zero delta and
237    // asks for nothing at all, rather than a target that only happens to clamp
238    // back to where it was.
239    //
240    // (`form_view` cannot reach the scroll area itself — it is the consumer's,
241    // two levels out — and asking through the cursor is what keeps the required
242    // inputs at `(ui, spec, &mut params)` for the headless caller.)
243    let arrival = egui::Id::new(("form-view-arrival", spec.hits_prefix));
244    let pass = ui.ctx().cumulative_pass_nr();
245    let arrived = ui.ctx().memory_mut(|m| {
246        let previous: Option<(String, u64)> = m.data.get_temp(arrival);
247        let continuing = previous
248            .is_some_and(|(title, drawn)| title == spec.title && pass.saturating_sub(drawn) <= 1);
249        m.data.insert_temp(arrival, (spec.title.to_string(), pass));
250        !continuing
251    });
252    if arrived {
253        // INSTANT, not animated: the reset must land before the frame the user
254        // sees, and a dialog gliding into place on every open is noise.
255        ui.scroll_to_cursor_animation(None, egui::style::ScrollAnimation::none());
256    }
257
258    // The whole form sits inside ONE padded container, so the fields never run
259    // flush against the pane edge the way the inline tree rendering did. The
260    // margin is the frame's, not per-widget spacing: a single container keeps
261    // the label-above-full-width rhythm intact when the pane is resized, and
262    // gives the scroll region a consistent inset on every side.
263    egui::Frame::group(ui.style())
264        .inner_margin(egui::Margin::same(FORM_MARGIN))
265        .outer_margin(egui::Margin::same(FORM_OUTER_MARGIN))
266        .show(ui, |ui| {
267            form_body(ui, spec, params, &mut hits, &mut out);
268        });
269
270    out
271}
272
273/// The form's contents, drawn INSIDE the padded container opened by
274/// [`form_view`]. Split out so the container owns the margin in one place
275/// rather than every section adding its own edge spacing.
276fn form_body(
277    ui: &mut egui::Ui,
278    spec: &FormViewSpec<'_>,
279    params: &mut Value,
280    hits: &mut Option<&mut HashMap<String, egui::Rect>>,
281    out: &mut FormViewOut,
282) {
283    // Fill the container's width so full-width inputs stay full width.
284    ui.set_width(ui.available_width());
285
286    // --- heading + the ONE exit button, on one row -------------------------
287    // No OK/Cancel pair and no buffer: editing is LIVE (every change commits and
288    // re-runs) and UNDO is the revert mechanism, so there is nothing for a
289    // Cancel to roll back that undo does not already cover.
290    //
291    // The exit is allocated FIRST, from the RIGHT edge, and the title takes what
292    // is left over: a right-to-left row measures the button before the heading
293    // exists, so no title — however long — can push the button off the pane, and
294    // the heading truncates into the remainder instead of running under it. (The
295    // reverse order, title-then-button, is exactly the layout that loses the
296    // button on a long feature name.)
297    ui.horizontal(|ui| {
298        ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
299            let exit = ui.button(spec.exit_label);
300            publish(spec, hits, "form:return", exit.rect);
301            out.exit_clicked = exit.clicked();
302            // The exit's rollback half, gated by the consumer's declaration —
303            // see [`FormViewSpec::rollback`].
304            out.roll_to_tip = out.exit_clicked && spec.rollback;
305            // Back to reading order for the title, inside whatever width the
306            // button left behind.
307            ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
308                let head = ui.add(
309                    egui::Label::new(egui::RichText::new(spec.title).heading()).truncate(),
310                );
311                publish(spec, hits, "form:feature", head.rect);
312            });
313        });
314    });
315    if let Some(subtitle) = spec.subtitle {
316        ui.label(egui::RichText::new(subtitle).weak());
317    }
318    ui.separator();
319
320    // --- banner: the subject's error, ABOVE the fields ---------------------
321    // (The history tree ALSO keeps this on the feature's row, so a failure is
322    // still visible while scanning the tree — see the panel.)
323    if let Some(banner) = spec.banner {
324        let frame = egui::Frame::group(ui.style())
325            .stroke(egui::Stroke::new(1.0, banner.color))
326            .fill(banner.color.gamma_multiply(0.12))
327            .show(ui, |ui| {
328                ui.set_width(ui.available_width());
329                ui.add(
330                    egui::Label::new(egui::RichText::new(banner.text).color(banner.color))
331                        .wrap_mode(egui::TextWrapMode::Wrap),
332                );
333                banner.is_error.then(|| ui.button("Report problem"))
334            });
335        if let Some(report) = frame.inner {
336            publish(spec, hits, "form:error", frame.response.rect);
337            publish(spec, hits, "form:report-problem", report.rect);
338            if report.clicked() {
339                let request = ProblemReportRequest { dialog: spec.title.to_string(), error: banner.text.to_string() };
340                ui.ctx().data_mut(|data| data.insert_temp(problem_report_id(), request));
341                ui.ctx().request_repaint();
342            }
343        }
344        ui.add_space(4.0);
345    }
346
347    // --- read-only: say why, and take no edit below this line ------------
348    if let Some(reason) = spec.read_only {
349        egui::Frame::group(ui.style())
350            .stroke(egui::Stroke::new(1.0, ui.visuals().weak_text_color()))
351            .show(ui, |ui| {
352                ui.set_width(ui.available_width());
353                let said = ui.add(egui::Label::new(format!("Read-only: {reason}")).wrap_mode(egui::TextWrapMode::Wrap));
354                publish(spec, hits, "form:read-only", said.rect);
355            });
356        ui.add_space(4.0);
357        ui.disable();
358    }
359
360    // --- partition the schema into direct params + grouped sections --------
361    let mut references: Vec<&FormField> = Vec::new();
362    let mut param_leaves: Vec<&FormField> = Vec::new();
363    let mut groups: Vec<(&str, Vec<&FormField>)> = Vec::new();
364    for f in spec.fields {
365        // The field-visibility hook: a hidden field is dropped here, before the
366        // partition, so it never reaches a section — and an emptied group never
367        // draws a bare header. Evaluated fresh each frame against the live params
368        // by the consumer, this is what makes fields show/hide as the field that
369        // governs them (e.g. a hole's type) changes.
370        if spec.hidden.is_some_and(|h| field_hidden(h, f)) {
371            continue;
372        }
373        match f.group.as_str() {
374            "References" => references.push(f),
375            "Parameters" => {
376                if matches!(f.kind, FieldKind::Text { read_only: true }) {
377                    continue; // the subject id — already the form's title
378                }
379                param_leaves.push(f);
380            }
381            group => match groups.iter_mut().find(|(name, _)| *name == group) {
382                Some(existing) => existing.1.push(f),
383                None => groups.push((group, vec![f])),
384            },
385        }
386    }
387    // Transform trails the other groups: it is the one the owner named as the
388    // collapsed accordion, so it belongs at the bottom, not between two open
389    // sections.
390    groups.sort_by_key(|(name, _)| usize::from(*name == "Transform"));
391
392    // (1) references, then (2) plain parameters — both un-sectioned, because a
393    // section over the fields the user came here to edit is a click in the way.
394    for f in references.iter().chain(param_leaves.iter()) {
395        draw_field(ui, spec, f, params, hits, out);
396    }
397
398    // (3) the remaining groups, each an accordion.
399    for (name, fields) in &groups {
400        section(ui, spec, name, hits, |ui, hits| {
401            for f in fields {
402                draw_field(ui, spec, f, params, hits, out);
403            }
404        });
405    }
406
407    // (4) the consumer's own section, when it has one.
408    if let Some((name, draw)) = spec.extra {
409        section(ui, spec, name, hits, |ui, _hits| draw(ui));
410    }
411
412    // (5) read-only trailing sections (Outputs…).
413    //
414    // These lines NAME scene entities too (a feature's output solids), so they
415    // report a hover exactly as a reference line does — the section is read-only
416    // in the sense that it edits nothing, not that it is inert.
417    let mut trailing_hover: Option<String> = None;
418    for (name, values) in spec.trailing.unwrap_or(&[]) {
419        section(ui, spec, name, hits, |ui, hits| {
420            if values.is_empty() {
421                ui.label(egui::RichText::new("(none)").weak());
422            }
423            for (i, value) in values.iter().enumerate() {
424                let line = ui.label(format!("• {value}"));
425                if line.hovered() {
426                    trailing_hover = Some(value.clone());
427                }
428                publish(spec, hits, &format!("form:trailing:{name}:{i}"), line.rect);
429            }
430        });
431    }
432    if trailing_hover.is_some() {
433        out.hovered_entity = trailing_hover;
434    }
435
436    // Breathing room UNDER the last thing in the form, so the final section's
437    // widgets are not flush against (and, once egui rounds their rects to
438    // physical pixels, a hair past) the pane's clip edge — which is exactly
439    // where a click stops landing.
440    ui.add_space(8.0);
441}
442
443/// Record one widget rect under `spec.hits_prefix`.
444fn publish(
445    spec: &FormViewSpec<'_>,
446    hits: &mut Option<&mut HashMap<String, egui::Rect>>,
447    key: &str,
448    rect: egui::Rect,
449) {
450    if let Some(map) = hits.as_deref_mut() {
451        map.insert(format!("{}{key}", spec.hits_prefix), rect);
452    }
453}
454
455/// One collapsible section: a header row that publishes `form:section:{name}`
456/// and, when open, `body`. Open/collapsed lives in egui memory, keyed to this
457/// form's subject, so two features' Transform sections remember separately and
458/// the caller carries no state.
459fn section(
460    ui: &mut egui::Ui,
461    spec: &FormViewSpec<'_>,
462    name: &str,
463    hits: &mut Option<&mut HashMap<String, egui::Rect>>,
464    body: impl FnOnce(&mut egui::Ui, &mut Option<&mut HashMap<String, egui::Rect>>),
465) {
466    ui.add_space(6.0);
467    let open = !COLLAPSED_BY_DEFAULT.contains(&name);
468    let response = egui::CollapsingHeader::new(egui::RichText::new(name).strong())
469        .id_salt(("form-view-section", spec.hits_prefix, spec.title, name))
470        .default_open(open)
471        .show(ui, |ui| body(ui, hits));
472    publish(
473        spec,
474        hits,
475        &format!("form:section:{name}"),
476        response.header_response.rect,
477    );
478}
479
480/// Draw ONE schema field: its label, then the input at FULL WIDTH beneath it.
481/// A `Reference` is the same shape — [`form::field_input`] draws its activation
482/// button and the chosen entities under this same label.
483fn draw_field(
484    ui: &mut egui::Ui,
485    spec: &FormViewSpec<'_>,
486    field: &FormField,
487    params: &mut Value,
488    hits: &mut Option<&mut HashMap<String, egui::Rect>>,
489    out: &mut FormViewOut,
490) {
491    let mut probe: HashMap<String, egui::Rect> = HashMap::new();
492    let mut rect = egui::Rect::NOTHING;
493    let mut actions = form::FieldActions::default();
494    ui.add_space(4.0);
495    // A `Button` field IS its own label (the schema gives it one), so a label
496    // above it would say the same thing twice. A `Bool` puts its checkbox on
497    // the label's row, as Settings does: a box alone on a line under its label
498    // spent two rows on one tick and read as detached from it
499    // (ui-polish-2026-10-28 row 12). The box is still the field's rect and the
500    // only thing that toggles, exactly as before.
501    let inline = matches!(field.kind, FieldKind::Bool);
502    if !inline && !matches!(field.kind, FieldKind::Button { .. }) {
503        ui.label(&field.label);
504    }
505    // Scope the widget id-stack to THIS (subject, field) so a Scalar's
506    // per-location egui-memory edit buffer (and its TextEdit focus id) can't
507    // collide when two subjects share a param name — switching between two
508    // extrudes mid-edit must not hand one's half-typed `distance` to the other.
509    // `make_persistent_id` folds in the ui id-stack only.
510    // The FULL path, not the last segment: a nested form (CAM's operation
511    // dialog) has `leadIn.kind` and `ramp.kind` on one subject, which would
512    // otherwise share an id. A single-segment path is its key, as before.
513    ui.push_id((spec.title, field.path.join(".")), |ui| {
514        let (changed, r) = if inline {
515            ui.horizontal(|ui| {
516                let drawn = form::field_input_with(ui, field, params, Some(&mut probe), &mut actions, spec.picking);
517                ui.label(&field.label);
518                drawn
519            })
520            .inner
521        } else {
522            form::field_input_with(ui, field, params, Some(&mut probe), &mut actions, spec.picking)
523        };
524        out.changed |= changed;
525        rect = r;
526    });
527    if let Some(map) = hits.as_deref_mut() {
528        let prefix = spec.hits_prefix;
529        map.insert(format!("{prefix}field:{}", field.path.join(".")), rect);
530        for (key, r) in probe {
531            map.insert(format!("{prefix}field:{key}"), r);
532        }
533    }
534    // A hovered reference LINE names an entity; the form's consumer owns lighting
535    // it (that needs the engine). One line is under the pointer at a time, so the
536    // last field to report wins — and only one ever reports.
537    if actions.hovered_entity.is_some() {
538        out.hovered_entity = actions.hovered_entity.take();
539    }
540    // The focused reference field's own two intents.
541    out.pick_done |= actions.pick_done;
542    if actions.pick_remove.is_some() {
543        out.pick_remove = actions.pick_remove;
544    }
545    // `field_input` reports the two ACTION kinds through the same out-param, by
546    // field key; which intent it is comes from the field's own kind.
547    if actions.clicked.is_some() {
548        match &field.kind {
549            FieldKind::Reference { filter, multiple } => {
550                out.ref_activate = Some(RefActivate {
551                    path: field.path.clone(),
552                    label: field.label.clone(),
553                    filter: filter.clone(),
554                    multiple: *multiple,
555                    seed: form::reference_names(form::value_at(params, &field.path)),
556                });
557            }
558            _ => out.button_clicked = actions.clicked.take(),
559        }
560    }
561}
562