pub struct NumberInputState { /* private fields */ }Expand description
State for a NumberInput component.
Implementations§
Source§impl NumberInputState
impl NumberInputState
Sourcepub fn new(value: f64) -> Self
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");Sourcepub fn integer(value: i64) -> Self
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");Sourcepub fn with_min(self, min: f64) -> Self
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);Sourcepub fn with_max(self, max: f64) -> Self
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);Sourcepub fn with_range(self, min: f64, max: f64) -> Self
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);Sourcepub fn with_step(self, step: f64) -> Self
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);Sourcepub fn with_precision(self, precision: usize) -> Self
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");Sourcepub fn with_label(self, label: impl Into<String>) -> Self
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"));Sourcepub fn with_placeholder(self, placeholder: impl Into<String>) -> Self
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...");Sourcepub fn value(&self) -> f64
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);Sourcepub fn set_value(&mut self, value: f64)
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);Sourcepub fn is_editing(&self) -> bool
pub fn is_editing(&self) -> bool
Returns true if the component is in text edit mode.
Sourcepub fn edit_buffer(&self) -> &str
pub fn edit_buffer(&self) -> &str
Returns the current edit buffer contents.
Sourcepub fn placeholder(&self) -> Option<&str>
pub fn placeholder(&self) -> Option<&str>
Returns the placeholder, if set.
Sourcepub fn set_placeholder(&mut self, placeholder: impl Into<String>)
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..."));Sourcepub fn format_value(&self) -> String
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");Sourcepub fn update(&mut self, msg: NumberInputMessage) -> Option<NumberInputOutput>
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
impl Clone for NumberInputState
Source§fn clone(&self) -> NumberInputState
fn clone(&self) -> NumberInputState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NumberInputState
impl Debug for NumberInputState
Source§impl Default for NumberInputState
impl Default for NumberInputState
Source§impl<'de> Deserialize<'de> for NumberInputState
impl<'de> Deserialize<'de> for NumberInputState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for NumberInputState
impl PartialEq for NumberInputState
Source§impl Serialize for NumberInputState
impl Serialize for NumberInputState
impl StructuralPartialEq for NumberInputState
Auto Trait Implementations§
impl Freeze for NumberInputState
impl RefUnwindSafe for NumberInputState
impl Send for NumberInputState
impl Sync for NumberInputState
impl Unpin for NumberInputState
impl UnsafeUnpin for NumberInputState
impl UnwindSafe for NumberInputState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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