OtpField
個別にスタイルできる入力セルで構成された、長さ制限付きのワンタイムコードエディターです。
デモを読み込み中…
let field = OtpField::new("code");
field.root().flex_row().gap(8.0)#インポート
quickgui から OtpField をインポートします。
use quickgui::*;#使い方
let field = OtpField::new("code");
field.root().flex_row().gap(8.0)#構成
OtpField::rootOtpField::inputOtpField::separator
#API リファレンス
項目を展開すると説明と完全なシグネチャが表示されます。ダッシュは宣言に既定値が記載されていないことを示します。
OtpField
ソースを見るpub 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>) -> Selfソースを見るroot_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>ソースを見るinput_idpub fn input_id(self, index: usize) -> ElementId—
separator_idpub fn separator_id(self, index: usize) -> ElementId—
OtpField::root_with
ソースを見るpub 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
ソースを見るpub fn root(self, state: &OtpFieldState) -> ElementCreate the unstyled root part. Use [`Self::root_with`] to supply an existing element.
OtpField::input_with
ソースを見るpub 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
ソースを見るpub fn input(self, state: &OtpFieldState, index: usize) -> ElementCreate the unstyled input part. Use [`Self::input_with`] to supply an existing element.
OtpField::separator_with
ソースを見るpub 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
ソースを見るpub fn separator(self, index: usize) -> ElementCreate the unstyled separator part. Use [`Self::separator_with`] to supply an existing element.
OtpField::slot_with
ソースを見るpub 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
ソースを見るpub 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
ソースを見るpub 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.
