Skip to main content

AttributedText

Struct AttributedText 

Source
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: String

The full string.

§spans: Vec<TextSpan>

Non-overlapping, sorted style runs covering text.

§align: TextAlign

Paragraph alignment.

§max_lines: u32

Maximum number of lines; 0 means no limit (numberOfLines).

§ellipsize: EllipsizeMode

How text beyond max_lines is cut.

§no_wrap: bool

Lines 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: bool

The 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

Source

pub fn is_selectable(&self) -> bool

Whether the text was made selectable (userSelect: "text", select-text).

Source

pub fn has_backgrounds(&self) -> bool

Whether a span has a background (TextBackground).

Source

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).

Source

pub fn has_hidden(&self) -> bool

Whether a run is hidden (ResolvedTextStyle::hidden).

Source

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.

Source

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.

Source

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.

Source

pub fn span_at(&self, index: u32) -> Option<&TextSpan>

The span containing the UTF-16 offset index (the last one past the end).

Source

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.

Source

pub fn hidden_at(&self, index: u32) -> bool

Whether the character at the UTF-16 offset index is in a hidden run (ResolvedTextStyle::hidden): nothing of it is drawn.

Source

pub fn background_at(&self, index: u32) -> Option<TextBackground>

The background of the character at the UTF-16 offset index.

Source

pub fn len_utf16(&self) -> u32

Length of the text so far, in UTF-16 units.

The innermost link containing the UTF-16 offset index.

Source

pub fn push_attachment(&mut self, size: Size<Points>, style: ResolvedTextStyle)

Appends an attachment of size on the baseline.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for AttributedText

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AttributedText

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AttributedText

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for AttributedText

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AttributedText

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.