pub enum ParamRange {
Linear {
min: f64,
max: f64,
},
Logarithmic {
min: f64,
max: f64,
},
Skewed {
min: f64,
max: f64,
factor: f64,
},
SymmetricalSkewed {
min: f64,
max: f64,
factor: f64,
center: f64,
},
Discrete {
min: i64,
max: i64,
},
Enum {
count: usize,
},
Reversed(&'static ParamRange),
}Expand description
Defines how a parameter maps between plain and normalized values.
Copy because every variant is POD (scalars, or a &'static for
Self::Reversed). Lets format wrappers pass info.range by value
without clone() noise.
Variants§
Linear
Logarithmic
Skewed
Power-law taper over [min, max]: normalize(plain) = t^factor
where t is the linear proportion. factor < 1.0 gives the low
end of the range more of the knob (a log-like taper); factor > 1.0 gives the high end more; factor == 1.0 is Linear.
SymmetricalSkewed
Skew anchored at center, which sits at the knob’s midpoint with
each half a mirror of the other. The idiomatic shape for
center-detented knobs - pan (center = 0) and EQ gain
(center = 0 dB) - where the two directions should feel
symmetric regardless of where center falls in [min, max].
Discrete
Enum
Reversed(&'static ParamRange)
Wraps another range with its normalized axis flipped: the inner
range’s plain max sits at the bottom of the knob and min at
the top. Plain bounds and step count are the inner range’s.
Implementations§
Source§impl ParamRange
impl ParamRange
Sourcepub fn normalize(&self, plain: f64) -> f64
pub fn normalize(&self, plain: f64) -> f64
Map a plain value to 0.0–1.0.
Degenerate bounds - min == max for Linear / Discrete,
non-positive or empty for Logarithmic, count <= 1 for
Enum - collapse to 0.0. Combined with Self::denormalize
returning min on the same inputs, the pair is round-trip
stable: the result always converges to the bottom of the
(degenerate) range rather than producing NaN or wrapping into
nonsense.
Sourcepub fn denormalize(&self, normalized: f64) -> f64
pub fn denormalize(&self, normalized: f64) -> f64
Map 0.0–1.0 back to a plain value.
Degenerate bounds collapse to min (or 0.0 for Enum with
count <= 1). See Self::normalize for the round-trip
semantics.
Sourcepub fn step_count(&self) -> Option<NonZeroU32>
pub fn step_count(&self) -> Option<NonZeroU32>
Number of discrete steps for a quantized range.
None means continuous (Linear / Logarithmic). Some(n) means
the range covers n + 1 distinct values (a step count of 3 →
4 picker positions). Cross-format wrappers that serialize a
0 = continuous sentinel into a C struct should call
.map(NonZeroU32::get).unwrap_or(0) at the FFI boundary.
Discrete / Enum variants with degenerate bounds (min > max,
or count <= 1) return None - semantically continuous,
because there’s nothing to step through.
Sourcepub fn step_count_usize(&self) -> usize
pub fn step_count_usize(&self) -> usize
step_count widened to usize with the continuous case
flattened to 1. Convenience for UI code that loops over
discrete values and falls back to a single step for continuous
ranges.
Sourcepub fn base(&self) -> &Self
pub fn base(&self) -> &Self
The underlying range with any Self::Reversed wrapper peeled
off. Reversing only flips the axis direction; the base range
decides the parameter’s shape (a reversed enum is still an enum).
Match on this when classifying by shape - picking a widget, a taper
- so a reversed enum / toggle isn’t misread as a continuous knob.
Trait Implementations§
Source§impl Clone for ParamRange
impl Clone for ParamRange
Source§fn clone(&self) -> ParamRange
fn clone(&self) -> ParamRange
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more