Expand description
Editable text: the retained state of every text_edit node, keyed by
node Key, built on cosmic-text’s editor.
A view declares an editor with Ui::text_edit(label, initial, &opts, spec), where opts is an EditOptions. The core keeps the buffer,
caret, selection, IME composition and undo history across frames,
routes InputEvent::Text / InputEvent::Key to the focused editor and
posts changed and submit events. An app reads the draft back with
Core::edit_text / Ui::edit_text and replaces it with
Core::set_edit_text; the store itself is not something an app
touches.
use kui_core::{Core, EditOptions, InputEvent, NodeSpec, Size, TextStyle};
let mut core = Core::new();
let mut ui = core.frame(Size::new(400.0, 300.0), 1.0);
let opts = EditOptions {
style: TextStyle::new(14.0),
autofocus: true,
..Default::default()
};
let field = ui.text_edit("name", "hello", &opts, NodeSpec::row().grow_width().pad(4.0));
ui.finish();
// Typing reaches the focused editor; the host reads the draft back.
core.handle_input(InputEvent::Text(" world".into()));
assert_eq!(core.edit_text(field).as_deref(), Some("hello world"));Structs§
- Edit
Options - How a
text_editnode behaves: its text style, whether it is a single-line field or a multiline document, and how it takes focus and paints its selection. Build one with struct update syntax fromDefault. - Edit
Store - The retained editors of one window, owned by
Core. Reach it throughUi::text_edit,Core::edit_textandCore::set_edit_textrather than directly.
Constants§
- MAX_
UNDECLARED_ EDITS - How many undeclared editors the store keeps before the longest
undeclared one is dropped. A declared editor is never evicted, however
many there are: retention across absence is what
text_editpromises, so this is a ceiling, not a prune. An editor holding a short line is a few KB and one holding a long line about 22 KB, so a full budget is a few MB.