Skip to main content

Module slider_math

Module slider_math 

Source
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§

SliderSpec
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 x into [min, max], tolerating a reversed (high-to-low) range and NaN endpoints the same way egui’s clamp_value_to_range does.
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.