Skip to main content

TextSpans

Struct TextSpans 

Source
pub struct TextSpans { /* private fields */ }
Expand description

An encoded list of spans, ready to travel.

Shared rather than copied, for the same reason a draw list is: the same list redrawn every frame compares equal and produces no mutation at all.

Implementations§

Source§

impl TextSpans

Source

pub fn new(spans: impl IntoIterator<Item = TextSpan>) -> Self

Source

pub fn new_with_fonts( spans: impl IntoIterator<Item = (TextSpan, FontRefs)>, ) -> Self

Runs, each with the fonts it is set in where the text has no role.

An empty list leaves that run in the text’s own font. A run of text that has a role is always in the theme’s font, whatever it names here.

Source

pub fn new_with_features( spans: impl IntoIterator<Item = (TextSpan, impl AsRef<[FontFeature]>)>, ) -> Self

Runs, each with the OpenType features it is set with, such as FontFeature::TABULAR_NUMS on the one run that is a number.

An empty list leaves that run with the features of the text it is in. A run that names features takes the text’s as well, and where both name a tag the run’s value is the one used. Unlike a font, features are taken by a run with a role and by a run of text that has one: they pick a form of the font and leave the font alone. At most MAX_FONT_FEATURES (16) are taken for one run; a longer list is still sent, so the Renderer can say what is wrong with it.

Source

pub fn from_bytes(bytes: impl Into<Rc<[u8]>>) -> Self

Adopts an already encoded list, which is what the protocol vectors carry.

Source

pub fn with_font_table(self, table: impl Into<Rc<[u8]>>) -> Self

The same runs with an already encoded font table beside them.

Source

pub fn with_feature_table(self, table: impl Into<Rc<[u8]>>) -> Self

The same runs with an already encoded font feature table beside them, as encode_feature_table lays one out. An empty table is no table.

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

Source

pub fn font_table(&self) -> &[u8] ⓘ

The SpanFonts blob: a count, then one entry per run that names fonts, then the font lists themselves. Every offset in it counts from the start of the blob.

Source

pub fn feature_table(&self) -> &[u8] ⓘ

The SpanFontFeatures blob: a count, then one entry per run that names features, then the feature records themselves. Every offset in it counts from the start of the blob. Empty where no run names a feature, and then nothing is sent.

Source

pub fn is_empty(&self) -> bool

Source

pub fn font_entry_count(&self) -> usize

How many runs name fonts.

Source

pub fn span_fonts(&self) -> Vec<(u32, Vec<FontRef>)>

The fonts each run that names any is set in, by the run’s index.

Source

pub fn feature_entry_count(&self) -> usize

How many runs name font features, as the table’s own count says.

Source

pub fn span_features(&self) -> Vec<(u32, Vec<FontFeature>)>

The font features each run that names any is set with, by the run’s index, in the order the table lists them.

Empty where there is no table and where the table cannot be read by the rules the Renderer holds it to: an entry or a feature list that runs past the end, an offset that is not a multiple of four, more than MAX_FONT_FEATURES features for one run, or a run named twice. The Renderer reports such a table and draws the text without any of it, so nothing is read out of half of one here either.

Source

pub fn spans(&self) -> impl Iterator<Item = TextSpan> + '_

The runs this list holds, decoded again.

Source

pub fn from_markdown(source: &str) -> (String, Self)

Turns a small, closed subset of markdown into a plain string and its spans.

**bold**, *italic* and `code`, and nothing else. It is a convenience, not a parser: anything it does not recognise is left in the string exactly as written, because silently eating a character a reader typed is worse than showing it.

Links are not here. A link needs a handler, and a handler is something the screen has rather than something a string can name.

Trait Implementations§

Source§

impl Clone for TextSpans

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 TextSpans

Source§

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

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

impl Default for TextSpans

Source§

fn default() -> Self

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

impl PartialEq for TextSpans

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 TextSpans

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