pub struct TextRun {
pub range: Range<usize>,
pub font: FontSpec,
pub color: Option<Color>,
pub background: Option<Color>,
pub underline: Underline,
pub strikethrough: bool,
pub link: Option<String>,
}Expand description
One styled span of a label’s text (docs/text-runs.md).
range is a byte range into the label’s text. Bytes, not chars: every backend that takes a
structured attributed string wants UTF-16 or byte offsets, str slicing is byte-based, and a
char count would have to be converted at every boundary. Ranges must be non-overlapping and
ascending; a gap between them is unstyled text, drawn with the label’s own font.
A run says only what differs. font is the whole descriptor rather than a delta because a
bold run inside a Body paragraph is FontSpec { style: Body, weight: Some(Bold), .. }. The
style has to travel with the weight or the run loses its semantic size.
Fields§
§range: Range<usize>§font: FontSpec§color: Option<Color>§background: Option<Color>A highlight painted behind the glyphs. Every native text editor carries this attribute (docs/texteditor.md), and search hits and review comments are the two things an app is asked for the moment it has styled text at all.
underline: UnderlineA line under the text.
strikethrough: boolA line through the text. Separate from FontSpec because it is a decoration, not a face:
no platform expresses it by picking a different font.
link: Option<String>Makes this run a link to the given target. Rendering it is Cap::TextRuns; making it
activatable is Cap::TextLinks, which is a smaller set (see the docs).
Implementations§
Source§impl TextRun
impl TextRun
Sourcepub fn font(range: Range<usize>, font: FontSpec) -> Self
pub fn font(range: Range<usize>, font: FontSpec) -> Self
A run that only changes the font, the common case for emphasis.