Expand description
Pure value-mapping math for crate::widgets::slider::Slider.
This module holds the numeric core of the slider — everything that turns a
value into a normalized [0, 1] position and back — kept separate from the
widget’s paint/event code so the mapping can be unit-tested in isolation and
so slider.rs stays under the project’s 800-line limit.
The logarithmic mapping (including ranges that span zero and infinity) and
the “smart aim” round-number finder are ported from egui’s
crates/egui/src/widgets/slider.rs and crates/emath/src/smart_aim.rs
respectively (see egui-reference/). Semantics are preserved so the
widget behaves like egui’s; only the API shape (scalar min/max instead
of RangeInclusive) differs to avoid dragging range types through the
widget.
Structs§
- Slider
Spec - Configuration for how a slider maps values to positions.
Functions§
- best_
in_ range_ f64 - Find the “simplest” number in the closed range
[min, max]— the one with the fewest decimal digits. E.g.[0.83, 1.354] -> 1.0,[0.37, 0.48] -> 0.4. - clamp_
value_ to_ range - Clamp
xinto[min, max], tolerating a reversed (high-to-low) range and NaN endpoints the same way egui’sclamp_value_to_rangedoes. - normalized_
from_ value - Map a value to its normalized
[0, 1]slider position. - value_
from_ normalized - Inverse of
normalized_from_value: map a normalized[0, 1]position back to a value.