pub struct OtpInputState { /* private fields */ }Expand description
Retained state for a Material 3 segmented OtpInput.
Wraps the underlying base OTP focus/blinking state while adding slot-cursor
navigation (Left, Right, Home, End), in-place slot replacement, Delete,
and clipboard paste (Ctrl/Cmd+V).
Implementations§
Source§impl OtpInputState
impl OtpInputState
Sourcepub fn new(
length: usize,
window: &mut Window,
cx: &mut Context<'_, OtpInputState>,
) -> OtpInputState
pub fn new( length: usize, window: &mut Window, cx: &mut Context<'_, OtpInputState>, ) -> OtpInputState
Creates a new OTP state with length digit slots (minimum 1).
Sourcepub fn default_value(
self,
value: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, OtpInputState>,
) -> OtpInputState
pub fn default_value( self, value: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, OtpInputState>, ) -> OtpInputState
Sets an initial digit value during construction (non-digits are stripped and truncated to length).
Sourcepub fn masked(
self,
masked: bool,
window: &mut Window,
cx: &mut Context<'_, OtpInputState>,
) -> OtpInputState
pub fn masked( self, masked: bool, window: &mut Window, cx: &mut Context<'_, OtpInputState>, ) -> OtpInputState
Enables or disables masked bullet display during construction.
Sourcepub fn value(&self, cx: &App) -> SharedString
pub fn value(&self, cx: &App) -> SharedString
Returns the current entered digits.
Sourcepub fn is_complete(&self, cx: &App) -> bool
pub fn is_complete(&self, cx: &App) -> bool
Returns whether all slots contain a digit.
Sourcepub fn active_slot(&self) -> usize
pub fn active_slot(&self) -> usize
Returns the currently targeted slot index (0..length()).
Sourcepub fn set_masked(
&mut self,
masked: bool,
window: &mut Window,
cx: &mut Context<'_, OtpInputState>,
)
pub fn set_masked( &mut self, masked: bool, window: &mut Window, cx: &mut Context<'_, OtpInputState>, )
Sets whether digits are masked with bullets.
Sourcepub fn set_value(
&mut self,
value: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, OtpInputState>,
)
pub fn set_value( &mut self, value: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, OtpInputState>, )
Replaces the entered digits programmatically without emitting OtpInputEvent::Change.
Sourcepub fn clear(
&mut self,
window: &mut Window,
cx: &mut Context<'_, OtpInputState>,
)
pub fn clear( &mut self, window: &mut Window, cx: &mut Context<'_, OtpInputState>, )
Clears all entered digits without emitting OtpInputEvent::Change.
Sourcepub fn set_active_slot(
&mut self,
index: usize,
cx: &mut Context<'_, OtpInputState>,
)
pub fn set_active_slot( &mut self, index: usize, cx: &mut Context<'_, OtpInputState>, )
Moves the active slot index, clamped to the reachable slot range.
Sourcepub fn paste(
&mut self,
text: &str,
window: &mut Window,
cx: &mut Context<'_, OtpInputState>,
) -> bool
pub fn paste( &mut self, text: &str, window: &mut Window, cx: &mut Context<'_, OtpInputState>, ) -> bool
Pastes digits extracted from text starting at the active slot (or replacing
the whole code when text contains at least length() digits).
Returns true if the value changed.
Sourcepub fn focus(&self, window: &mut Window, cx: &mut Context<'_, OtpInputState>)
pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, OtpInputState>)
Focuses the OTP input.
Trait Implementations§
impl EventEmitter<OtpInputEvent> for OtpInputState
Source§impl Focusable for OtpInputState
impl Focusable for OtpInputState
Source§fn focus_handle(&self, cx: &App) -> FocusHandle
fn focus_handle(&self, cx: &App) -> FocusHandle
Source§impl Render for OtpInputState
impl Render for OtpInputState
Source§fn render(
&mut self,
_: &mut Window,
_: &mut Context<'_, OtpInputState>,
) -> impl IntoElement
fn render( &mut self, _: &mut Window, _: &mut Context<'_, OtpInputState>, ) -> impl IntoElement
Auto Trait Implementations§
impl !RefUnwindSafe for OtpInputState
impl !Send for OtpInputState
impl !Sync for OtpInputState
impl !UnwindSafe for OtpInputState
impl Forget for OtpInputState
impl Freeze for OtpInputState
impl Move for OtpInputState
impl Unpin for OtpInputState
impl UnsafeUnpin for OtpInputStatewhere
NonZeroU32Inner: UnsafeUnpin,
*const (): UnsafeUnpin,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: UnsafeUnpin,
PhantomData<fn(OtpState) -> OtpState>: 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