truce_gui_types/snapshot.rs
1//! Read-only view of parameter state consumed by the pure-library
2//! rendering and interaction functions (`widgets::draw`,
3//! `interaction::dispatch`).
4//!
5//! Callers build a `ParamSnapshot` per frame from their own parameter
6//! store - typically `BuiltinEditor` forwards `PluginContext` + `Params`
7//! accesses, but any plugin that owns its own frame can populate it
8//! from whatever source it likes.
9
10use crate::widgets::WidgetType;
11
12/// Immutable view of one frame's worth of parameter state.
13///
14/// Each field is a borrowed closure, so the snapshot itself is cheap
15/// to construct - no copying of values up front. Closures are read
16/// on demand as widgets/dispatch need them.
17pub struct ParamSnapshot<'a> {
18 /// Read normalized value (0.0–1.0).
19 pub get_param: &'a dyn Fn(u32) -> f32,
20
21 /// Read plain (unit-scaled) value.
22 pub get_param_plain: &'a dyn Fn(u32) -> f32,
23
24 /// Format the current plain value as a display string.
25 pub format_param: &'a dyn Fn(u32) -> String,
26
27 /// Read a meter value (0.0–1.0).
28 pub get_meter: &'a dyn Fn(u32) -> f32,
29
30 /// Enumerate option display strings for a discrete/enum parameter.
31 /// Returns empty if the parameter is continuous or not dropdown-shaped.
32 pub get_options: &'a dyn Fn(u32) -> Vec<String>,
33
34 /// Default normalized value, used for reset-on-double-click.
35 pub default_normalized: &'a dyn Fn(u32) -> f32,
36
37 /// Compute the next normalized value after a click-to-cycle selector
38 /// advance. Wraps around at the end of the range.
39 pub next_discrete_normalized: &'a dyn Fn(u32) -> f32,
40
41 /// Quantize a normalized value to the param's nearest representable
42 /// step. For `IntParam` / `EnumParam` this snaps to integer steps;
43 /// continuous (`FloatParam`) ranges return the input unchanged.
44 /// Called from drag / wheel paths so emitted `ParamEdit::Set` events
45 /// already carry the snapped value.
46 pub snap_normalized: &'a dyn Fn(u32, f32) -> f32,
47
48 /// Parameter display name. Used as a fallback label when a layout
49 /// entry did not supply its own (e.g. XY-pad axis names).
50 pub param_name: &'a dyn Fn(u32) -> String,
51
52 /// Auto-detected widget type from the parameter's range. `widgets::draw`
53 /// uses this when the layout entry did not specify an explicit widget
54 /// kind.
55 pub widget_type: &'a dyn Fn(u32) -> WidgetType,
56}