pub struct AttributedText {Show 15 fields
pub text: String,
pub spans: Vec<TextSpan>,
pub align: TextAlign,
pub max_lines: u32,
pub ellipsize: EllipsizeMode,
pub no_wrap: bool,
pub shadow: Option<TextShadow>,
pub links: Vec<TextLink>,
pub test_ids: Vec<SpanTestId>,
pub copy_texts: Vec<AttachmentCopyText>,
pub writing_direction: Option<bool>,
pub rtl: bool,
pub selectable: Option<bool>,
pub selection_color: Option<Color>,
pub attachments: Vec<TextAttachment>,
/* private fields */
}Expand description
The merged content of a <text> block: its own text plus all nested
spans and raw text nodes, flattened into one string with style runs.
Fields§
§text: StringThe full string.
spans: Vec<TextSpan>Non-overlapping, sorted style runs covering text.
align: TextAlignParagraph alignment.
max_lines: u32Maximum number of lines; 0 means no limit (numberOfLines).
ellipsize: EllipsizeModeHow text beyond max_lines is cut.
no_wrap: boolLines never wrap (whitespace-nowrap): measured at their natural
width, overflowing the box.
shadow: Option<TextShadow>Shadow behind the whole block (drawing only, not layout).
links: Vec<TextLink>Nested <text> spans that take presses (they may nest).
test_ids: Vec<SpanTestId>Nested <Text> spans with a testID (they may nest). Platforms
draw nothing from them. Tests name a span by its id.
copy_texts: Vec<AttachmentCopyText>What attachments give in place of their placeholder when the text
is copied (copyText of a view inside the text), in text order.
Platforms draw nothing from them: they are what
AttributedText::copied_text puts where the attachment is.
writing_direction: Option<bool>writingDirection: right to left (Some(true)), left to right, or
from the content (None).
rtl: boolThe block is laid out right to left: auto alignment is the right
side.
selectable: Option<bool>A long press copies the text (userSelect: "text" or select-text;
drawing only): Some(false) when set off, None when not set, which
is not selectable except where text is by default (desktop
browsers). is_selectable is whether it is asked for.
selection_color: Option<Color>The highlight of the selection of selectable text (selectionColor);
the platform’s tint when None.
attachments: Vec<TextAttachment>Inline views and images, in text order: each is an object
replacement character (U+FFFC) the engine gives the attachment’s
size. Their optional alignment is passed separately to
TextEngine::prepare_aligned; prepare places them on the baseline.
Implementations§
Source§impl AttributedText
impl AttributedText
Sourcepub fn is_selectable(&self) -> bool
pub fn is_selectable(&self) -> bool
Whether the text was made selectable (userSelect: "text", select-text).
Sourcepub fn has_backgrounds(&self) -> bool
pub fn has_backgrounds(&self) -> bool
Whether a span has a background (TextBackground).
Sourcepub fn uniform_color(&self) -> Option<Color>
pub fn uniform_color(&self) -> Option<Color>
The color every character is drawn in, decoration lines included,
if there is one (None for several, or no text): what a transition
of the text’s color animates (crate::transition::recolor).
Whether a run is hidden (ResolvedTextStyle::hidden).
Sourcepub fn visible_text(&self) -> Cow<'_, str>
pub fn visible_text(&self) -> Cow<'_, str>
The text a screen reader reads: all of it but its hidden runs
(ResolvedTextStyle::hidden); borrowed when none is.
Empty attachments (no height: a span’s padding) are no content and are left out too.
Sourcepub fn copied_text(&self, range: Range<u32>) -> String
pub fn copied_text(&self, range: Range<u32>) -> String
The characters of the UTF-16 range range as a copy gives them:
an attachment as its copy text (Self::copy_texts), or nothing
without one (its placeholder, ATTACHMENT_CHAR, is left out), and
without hidden runs (ResolvedTextStyle::hidden). The range is
clamped to the text; offsets inside a surrogate pair round down.
Sourcepub fn text_without_attachments(&self, range: Range<u32>) -> String
pub fn text_without_attachments(&self, range: Range<u32>) -> String
The characters of the UTF-16 range range without attachments’
placeholders (ATTACHMENT_CHAR, whatever they copy as) and
hidden runs: the text’s own characters, as accessibility reads them
beside the inline views it reads on their own. Clamped as
Self::copied_text.
Sourcepub fn span_at(&self, index: u32) -> Option<&TextSpan>
pub fn span_at(&self, index: u32) -> Option<&TextSpan>
The span containing the UTF-16 offset index (the last one past the
end).
Sourcepub fn visible_ranges(&self, range: Range<u32>) -> Vec<Range<u32>>
pub fn visible_ranges(&self, range: Range<u32>) -> Vec<Range<u32>>
The pieces of the UTF-16 range range that no hidden run covers
(ResolvedTextStyle::hidden), in order: where a selection’s
highlight is drawn. The whole range when no run is hidden.
Whether the character at the UTF-16 offset index is in a hidden
run (ResolvedTextStyle::hidden): nothing of it is drawn.
Sourcepub fn background_at(&self, index: u32) -> Option<TextBackground>
pub fn background_at(&self, index: u32) -> Option<TextBackground>
The background of the character at the UTF-16 offset index.
Sourcepub fn link_at(&self, index: u32) -> Option<&TextLink>
pub fn link_at(&self, index: u32) -> Option<&TextLink>
The innermost link containing the UTF-16 offset index.
Sourcepub fn push_attachment(&mut self, size: Size<Points>, style: ResolvedTextStyle)
pub fn push_attachment(&mut self, size: Size<Points>, style: ResolvedTextStyle)
Appends an attachment of size on the baseline.
Sourcepub fn push(&mut self, s: &str, style: ResolvedTextStyle)
pub fn push(&mut self, s: &str, style: ResolvedTextStyle)
Appends s with style, merging with the previous run when the
style is identical. Italic text keeps its color emoji upright, in
runs of their own.
Sourcepub fn recolored_ranges(&self, other: &Self) -> Option<Vec<Range<u32>>>
pub fn recolored_ranges(&self, other: &Self) -> Option<Vec<Range<u32>>>
The characters (UTF-16 offsets; ascending, apart) drawn otherwise in
other, when the two texts differ at most in colors, hidden runs
and test metadata, as the core’s colors-only path allows; None
when they differ in anything else. A platform that draws colors from
the text and keeps the layout redraws only where these lie.
Sourcepub fn layout_eq(&self, other: &Self) -> bool
pub fn layout_eq(&self, other: &Self) -> bool
True if both texts lay out identically: same characters, runs, metrics and alignment. Decorative attributes (colors) are ignored.
Sourcepub fn layout_hash(&self) -> u64
pub fn layout_hash(&self) -> u64
A 64-bit hash of everything AttributedText::layout_eq compares.
SipHash (not Fx): it keys a cache without a full equality check.