Expand description
Retained, change-only widget property writers.
Bindings memoizes the last value written per widget and performs the
Ui::set_* call only when the new value differs. A render pass that
writes the model into the widgets therefore performs zero widget
operations when nothing changed, which keeps idle frames free of native
churn (scroll position, hover state, IME composition) without hand-rolled
dirty flags per widget:
use native_gui_mock::MockBackend;
use native_gui_core::{Bindings, Ui, WidgetKind};
let mut ui = Ui::new(MockBackend::default());
let status = ui.create(WidgetKind::Label, Some("0"))?;
let mut bindings = Bindings::new();
// First sync writes; a second sync with the same value writes nothing.
bindings.text(&mut ui, status, "1")?;
bindings.text(&mut ui, status, "1")?;
assert_eq!(bindings.writes(), 1);
assert_eq!(bindings.skipped(), 1);The flow is one-way (model → widget): the app owns the state, calls the
writers on every render pass, and the bindings suppress unchanged values.
Two-way text binding (echoing TextChanged back into the model) is
deliberately not provided yet: the IME echo rules
must settle first, because writing text into a focused input can reset an
in-progress composition.
Bindings::clear forgets the cached values, forcing the next sync to
rewrite everything — use it after mutating widgets outside the bindings
(for example after loading a new document).
Structs§
- Bindings
- Last-written widget property values;
Ui::set_*runs only when a value actually changed.