#[non_exhaustive]pub struct NumberSpec {
pub min: Option<f64>,
pub max: Option<f64>,
pub step: f64,
pub decimals: Option<u32>,
}Expand description
The rules of a number field (number_input): range, step, shown decimals. The
value stays text while it is typed (-, 1. and an empty field are fine); the app
reads it with NumberSpec::parse, the steppers and the arrow keys go through
NumberSpec::stepped, and leaving the field tidies it with
NumberSpec::normalized (uzor-framework’s kit::dom does all three).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.min: Option<f64>Smallest value (inclusive).
max: Option<f64>Largest value (inclusive).
step: f64One stepper / arrow-key step.
decimals: Option<u32>Decimals shown after a step or on leaving the field (None: as many as needed).
Implementations§
Source§impl NumberSpec
impl NumberSpec
Sourcepub fn new() -> NumberSpec
pub fn new() -> NumberSpec
Any number, step 1.
Sourcepub fn integer() -> NumberSpec
pub fn integer() -> NumberSpec
Whole numbers only (no decimal point is typed), step 1.
Sourcepub fn range(self, min: f64, max: f64) -> NumberSpec
pub fn range(self, min: f64, max: f64) -> NumberSpec
The range min..=max.
Sourcepub fn min(self, v: f64) -> NumberSpec
pub fn min(self, v: f64) -> NumberSpec
The smallest value.
Sourcepub fn max(self, v: f64) -> NumberSpec
pub fn max(self, v: f64) -> NumberSpec
The largest value.
Sourcepub fn step(self, v: f64) -> NumberSpec
pub fn step(self, v: f64) -> NumberSpec
One step.
Sourcepub fn decimals(self, n: u32) -> NumberSpec
pub fn decimals(self, n: u32) -> NumberSpec
Decimals shown.
Sourcepub fn accepts(&self, c: char) -> bool
pub fn accepts(&self, c: char) -> bool
Whether c may be typed: digits, a sign, a decimal point (. or ,) unless whole
numbers only, and an exponent.
Sourcepub fn sanitize(&self, text: &str) -> String
pub fn sanitize(&self, text: &str) -> String
text with what may not be typed taken out (a paste of "1 234,5 $" → "1234,5").
Sourcepub fn parse(&self, text: &str) -> Option<f64>
pub fn parse(&self, text: &str) -> Option<f64>
The value text holds, inside the range; None while it is not a number yet.
A decimal comma reads as a point.
Sourcepub fn format(&self, v: f64) -> String
pub fn format(&self, v: f64) -> String
v as text: with NumberSpec::decimals places, else as short as it reads.
Sourcepub fn stepped(&self, text: &str, n: i32) -> String
pub fn stepped(&self, text: &str, n: i32) -> String
The text after n steps from text (an unreadable text steps from the range’s
start, or 0), snapped to the step grid and clamped.
Sourcepub fn normalized(&self, text: &str) -> String
pub fn normalized(&self, text: &str) -> String
The text tidied on leaving the field: the clamped value formatted, or the text unchanged when it is not a number (empty stays empty).
Trait Implementations§
Source§impl Clone for NumberSpec
impl Clone for NumberSpec
Source§fn clone(&self) -> NumberSpec
fn clone(&self) -> NumberSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more