Struct ProgressSpec

Source
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: f32

Inclusive value represented by an empty indicator.

§max: f32

Inclusive value represented by a full indicator.

Implementations§

Source§

impl ProgressSpec

Source

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 });
Source

pub fn sanitized(self) -> Self

Returns this specification normalized according to Self::new.

§Examples
use ailloli_ui_core::ProgressSpec;

let spec = ProgressSpec { min: 5.0, max: 5.0 }.sanitized();
assert_eq!(spec.max, 6.0);
Source

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);
Source

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);
Source

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);
Source

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

Source§

fn clone(&self) -> ProgressSpec

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProgressSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProgressSpec

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for ProgressSpec

Source§

fn eq(&self, other: &ProgressSpec) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ProgressSpec

Source§

impl StructuralPartialEq for ProgressSpec

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.