OtpField
A bounded one-time-code editor made from individually styled input cells.
Loading interactive demo…
let field = OtpField::new("code");
field.root().flex_row().gap(8.0)#Import
Import OtpField from quickgui.
use quickgui::*;#Usage
let field = OtpField::new("code");
field.root().flex_row().gap(8.0)#Anatomy
OtpField::rootOtpField::inputOtpField::separator
#API reference
Expand an entry for its description and complete signature. A dash means no declaration default is documented.
OtpField
View sourcepub fn new(root_id: impl Into<ElementId>) -> Selfauto_submitpub fn auto_submit(mut self, form: impl Into<ElementId>) -> Self—
Submit the named form as soon as the final slot is filled. QuickGUI routes the request through [`crate::EventContext::submit_form`], so the form is validated exactly as a Return press or a submit button would validate it. Pass the id of the nearest mounted [`crate::form`] ancestor.
pub fn auto_submit(mut self, form: impl Into<ElementId>) -> SelfView sourceroot_idpub const fn root_id(self) -> ElementId—
submitted_formpub const fn submitted_form(self) -> Option<ElementId>—
Configures submitted form for this part.
pub const fn submitted_form(self) -> Option<ElementId>View sourceinput_idpub fn input_id(self, index: usize) -> ElementId—
separator_idpub fn separator_id(self, index: usize) -> ElementId—
Configures separator id for this part.
pub fn separator_id(self, index: usize) -> ElementIdView sourceOtpField::root_with
View sourcepub fn root_with(self, state: &OtpFieldState, root: Element) -> ElementDecorate an application-owned root without adding layout or appearance. The root is the group that names the whole code and carries its validity, so assistive technology announces one field rather than a row of unrelated one-character inputs.
OtpField::root
View sourcepub fn root(self, state: &OtpFieldState) -> ElementCreate the unstyled root part. Use [`Self::root_with`] to supply an existing element.
OtpField::input_with
View sourcepub fn input_with(self, state: &OtpFieldState, index: usize, input: Element) -> ElementDecorate one application-owned slot input without adding appearance. Pass a [`crate::text_input`] built from [`OtpFieldState::slot_text`]. QuickGUI adds the stable identity, the slot's position in the code, the masked presentation, and the required and disabled policy. Use [`Self::slot_with`] to attach the behavior as well.
OtpField::input
View sourcepub fn input(self, state: &OtpFieldState, index: usize) -> ElementCreate the unstyled input part. Use [`Self::input_with`] to supply an existing element.
OtpField::separator_with
View sourcepub fn separator_with(self, index: usize, separator: Element) -> ElementDecorate an application-owned separator between two slots. The separator is decorative: it carries a stable identity and the Separator role, and is hidden from assistive technology so it never interrupts the announced code.
OtpField::separator
View sourcepub fn separator(self, index: usize) -> ElementCreate the unstyled separator part. Use [`Self::separator_with`] to supply an existing element.
OtpField::slot_with
View sourcepub fn slot_with<V: 'static, Change, Complete>( self, cx: &mut ViewContext<'_, V>, state: &OtpFieldState, index: usize, input: Element, access: fn(&mut V) -> &mut OtpFieldState, on_value_change: Change, on_complete: Complete, ) -> Element where Change: Fn(&mut V, &str, &mut EventContext) + Clone + 'static, Complete: Fn(&mut V, &str, &mut EventContext) + Clone + 'static,Decorate one slot and attach its complete behavior. This registers the slot's input listener and its typed keyboard actions. Install [`otp_field_key_bindings`] once on the application keymap. `on_value_change` runs for every change with the whole code; `on_complete` runs only on the transition into a full code, and is followed by [`Self::auto_submit`] when one is declared.
OtpField::slot
View sourcepub fn slot<V: 'static, Change, Complete>( self, cx: &mut ViewContext<'_, V>, state: &OtpFieldState, index: usize, access: fn(&mut V) -> &mut OtpFieldState, on_value_change: Change, on_complete: Complete, ) -> Element where Change: Fn(&mut V, &str, &mut EventContext) + Clone + 'static, Complete: Fn(&mut V, &str, &mut EventContext) + Clone + 'static,Create the unstyled slot part. Use [`Self::slot_with`] to supply an existing element.
OtpField::slot_with_accessor
View sourcepub fn slot_with_accessor<V: 'static, Change, Complete>( self, cx: &mut ViewContext<'_, V>, state: &OtpFieldState, index: usize, input: Element, access: StateAccessor<V, OtpFieldState>, on_value_change: Change, on_complete: Complete, ) -> Element where Change: Fn(&mut V, &str, &mut EventContext) + Clone + 'static, Complete: Fn(&mut V, &str, &mut EventContext) + Clone + 'static,Decorate one slot and attach its behavior against a per-instance state accessor.
