Skip to main content

NumberInputState

Struct NumberInputState 

Source
pub struct NumberInputState { /* private fields */ }
Expand description

State for a NumberInput component.

Implementations§

Source§

impl NumberInputState

Source

pub fn new(value: f64) -> Self

Creates a new number input with the given initial value.

Defaults to step 1.0 and precision 0 (integer display).

§Example
use envision::component::NumberInputState;

let state = NumberInputState::new(42.0);
assert_eq!(state.value(), 42.0);
assert_eq!(state.format_value(), "42");
Source

pub fn integer(value: i64) -> Self

Creates a new number input configured for integer values.

Convenience constructor that sets precision to 0 and step to 1.0.

§Example
use envision::component::NumberInputState;

let state = NumberInputState::integer(42);
assert_eq!(state.value(), 42.0);
assert_eq!(state.format_value(), "42");
Source

pub fn with_min(self, min: f64) -> Self

Sets the minimum bound (builder pattern).

§Example
use envision::component::NumberInputState;

let state = NumberInputState::new(5.0).with_min(0.0);
Source

pub fn with_max(self, max: f64) -> Self

Sets the maximum bound (builder pattern).

§Example
use envision::component::NumberInputState;

let state = NumberInputState::new(5.0).with_max(10.0);
Source

pub fn with_range(self, min: f64, max: f64) -> Self

Sets both minimum and maximum bounds (builder pattern).

§Example
use envision::component::NumberInputState;

let state = NumberInputState::new(5.0).with_range(0.0, 10.0);
Source

pub fn with_step(self, step: f64) -> Self

Sets the step size (builder pattern).

§Example
use envision::component::NumberInputState;

let state = NumberInputState::new(0.0).with_step(0.5);
Source

pub fn with_precision(self, precision: usize) -> Self

Sets the decimal precision (builder pattern).

§Example
use envision::component::NumberInputState;

let state = NumberInputState::new(3.75).with_precision(2);
assert_eq!(state.format_value(), "3.75");
Source

pub fn with_label(self, label: impl Into<String>) -> Self

Sets the label (builder pattern).

§Example
use envision::component::NumberInputState;

let state = NumberInputState::new(0.0).with_label("Quantity");
assert_eq!(state.label(), Some("Quantity"));
Source

pub fn with_placeholder(self, placeholder: impl Into<String>) -> Self

Sets the placeholder text (builder pattern).

§Example
use envision::component::NumberInputState;

let state = NumberInputState::new(0.0).with_placeholder("Enter value...");
Source

pub fn value(&self) -> f64

Returns the current numeric value.

§Example
use envision::component::NumberInputState;

let state = NumberInputState::new(42.0);
assert_eq!(state.value(), 42.0);
Source

pub fn set_value(&mut self, value: f64)

Sets the current value, clamping to any configured bounds.

§Example
use envision::component::NumberInputState;

let mut state = NumberInputState::new(0.0).with_range(0.0, 100.0);
state.set_value(50.0);
assert_eq!(state.value(), 50.0);

state.set_value(200.0);
assert_eq!(state.value(), 100.0);
Source

pub fn is_editing(&self) -> bool

Returns true if the component is in text edit mode.

Source

pub fn edit_buffer(&self) -> &str

Returns the current edit buffer contents.

Source

pub fn label(&self) -> Option<&str>

Returns the label, if set.

Source

pub fn placeholder(&self) -> Option<&str>

Returns the placeholder, if set.

Source

pub fn set_placeholder(&mut self, placeholder: impl Into<String>)

Sets the placeholder text.

§Example
use envision::component::NumberInputState;

let mut state = NumberInputState::new(0.0);
state.set_placeholder("Enter a number...");
assert_eq!(state.placeholder(), Some("Enter a number..."));
Source

pub fn step(&self) -> f64

Returns the step size.

Source

pub fn precision(&self) -> usize

Returns the precision (decimal places).

Source

pub fn min(&self) -> Option<f64>

Returns the minimum bound, if set.

Source

pub fn max(&self) -> Option<f64>

Returns the maximum bound, if set.

Source

pub fn format_value(&self) -> String

Formats the current value according to the configured precision.

§Example
use envision::component::NumberInputState;

let state = NumberInputState::new(42.0);
assert_eq!(state.format_value(), "42");

let state = NumberInputState::new(3.75).with_precision(2);
assert_eq!(state.format_value(), "3.75");
Source

pub fn update(&mut self, msg: NumberInputMessage) -> Option<NumberInputOutput>

Updates the number input state with a message, returning any output.

§Example
use envision::component::{NumberInputMessage, NumberInputOutput, NumberInputState};

let mut state = NumberInputState::new(10.0);
let output = state.update(NumberInputMessage::Increment);
assert_eq!(output, Some(NumberInputOutput::ValueChanged(11.0)));
assert_eq!(state.value(), 11.0);

Trait Implementations§

Source§

impl Clone for NumberInputState

Source§

fn clone(&self) -> NumberInputState

Returns a duplicate 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 NumberInputState

Source§

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

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

impl Default for NumberInputState

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for NumberInputState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for NumberInputState

Source§

fn eq(&self, other: &NumberInputState) -> 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 Serialize for NumberInputState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for NumberInputState

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> StateExt for T

Source§

fn updated(self, cmd: Command<impl Clone>) -> UpdateResult<Self, impl Clone>

Updates self and returns a command.
Source§

fn unchanged(self) -> UpdateResult<Self, ()>

Returns self with no command.
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,