pub struct AnnotatedString { /* private fields */ }Expand description
The basic data structure of text with multiple styles: Compose’s
AnnotatedString. Its content, the text, styles, annotations and link
identities, is shared with every layout and draw made from it, so a clone
copies no text. The handlers of its clickable links stay with it.
To construct an AnnotatedString with styles you can use
AnnotatedString::builder().
Implementations§
Source§impl AnnotatedString
impl AnnotatedString
Sourcepub fn new(text: String) -> Self
pub fn new(text: String) -> Self
Creates a string holding text with no styles and no annotations.
Sourcepub fn is_plain(&self, text: &str) -> bool
pub fn is_plain(&self, text: &str) -> bool
Whether this is text with no styles, annotations or links: the
string AnnotatedString::new makes of text.
Sourcepub fn span_styles(&self) -> &[RangeStyle<SpanStyle>]
pub fn span_styles(&self) -> &[RangeStyle<SpanStyle>]
Character styles with the byte ranges they cover.
Sourcepub fn paragraph_styles(&self) -> &[RangeStyle<ParagraphStyle>]
pub fn paragraph_styles(&self) -> &[RangeStyle<ParagraphStyle>]
Paragraph styles with the byte ranges they cover.
Sourcepub fn string_annotations(&self) -> &[RangeStyle<StringAnnotation>]
pub fn string_annotations(&self) -> &[RangeStyle<StringAnnotation>]
Tag and value annotations with the byte ranges they cover.
Sourcepub fn has_link_annotations(&self, start: usize, end: usize) -> bool
pub fn has_link_annotations(&self, start: usize, end: usize) -> bool
Whether a link annotation covers part of [start, end).
JC parity: AnnotatedString.hasLinkAnnotations(start, end)
Sourcepub fn span_boundaries(&self) -> SpanBoundaries
pub fn span_boundaries(&self) -> SpanBoundaries
Returns a sorted list of unique byte indices where styles change.
Sourcepub fn render_string(&self) -> &Arc<RenderString> ⓘ
pub fn render_string(&self) -> &Arc<RenderString> ⓘ
The content as rendering reads it (text, styles, link identity), never the link handlers. Shared: every clone of this string holds the same.
Sourcepub fn span_measurement_hash(&self) -> u64
pub fn span_measurement_hash(&self) -> u64
Hash of the span styles’ ranges and the attributes that change how the text measures: two strings with the same text and hash measure alike, whatever their spans’ colors, backgrounds or decorations.
Sourcepub fn render_hash(&self) -> u64
pub fn render_hash(&self) -> u64
Hash of the text and of the span and paragraph styles, as renderers use it to key caches.
Sourcepub fn map_span_styles(&self, map: impl FnMut(&mut SpanStyle)) -> Self
pub fn map_span_styles(&self, map: impl FnMut(&mut SpanStyle)) -> Self
This string with map applied to each of its span styles: the same
text, ranges, annotations and links.
Sourcepub fn subsequence(&self, range: Range<usize>) -> Self
pub fn subsequence(&self, range: Range<usize>) -> Self
Returns a new AnnotatedString containing a substring of the original text
and any styles that overlap with the new range, with indices adjusted.
Sourcepub fn get_string_annotations(
&self,
tag: &str,
start: usize,
end: usize,
) -> Vec<&RangeStyle<StringAnnotation>>
pub fn get_string_annotations( &self, tag: &str, start: usize, end: usize, ) -> Vec<&RangeStyle<StringAnnotation>>
Returns all string annotations with the given tag whose range overlaps [start, end).
JC parity: AnnotatedString.getStringAnnotations(tag, start, end) -> List<Range<String>>
Sourcepub fn get_link_annotations(
&self,
start: usize,
end: usize,
) -> Vec<RangeStyle<LinkAnnotation>>
pub fn get_link_annotations( &self, start: usize, end: usize, ) -> Vec<RangeStyle<LinkAnnotation>>
Returns all link annotations whose range overlaps [start, end).
JC parity: AnnotatedString.getLinkAnnotations(start, end)