pub enum ValueMapping {
Linear,
Logarithmic,
Custom {
to_normalized: Rc<dyn Fn(f32) -> f32>,
from_normalized: Rc<dyn Fn(f32) -> f32>,
},
}Expand description
How a slider maps its position to a value.
ValueMapping::Linear and ValueMapping::Logarithmic are the built-in
mappings. ValueMapping::Custom takes a pair of inverse functions when a
parameter follows its own curve.
The functions must be monotonic and inverse to each other. Inputs are
clamped to 0.0..=1.0 and min..=max, and a non-finite result falls back
to the low end.
Variants§
Linear
Values change uniformly across the slider range.
Logarithmic
The distance between values grows exponentially; min must be greater
than zero.
This is useful for parameters with a large range where smaller changes are more significant at lower values, such as volume, frequency, and zoom.
Moving the slider 1/3 of the way yields ~10, 2/3 yields ~100, and the full range covers three orders of magnitude evenly.
Custom
A caller-supplied pair of inverse mappings between a value and its fraction of the range.
Implementations§
Source§impl ValueMapping
impl ValueMapping
Sourcepub fn custom(
to_normalized: impl Fn(f32) -> f32 + 'static,
from_normalized: impl Fn(f32) -> f32 + 'static,
) -> Self
pub fn custom( to_normalized: impl Fn(f32) -> f32 + 'static, from_normalized: impl Fn(f32) -> f32 + 'static, ) -> Self
Creates a custom mapping from a pair of inverse functions.
to_normalized maps a value to its fraction of the range, and
from_normalized maps that fraction back to a value.
Sourcepub fn is_logarithmic(&self) -> bool
pub fn is_logarithmic(&self) -> bool
Whether this is the built-in logarithmic mapping.
Trait Implementations§
Source§impl Clone for ValueMapping
impl Clone for ValueMapping
Source§impl Default for ValueMapping
impl Default for ValueMapping
Source§impl From<SliderScale> for ValueMapping
impl From<SliderScale> for ValueMapping
Source§fn from(scale: SliderScale) -> Self
fn from(scale: SliderScale) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for ValueMapping
impl !Send for ValueMapping
impl !Sync for ValueMapping
impl !UnwindSafe for ValueMapping
impl Forget for ValueMapping
impl Freeze for ValueMapping
impl Move for ValueMapping
impl Unpin for ValueMapping
impl UnsafeUnpin for ValueMappingwhere
*const RcInner<dyn Fn(f32) -> f32> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(f32) -> f32>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().