pub struct ProgressSpec {
pub min: f32,
pub max: f32,
}Expand description
Numeric domain used by determinate progress indicators.
§Examples
use ailloli_ui_core::ProgressSpec;
let progress = ProgressSpec::new(0.0, 10.0);
assert_eq!(progress.fraction_for_value(5.0), 0.5);Fields§
§min: f32Inclusive value represented by an empty indicator.
max: f32Inclusive value represented by a full indicator.
Implementations§
Source§impl ProgressSpec
impl ProgressSpec
Sourcepub fn new(min: f32, max: f32) -> Self
pub fn new(min: f32, max: f32) -> Self
Creates an ascending progress domain with finite input bounds.
Reversed bounds are swapped, equal bounds are expanded upward by adding
1.0 to the maximum, and any non-finite input bound resets the whole
range to 0.0..=1.0. At magnitudes where that increment is not
representable, equal bounds can remain equal.
§Examples
use ailloli_ui_core::ProgressSpec;
assert_eq!(ProgressSpec::new(10.0, 0.0), ProgressSpec { min: 0.0, max: 10.0 });Sourcepub fn span(self) -> f32
pub fn span(self) -> f32
Returns max - min for the sanitized domain.
The result is normally positive and finite. It can be zero when two
large equal bounds cannot be widened by 1.0, or infinity when the
difference between finite extreme bounds overflows.
§Examples
use ailloli_ui_core::ProgressSpec;
assert_eq!(ProgressSpec::new(10.0, 30.0).span(), 20.0);Sourcepub fn clamp_value(self, value: f32) -> f32
pub fn clamp_value(self, value: f32) -> f32
Clamps a value into the inclusive sanitized domain.
A non-finite value selects the minimum.
§Examples
use ailloli_ui_core::ProgressSpec;
assert_eq!(ProgressSpec::new(10.0, 20.0).clamp_value(25.0), 20.0);Sourcepub fn fraction_for_value(self, value: f32) -> f32
pub fn fraction_for_value(self, value: f32) -> f32
Maps a value into 0.0..=1.0, clamping values outside the domain.
A zero or overflowing span caused by extreme finite bounds can make the
IEEE-754 division return NaN.
§Examples
use ailloli_ui_core::ProgressSpec;
assert_eq!(ProgressSpec::new(10.0, 30.0).fraction_for_value(20.0), 0.5);Sourcepub fn value_for_fraction(self, fraction: f32) -> f32
pub fn value_for_fraction(self, fraction: f32) -> f32
Maps a normalized fraction back into the progress domain.
Fractions outside 0.0..=1.0 are clamped and non-finite fractions
select the minimum. An overflowing span between extreme finite bounds
can make the returned value non-finite.
§Examples
use ailloli_ui_core::ProgressSpec;
assert_eq!(ProgressSpec::new(10.0, 30.0).value_for_fraction(0.75), 25.0);Trait Implementations§
Source§impl Clone for ProgressSpec
impl Clone for ProgressSpec
Source§fn clone(&self) -> ProgressSpec
fn clone(&self) -> ProgressSpec
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more