pub struct Binding<T: 'static> {
pub read: ReadSignal<T>,
/* private fields */
}Expand description
A reactive, two-way binding to one field-shaped value.
§Interaction boundaries
Binding::commit and Binding::focus_exit report independent facts:
- Commit is the widget-defined end of one interaction unit. A switch click or slider release can commit while the control remains focused.
- Focus Exit means focus left the widget’s complete logical focus scope. An unchanged native text input can report Focus Exit without committing a value change.
§Native control example
A switch click can call write, then commit, while focus remains on the switch. A later
departure from the switch calls focus_exit. An unchanged text input that loses focus can call
only focus_exit because there was no value interaction to commit.
§Compound-widget example
For a compound widget, the logical focus scope includes its owned controls and popup or portal content. Moving focus from a combobox trigger into its popup does not report Focus Exit. When a selection writes and commits before focus leaves that complete scope, report the write, then Commit, then Focus Exit.
Equality compares the binding’s producer-defined identity. Equal bindings are guaranteed to represent interchangeable read, write, Commit, and Focus Exit behavior; producers may conservatively return unequal bindings when they cannot prove that interchangeability.
Fields§
§read: ReadSignal<T>The binding’s reactive value.
Implementations§
Source§impl<T: 'static> Binding<T>
impl<T: 'static> Binding<T>
Sourcepub fn new(
read: ReadSignal<T>,
write: Callback<(T, ChangeOrigin)>,
commit: Callback<()>,
) -> Self
pub fn new( read: ReadSignal<T>, write: Callback<(T, ChangeOrigin)>, commit: Callback<()>, ) -> Self
Creates a binding identified by its exact read, write, and commit handles.
Focus Exit is a no-op unless replaced with Binding::with_focus_exit or
Binding::with_focus_exit_using_identity.
Sourcepub fn new_with_identity<I>(
read: ReadSignal<T>,
write: Callback<(T, ChangeOrigin)>,
commit: Callback<()>,
identity: I,
) -> Selfwhere
I: PartialEq + 'static,
pub fn new_with_identity<I>(
read: ReadSignal<T>,
write: Callback<(T, ChangeOrigin)>,
commit: Callback<()>,
identity: I,
) -> Selfwhere
I: PartialEq + 'static,
Creates a binding with a producer-defined comparable identity.
Equal identities must always represent interchangeable read, write, and commit behavior.
This constructor installs no-op Focus Exit behavior, so that behavior is interchangeable as
well. Producers that cannot prove interchangeability should use Binding::new instead.
Sourcepub fn with_focus_exit(self, focus_exit: Callback<()>) -> Self
pub fn with_focus_exit(self, focus_exit: Callback<()>) -> Self
Adds the callback invoked when focus leaves the widget’s complete logical focus scope.
This builder also incorporates the callback into binding identity, preserving the guarantee that equal bindings have interchangeable Focus Exit behavior. It does not alter Commit or imply any form-library blur, touched, or validation semantics.
Sourcepub fn with_focus_exit_using_identity(self, focus_exit: Callback<()>) -> Self
pub fn with_focus_exit_using_identity(self, focus_exit: Callback<()>) -> Self
Adds Focus Exit behavior covered by the binding’s existing comparable identity.
Unlike Binding::with_focus_exit, this builder does not incorporate the callback’s
allocation identity. Calling it asserts that bindings with equal existing identities also
have interchangeable Focus Exit behavior, in addition to interchangeable read, write, and
Commit behavior. Producers that cannot prove this must use Binding::with_focus_exit
instead.
This builder does not alter Commit or imply any form-library blur, touched, or validation semantics.
Sourcepub fn write(&self, value: T, origin: ChangeOrigin)
pub fn write(&self, value: T, origin: ChangeOrigin)
Writes a value and preserves where the change originated.
Sourcepub fn focus_exit(&self)
pub fn focus_exit(&self)
Reports that focus left the widget’s complete logical focus scope.
This is independent from Binding::commit. Widgets are responsible for defining their
complete scope, including owned child controls and popup or portal content, and for
suppressing reports while focus moves within it.
Sourcepub fn into_trio(self) -> BindingPropTrio<T>
pub fn into_trio(self) -> BindingPropTrio<T>
Decomposes this binding into the dependency-free widget prop contract.
The lower-level on_change callback has no origin parameter, so its writes are user writes.