Skip to main content

Module text

Module text 

Source
Expand description

Core-owned text stack. Shaping and line layout run through cosmic-text and are cached across frames keyed by (content, style, scale) — the layout pass measures through this cache, so shaping survives resizes and static text costs a hash lookup per frame. Rasterization feeds the shared glyph atlas; renderers only ever see positioned atlas quads.

Structs§

Span
One styled run inside a rich-text paragraph. Spans are shaped and wrapped together as a single flow; plain data, so every frontend can build them.
TextHit
Where a point landed in the text a keyed node drew: a byte offset and the visual row it is on. byte is a caret position: between two characters, past the last one at the end, and cosmic-text’s rule for which side of a glyph the point fell on. For a node holding several text runs the offset runs across them in tree order, the way the access tree reads a line. line is the visual row within the node, 0-based, counted across every run the key covers by where the rows sit: a line row of three inline runs is one row, a run that wrapped is as many as it wrapped to, and two runs stacked are two — not the wrapped line within one run’s buffer, and not the ordinal role="line" node a pointer event’s line names (that one counts rows of the editor, this one rows of the text asked about).
TextMetrics
What a piece of text measures, in logical px at the current scale — the same numbers layout uses for a text node with that content and style, so a view can size a column to its widest label or pick a tier that fits without hand-tuned magic numbers.
TextSystem
The shaping and rasterization state of one window. The font database it shapes against is not in here — that is the session’s (crate::session::Session), passed in as fs — because a font registered in one window has to shape in every window of the session. What is here is coupled to this window’s glyph atlas: the shaped-buffer cache stamps its positioned glyphs with the atlas stamp they were packed against, and the frame lists are what TextId indexes.

Constants§

DEFAULT_TEXT_CACHE_BYTES
The default byte budget for the shaped-text cache. Sized so a screenful of code never meets it — two panes of 55 highlighted lines are ~900 short entries, a few megabytes — and a pane streaming new text meets it within seconds, which is when the clock alone let the cache reach gigabytes. Core::set_text_cache_budget changes it.
LONG_LINE_BYTES
A non-wrapping text at least this long is shaped in chunks: a minified bundle, a log line with a blob in it, a base64 field. Shorter text takes the path it always took, so nothing below the line moves. Bytes, not characters, for the same reason a step line carries integers: every binding can count them.