Skip to main content

NumberInputState

Struct NumberInputState 

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

Retained state for a Material 3 NumberInput.

Owns the inner TextFieldState, numeric bounds, step size, and optional fixed decimal precision. Subscribe to NumberInputEvent to react to edits and steps.

Implementations§

Source§

impl NumberInputState

Source

pub fn new( window: &mut Window, cx: &mut Context<'_, NumberInputState>, ) -> NumberInputState

Creates an empty numeric input state with a default step of 1.0.

Source

pub fn default_value( self, value: f64, window: &mut Window, cx: &mut Context<'_, NumberInputState>, ) -> NumberInputState

Sets the initial numeric value during state construction.

Source

pub fn min(self, min: f64) -> NumberInputState

Sets the inclusive lower bound during construction. Non-finite values are ignored.

Source

pub fn max(self, max: f64) -> NumberInputState

Sets the inclusive upper bound during construction. Non-finite values are ignored.

Source

pub fn bounds(self, min: f64, max: f64) -> NumberInputState

Sets inclusive lower and upper bounds during construction.

If min > max, the bounds are swapped so min <= max.

Source

pub fn step(self, step: f64) -> NumberInputState

Sets the step increment used by buttons and Up/Down keys. Non-finite or non-positive steps are ignored.

Source

pub fn precision(self, digits: usize) -> NumberInputState

Fixes the number of decimal digits formatted after stepping or calling Self::set_value.

Source

pub fn set_min( &mut self, min: Option<f64>, cx: &mut Context<'_, NumberInputState>, )

Updates the inclusive lower bound.

Source

pub fn set_max( &mut self, max: Option<f64>, cx: &mut Context<'_, NumberInputState>, )

Updates the inclusive upper bound.

Source

pub fn set_step(&mut self, step: f64, cx: &mut Context<'_, NumberInputState>)

Updates the step size. Non-finite or non-positive values are ignored.

Source

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

Returns the configured lower bound, if any.

Source

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

Returns the configured upper bound, if any.

Source

pub fn step_value(&self) -> f64

Returns the configured step size.

Source

pub fn value(&self, cx: &App) -> Option<f64>

Returns the current parsed numeric value, or None when empty or incomplete.

Source

pub fn text(&self, cx: &App) -> SharedString

Returns the current formatted text in the editor.

Source

pub fn set_value( &mut self, value: f64, window: &mut Window, cx: &mut Context<'_, NumberInputState>, )

Replaces the numeric value, clamping to configured bounds without emitting NumberInputEvent::Change.

Source

pub fn set_text( &mut self, text: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, NumberInputState>, )

Replaces the raw editor text without emitting NumberInputEvent::Change.

Source

pub fn is_disabled(&self, cx: &App) -> bool

Returns whether the editor is disabled.

Source

pub fn set_disabled( &mut self, disabled: bool, cx: &mut Context<'_, NumberInputState>, )

Sets whether the editor is disabled.

Source

pub fn is_readonly(&self, cx: &App) -> bool

Returns whether the editor is read-only.

Source

pub fn set_readonly( &mut self, readonly: bool, cx: &mut Context<'_, NumberInputState>, )

Sets whether the editor is read-only.

Source

pub fn can_increment(&self, cx: &App) -> bool

Returns whether stepping upward is currently permitted.

Source

pub fn can_decrement(&self, cx: &App) -> bool

Returns whether stepping downward is currently permitted.

Source

pub fn step_by( &mut self, action: NumberStepAction, window: &mut Window, cx: &mut Context<'_, NumberInputState>, ) -> bool

Steps the current value in action direction, clamping to configured bounds.

Returns true when the value changed.

Source

pub fn increment( &mut self, window: &mut Window, cx: &mut Context<'_, NumberInputState>, ) -> bool

Increments the numeric value by one step.

Source

pub fn decrement( &mut self, window: &mut Window, cx: &mut Context<'_, NumberInputState>, ) -> bool

Decrements the numeric value by one step.

Source

pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, NumberInputState>)

Moves keyboard focus to the inner numeric text editor.

Source

pub fn editor(&self) -> &Entity<InputBaseState<InputMode>>

Returns the underlying retained TextFieldState editor entity.

Trait Implementations§

Source§

impl EventEmitter<NumberInputEvent> for NumberInputState

Source§

impl Focusable for NumberInputState

Source§

fn focus_handle(&self, cx: &App) -> FocusHandle

Returns the focus handle associated with this view.
Source§

impl Render for NumberInputState

Source§

fn render( &mut self, _: &mut Window, _: &mut Context<'_, NumberInputState>, ) -> impl IntoElement

Render this view into an element tree.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more