Expand description
Rich-text editing for egui, over paragraphs the application lays out and owns itself.
egui’s TextEdit edits one string drawn in one format. A document editor
draws paragraphs of styled runs among lists, tables and pictures of its own,
and wants a caret that moves through all of them as if the page were one
surface. This crate is that caret. The application keeps its document and
its layout; it describes each paragraph’s text as a ParagraphJob and
implements Model so that an edit lands in its own document. A
RichEdit turns keys, the pointer and the clipboard into Edits, and
paints the selection and the caret over the application’s galleys.
§A frame
RichEdit::input, before anything is laid out, takes this frame’s events and applies them to the model, so the layout that follows already shows what was typed.- Then, for every editable paragraph in document order, whether or not it
is on screen: build its
ParagraphJob, lay it out, allocate a response that senses clicks and drags, and hand all of it toRichEdit::paragraph, which paints it.
§Offsets
A Position is a paragraph and a character offset (characters, not
bytes) into the model’s text of that paragraph. What is drawn need not be
that text: a tab drawn as spaces, a footnote’s citation that the model does
not count, a field’s current value. ParagraphJob::atom records each such
piece, and the caret steps over it whole.
Structs§
- Laid
- A paragraph as the application laid it out and where it is on screen.
- Offset
Map - Which drawn characters of a paragraph stand for which of the model’s.
- Paragraph
Job - A paragraph’s text as it is drawn, built piece by piece so that every drawn character is known to stand for some part of the model’s text.
- Position
- Where a caret can stand: a paragraph, and a character offset into the model’s text of it.
- Rich
Edit - The editor’s state, kept by the application from one frame to the next.
- Selection
- A selection: where it began and where it has been taken to. The two are the same position when the selection is a caret.
Enums§
- Edit
- A change the editor asks the model to make.
- Mark
- Formatting a range of text is given or has taken off. The set is fixed, so that neither the editor nor the model needs a style system to agree on.
Traits§
- Model
- The document, as the editor sees it. The application implements this over whatever it keeps its document in.