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) -> AnnotatedString
pub fn new(text: String) -> AnnotatedString
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) -> SmallVec<[usize; 8]>
pub fn span_boundaries(&self) -> SmallVec<[usize; 8]>
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),
) -> AnnotatedString
pub fn map_span_styles( &self, map: impl FnMut(&mut SpanStyle), ) -> AnnotatedString
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>) -> AnnotatedString
pub fn subsequence(&self, range: Range<usize>) -> AnnotatedString
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)
Trait Implementations§
Source§impl Clone for AnnotatedString
impl Clone for AnnotatedString
Source§fn clone(&self) -> AnnotatedString
fn clone(&self) -> AnnotatedString
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AnnotatedString
impl Debug for AnnotatedString
Source§impl Default for AnnotatedString
impl Default for AnnotatedString
Source§fn default() -> AnnotatedString
fn default() -> AnnotatedString
Source§impl From<&String> for AnnotatedString
impl From<&String> for AnnotatedString
Source§fn from(text: &String) -> AnnotatedString
fn from(text: &String) -> AnnotatedString
Source§impl From<&mut String> for AnnotatedString
impl From<&mut String> for AnnotatedString
Source§fn from(text: &mut String) -> AnnotatedString
fn from(text: &mut String) -> AnnotatedString
Source§impl From<&str> for AnnotatedString
impl From<&str> for AnnotatedString
Source§fn from(text: &str) -> AnnotatedString
fn from(text: &str) -> AnnotatedString
Source§fn from(value: AnnotatedString) -> Self
fn from(value: AnnotatedString) -> Self
Source§impl From<Arc<RenderString>> for AnnotatedString
impl From<Arc<RenderString>> for AnnotatedString
Source§fn from(content: Arc<RenderString>) -> AnnotatedString
fn from(content: Arc<RenderString>) -> AnnotatedString
Source§impl From<String> for AnnotatedString
impl From<String> for AnnotatedString
Source§fn from(text: String) -> AnnotatedString
fn from(text: String) -> AnnotatedString
Auto Trait Implementations§
impl !RefUnwindSafe for AnnotatedString
impl !Send for AnnotatedString
impl !Sync for AnnotatedString
impl !UnwindSafe for AnnotatedString
impl Forget for AnnotatedString
impl Freeze for AnnotatedString
impl Move for AnnotatedString
impl Unpin for AnnotatedString
impl UnsafeUnpin for AnnotatedString
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more