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
impl TextSpans
pub fn new(spans: impl IntoIterator<Item = TextSpan>) -> Self
Sourcepub fn new_with_fonts(
spans: impl IntoIterator<Item = (TextSpan, FontRefs)>,
) -> Self
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.
Sourcepub fn from_bytes(bytes: impl Into<Rc<[u8]>>) -> Self
pub fn from_bytes(bytes: impl Into<Rc<[u8]>>) -> Self
Adopts an already encoded list, which is what the protocol vectors carry.
Sourcepub fn with_font_table(self, table: impl Into<Rc<[u8]>>) -> Self
pub fn with_font_table(self, table: impl Into<Rc<[u8]>>) -> Self
The same runs with an already encoded font table beside them.
pub fn as_bytes(&self) -> &[u8] ⓘ
Sourcepub fn font_table(&self) -> &[u8] ⓘ
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.
pub fn is_empty(&self) -> bool
Sourcepub fn font_entry_count(&self) -> usize
pub fn font_entry_count(&self) -> usize
How many runs name fonts.
Sourcepub fn span_fonts(&self) -> Vec<(u32, Vec<FontRef>)>
pub fn span_fonts(&self) -> Vec<(u32, Vec<FontRef>)>
The fonts each run that names any is set in, by the run’s index.
Sourcepub fn spans(&self) -> impl Iterator<Item = TextSpan> + '_
pub fn spans(&self) -> impl Iterator<Item = TextSpan> + '_
The runs this list holds, decoded again.
Sourcepub fn from_markdown(source: &str) -> (String, Self)
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.