Module inspector

Source
Expand description

Checked, borrowed authoring controls in logical screen units.

Build from a fixed model snapshot. Numeric formatting/units and domain rules belong to the caller. No model reference is stored or mutated: only an InspectorOutcome::Accepted value may be applied, outside UI composition. Validation callbacks must be pure; arbitrary callback side effects cannot be rolled back. An invalid edit returns its error without changing the snapshot. Feed the error back as field copy next frame (for example FieldState::Invalid), or in a separate notice. Disabled, unavailable and invalid fields have distinct visible prefixes and never propose changes.

InspectorLayout::finish atomically submits all commands through Ui::compose, then finishes input and validates at most one fresh activation. It deliberately exposes no speculative result from inside a composition. Call once per frame after Ui::begin, after other UI submissions. Use InspectorLayout::finish_player for the existing remapped confirm route; do not separately finish/route that edge through another UI owner. On submit failure input is not finished: finish the restored prior UI or an explicit readable fallback yourself. The inspector is an overlay, not a modal; panels are paint-only. Route scene gestures using Ui::interaction after finish.

All labels, values, units, status messages and controls are measured before insertion. At most 16 fields, eight choices per field and 8192 source bytes. Rows wrap without shrinking fonts; every control stays at least 44 units high. Too narrow/short bounds reject the entire layout with InvalidLayout: the caller must choose a larger panel, fewer fields or a separate readable view. There is no silent omission, implicit scroll or text-entry framework. Use bounds fully inside the viewport safe area and inherited clips; later ancestor clipping can still obscure content. Inspection exposes actual button rectangles and complete labels. Theme tokens map directly to ordinary text/button styles; retained button focus outlines keep their existing two-unit stroke.

This runnable native recipe uses the real ordered touch journal, a fixed snapshot, pure domain validation and application after finish. It is synthetic native input, not a window/device playtest. Physics lab adoption and complete mass/gravity/friction validator recipes are handed off in task285’s receipt.

use ferravex_play::ui::theme::{ThemeMode, UiTheme};
use ferravex_render::{Vec2, input::{host_frame, touch, touch_event},
    ui::{Ui, UiError, Viewport, inspector::*}};
let mut model = 1.0_f32;
let mut ui = Ui::new();
let viewport = Viewport::responsive([320., 480.], [0.; 4])?;
let fields = [InspectorField {
    id: 1, label: "MASS", display: "1.00", unit: "kg", state: FieldState::Enabled,
    control: InspectorControl::Stepper { value: model, min: 0.1, max: 100.,
        step: 0.25, policy: LimitPolicy::Reject, decrease: 2, increase: 3 },
}];
let layout = InspectorLayout::new(viewport.bounds(), &fields,
    UiTheme::preset(ThemeMode::Normal))?;
let rect = layout.control_rect(3).unwrap();
for phase in [touch::Phase::Start, touch::Phase::End] {
    touch_event(touch::Event { id: 7, phase,
        position: Vec2::new(rect.min[0] + 2., rect.min[1] + 2.) });
}
host_frame(0., 320, 480, || -> Result<(), UiError> {
    ui.begin(viewport);
    let outcome = layout.finish(&mut ui, true, |change| {
        // Substitute the existing physics/body validator, using a candidate copy.
        match change.value {
            FieldValue::Number(n) if n <= 10. => Ok(()),
            _ => Err("mass exceeds this tool's authored limit"),
        }
    })?;
    assert_eq!(model, 1.); // Nothing mutated during composition or validation.
    if let InspectorOutcome::Accepted(change) = outcome {
        if let FieldValue::Number(n) = change.value { model = n; }
    }
    assert!(ui.interaction().pointer_consumed);
    ui.paint();
    Ok(())
})?;
assert_eq!(model, 1.25);

Structs§

InspectorChoice
Stable ID and complete single-line choice copy; disabled options stay visible.
InspectorField
A fixed snapshot with caller-formatted value/units. Display must be nonblank; it is never parsed. Units may be empty. Multi-line field/status copy wraps.
InspectorLayout
Immutable measured layout. No heap storage, model/controller or hidden reset state. Rebuild after any model/copy/theme/bounds change; Ui::begin clears old submissions, and Ui::cancel cancels capture when the tool closes/resets.
ValueChange
Previous snapshot value and validated proposed value, keyed by caller field ID.

Enums§

FieldState
Availability and complete contextual message. Only Enabled permits edits.
FieldValue
Typed proposal values, with no references to a live model.
InspectorControl
Borrowed control snapshot. Field and control IDs must all be distinct.
InspectorOutcome
One finished activation. Apply Accepted once, then rebuild the snapshot. Idle includes disabled input, cancellation, a held gesture and unchanged choice.
InvalidEdit
Numeric rejection is separate from caller-owned domain validation.
LimitPolicy
An explicit authored policy; overflow/nonfinite arithmetic always rejects.

Constants§

MAX_INSPECTOR_BYTES
Combined UTF-8 bytes, including disabled and unselected copy.
MAX_INSPECTOR_CHOICES
Maximum options in one choice field.
MAX_INSPECTOR_FIELDS
Hard source bounds, checked before scanning field copy or choices.