pub struct NumberInput { /* private fields */ }Expand description
A number field with a step grid and, optionally, a range.
It never clamps. A value outside the range stays on screen exactly as it is
and is published invalid, because silently correcting a number nobody
chose hides the disagreement instead of reporting it.
Implementations§
Source§impl NumberInput
impl NumberInput
pub fn new( ident: impl Into<Ident>, window: &mut Window, cx: &mut Context<'_, Self>, ) -> Self
Sourcepub fn value(self, value: f64) -> Self
pub fn value(self, value: f64) -> Self
Seeds the number the control draws. The caller keeps owning it.
pub fn range(self, min: f64, max: f64) -> Self
pub fn min(self, min: f64) -> Self
pub fn max(self, max: f64) -> Self
Sourcepub fn name(self, name: impl Into<SharedString>) -> Self
pub fn name(self, name: impl Into<SharedString>) -> Self
Names the control for a reader. A number field is usually labelled by the form around it, and the name is passed to the field that actually takes the keystrokes so a reader landing there knows what it is.
Sourcepub fn page_step(self, page_step: f64) -> Self
pub fn page_step(self, page_step: f64) -> Self
How far page-up and page-down move. Ten steps unless told otherwise.
Sourcepub fn precision(self, precision: usize) -> Self
pub fn precision(self, precision: usize) -> Self
How many decimals the field draws and reports.
Sourcepub fn unit(self, unit: impl Into<SharedString>) -> Self
pub fn unit(self, unit: impl Into<SharedString>) -> Self
What the number counts, such as "ms". Shown after the field and
carried in the published value.
pub fn required(self, required: bool) -> Self
Sourcepub fn set_value(&mut self, value: f64, cx: &mut Context<'_, Self>)
pub fn set_value(&mut self, value: f64, cx: &mut Context<'_, Self>)
Replaces the number from the host side.
The host already knows the number it just set, so this reports nothing; only what a typist asks for is reported.
pub fn set_disabled(&mut self, disabled: bool, cx: &mut Context<'_, Self>)
Sourcepub fn current(&self) -> Option<f64>
pub fn current(&self) -> Option<f64>
The number the control last held, or None when nobody has given it
one and nobody has typed one.
pub fn field(&self) -> &Entity<TextInput>
Sourcepub fn shown(&self, cx: &App) -> Option<f64>
pub fn shown(&self, cx: &App) -> Option<f64>
The number in the field, which is the typist’s text rather than the host’s value while an edit is in progress.
Sourcepub fn is_invalid(&self, cx: &App) -> bool
pub fn is_invalid(&self, cx: &App) -> bool
Whether what the field holds is something the control was told to accept. An empty field holds no number and says nothing about one.
Sourcepub fn invalid_reason(&self, cx: &App) -> Option<SharedString>
pub fn invalid_reason(&self, cx: &App) -> Option<SharedString>
Why the field is invalid, in words, or None when it is not. This and
Self::is_invalid read the same range, so a control cannot be drawn
as wrong without being able to say what is wrong with it.
Trait Implementations§
Source§impl Debug for NumberInput
impl Debug for NumberInput
Source§impl Disableable for NumberInput
impl Disableable for NumberInput
impl EventEmitter<NumberInputEvent> for NumberInput
Source§impl Focusable for NumberInput
impl Focusable for NumberInput
Source§fn focus_handle(&self, _cx: &App) -> FocusHandle
fn focus_handle(&self, _cx: &App) -> FocusHandle
Source§impl Render for NumberInput
impl Render for NumberInput
Auto Trait Implementations§
impl !RefUnwindSafe for NumberInput
impl !Send for NumberInput
impl !Sync for NumberInput
impl !UnwindSafe for NumberInput
impl Freeze for NumberInput
impl Unpin for NumberInput
impl UnsafeUnpin for NumberInput
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
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