use ui::input::{self, FieldEvent, TextField};
input::init(cx); // once, at startup
let field = cx.new(|cx| TextField::new(cx).with_placeholder("Search…"));
cx.subscribe(&field, |view, field, event, cx| {
if let FieldEvent::Changed(_) = event {
view.filter(field.read(cx).content().clone(), cx);
}
}).detach();
// …then render it: .child(field.clone())- A field is an entity the caller holds; render the same
Entity<TextField>every frame. - Subscribe to
FieldEvent, notcx.observe: observe fires on every caret blink. - Bindings are scoped to
input::KEY_CONTEXT. To rebind, takeinput::bindings()and layer over it withui::keys. set_contentclears the undo history.