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
impl NumberInputState
Sourcepub fn new(
window: &mut Window,
cx: &mut Context<'_, NumberInputState>,
) -> NumberInputState
pub fn new( window: &mut Window, cx: &mut Context<'_, NumberInputState>, ) -> NumberInputState
Creates an empty numeric input state with a default step of 1.0.
Sourcepub fn default_value(
self,
value: f64,
window: &mut Window,
cx: &mut Context<'_, NumberInputState>,
) -> NumberInputState
pub fn default_value( self, value: f64, window: &mut Window, cx: &mut Context<'_, NumberInputState>, ) -> NumberInputState
Sets the initial numeric value during state construction.
Sourcepub fn min(self, min: f64) -> NumberInputState
pub fn min(self, min: f64) -> NumberInputState
Sets the inclusive lower bound during construction. Non-finite values are ignored.
Sourcepub fn max(self, max: f64) -> NumberInputState
pub fn max(self, max: f64) -> NumberInputState
Sets the inclusive upper bound during construction. Non-finite values are ignored.
Sourcepub fn bounds(self, min: f64, max: f64) -> NumberInputState
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.
Sourcepub fn step(self, step: f64) -> NumberInputState
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.
Sourcepub fn precision(self, digits: usize) -> NumberInputState
pub fn precision(self, digits: usize) -> NumberInputState
Fixes the number of decimal digits formatted after stepping or calling Self::set_value.
Sourcepub fn set_min(
&mut self,
min: Option<f64>,
cx: &mut Context<'_, NumberInputState>,
)
pub fn set_min( &mut self, min: Option<f64>, cx: &mut Context<'_, NumberInputState>, )
Updates the inclusive lower bound.
Sourcepub fn set_max(
&mut self,
max: Option<f64>,
cx: &mut Context<'_, NumberInputState>,
)
pub fn set_max( &mut self, max: Option<f64>, cx: &mut Context<'_, NumberInputState>, )
Updates the inclusive upper bound.
Sourcepub fn set_step(&mut self, step: f64, cx: &mut Context<'_, NumberInputState>)
pub fn set_step(&mut self, step: f64, cx: &mut Context<'_, NumberInputState>)
Updates the step size. Non-finite or non-positive values are ignored.
Sourcepub fn step_value(&self) -> f64
pub fn step_value(&self) -> f64
Returns the configured step size.
Sourcepub fn value(&self, cx: &App) -> Option<f64>
pub fn value(&self, cx: &App) -> Option<f64>
Returns the current parsed numeric value, or None when empty or incomplete.
Sourcepub fn text(&self, cx: &App) -> SharedString
pub fn text(&self, cx: &App) -> SharedString
Returns the current formatted text in the editor.
Sourcepub fn set_value(
&mut self,
value: f64,
window: &mut Window,
cx: &mut Context<'_, NumberInputState>,
)
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.
Sourcepub fn set_text(
&mut self,
text: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, NumberInputState>,
)
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.
Sourcepub fn is_disabled(&self, cx: &App) -> bool
pub fn is_disabled(&self, cx: &App) -> bool
Returns whether the editor is disabled.
Sourcepub fn set_disabled(
&mut self,
disabled: bool,
cx: &mut Context<'_, NumberInputState>,
)
pub fn set_disabled( &mut self, disabled: bool, cx: &mut Context<'_, NumberInputState>, )
Sets whether the editor is disabled.
Sourcepub fn is_readonly(&self, cx: &App) -> bool
pub fn is_readonly(&self, cx: &App) -> bool
Returns whether the editor is read-only.
Sourcepub fn set_readonly(
&mut self,
readonly: bool,
cx: &mut Context<'_, NumberInputState>,
)
pub fn set_readonly( &mut self, readonly: bool, cx: &mut Context<'_, NumberInputState>, )
Sets whether the editor is read-only.
Sourcepub fn can_increment(&self, cx: &App) -> bool
pub fn can_increment(&self, cx: &App) -> bool
Returns whether stepping upward is currently permitted.
Sourcepub fn can_decrement(&self, cx: &App) -> bool
pub fn can_decrement(&self, cx: &App) -> bool
Returns whether stepping downward is currently permitted.
Sourcepub fn step_by(
&mut self,
action: NumberStepAction,
window: &mut Window,
cx: &mut Context<'_, NumberInputState>,
) -> bool
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.
Sourcepub fn increment(
&mut self,
window: &mut Window,
cx: &mut Context<'_, NumberInputState>,
) -> bool
pub fn increment( &mut self, window: &mut Window, cx: &mut Context<'_, NumberInputState>, ) -> bool
Increments the numeric value by one step.
Sourcepub fn decrement(
&mut self,
window: &mut Window,
cx: &mut Context<'_, NumberInputState>,
) -> bool
pub fn decrement( &mut self, window: &mut Window, cx: &mut Context<'_, NumberInputState>, ) -> bool
Decrements the numeric value by one step.
Sourcepub fn focus(&self, window: &mut Window, cx: &mut Context<'_, NumberInputState>)
pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, NumberInputState>)
Moves keyboard focus to the inner numeric text editor.
Sourcepub fn editor(&self) -> &Entity<InputBaseState<InputMode>>
pub fn editor(&self) -> &Entity<InputBaseState<InputMode>>
Returns the underlying retained TextFieldState editor entity.
Trait Implementations§
impl EventEmitter<NumberInputEvent> for NumberInputState
Source§impl Focusable for NumberInputState
impl Focusable for NumberInputState
Source§fn focus_handle(&self, cx: &App) -> FocusHandle
fn focus_handle(&self, cx: &App) -> FocusHandle
Source§impl Render for NumberInputState
impl Render for NumberInputState
Source§fn render(
&mut self,
_: &mut Window,
_: &mut Context<'_, NumberInputState>,
) -> impl IntoElement
fn render( &mut self, _: &mut Window, _: &mut Context<'_, NumberInputState>, ) -> impl IntoElement
Auto Trait Implementations§
impl !RefUnwindSafe for NumberInputState
impl !Send for NumberInputState
impl !Sync for NumberInputState
impl !UnwindSafe for NumberInputState
impl Forget for NumberInputState
impl Freeze for NumberInputStatewhere
NonZero<u32>: Freeze,
*const (): Freeze,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: Freeze,
PhantomData<fn(InputBaseState<InputMode>) -> InputBaseState<InputMode>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Subscription>: Freeze,
impl Move for NumberInputState
impl Unpin for NumberInputState
impl UnsafeUnpin for NumberInputStatewhere
NonZeroU32Inner: UnsafeUnpin,
*const (): UnsafeUnpin,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: UnsafeUnpin,
PhantomData<fn(InputBaseState<InputMode>) -> InputBaseState<InputMode>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Subscription>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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